How to reconnect the iris websocket on disconnection, without refreshing the client page?
Hello @kickbox, I guess this is more of a javascript question, but anyway, here is a quick example of how I would do it (you need to have the iris-ws.js included inside your page):
function InitWebsocket() {
let websocket = new Ws('wss:yourwebsocketurl');
let wsTimeout;
let reconnectInterval= 5000;
websocket.OnConnect(function() {
clearTimeout(wsTimeout);
});
websocket.OnDisconnect(function() {
wsTimeout = setTimeout(function() {
InitWebsocket();
}, reconnectInterval);
});
}
InitWebsocket();
Basically on disconnect you just try to reconnect again every 5 seconds, until it connects and it resets the timeout interval, this can be extended according to your needs.
Thank you!
Most helpful comment
Hello @kickbox, I guess this is more of a javascript question, but anyway, here is a quick example of how I would do it (you need to have the iris-ws.js included inside your page):
Basically on disconnect you just try to reconnect again every 5 seconds, until it connects and it resets the timeout interval, this can be extended according to your needs.