18.07.2022, 10:04
There's an automatic reconnect algorithm that should trigger after several seconds if a disconnect happens. Try waiting around 15 seconds or so, does it start working afterwards?
You can use Page Visibility API to force reload in case the page was hidden then shown again.
Another possible solution is to send a ping command after the page is shown again. This can speed up the disconnect detection. It should also be a bit faster compared to the whole page reload. See if it works for you.
You can use Page Visibility API to force reload in case the page was hidden then shown again.
Code:
$(function() {
var hidden;
document.addEventListener('visibilitychange', function() {
var state = document.visibilityState;
var planid = window.currentPlanId;
if (state == 'visible' && hidden && planid) {
window.location = '/scada-vis/#' + planid;
window.location.reload();
}
else if (state == 'hidden') {
hidden = true;
}
}, false);
});
Another possible solution is to send a ping command after the page is shown again. This can speed up the disconnect detection. It should also be a bit faster compared to the whole page reload. See if it works for you.
Code:
$(function() {
var hidden;
document.addEventListener('visibilitychange', function() {
var state = document.visibilityState;
var lb = window.localbus;
if (state == 'visible' && hidden && lb && lb.ws) {
lb.ws.send('ping');
}
else if (state == 'hidden') {
hidden = true;
}
}, false);
});