1
0
mirror of https://github.com/s00500/ESPUI.git synced 2025-09-13 05:32:09 +00:00

UI reinits on 'page becomes visible' when websocket connection is lost

This commit is contained in:
Dave Kliczbor
2018-11-18 15:19:48 +01:00
parent 11faa37fa2
commit 4c359ab14e
3 changed files with 19 additions and 7 deletions

View File

@@ -83,6 +83,7 @@ function colorClass(colorId) {
}
var websock;
var websockConnected = false;
function restart() {
$(document).add('*').off();
@@ -92,6 +93,7 @@ function restart() {
}
function conStatusError() {
websockConnected = false;
$("#conStatus").removeClass("color-green");
$("#conStatus").addClass("color-red");
$("#conStatus").text("Error / No Connection (click me to retry)");
@@ -101,12 +103,20 @@ function conStatusError() {
});
}
function handleVisibilityChange() {
if (!websockConnected && !document.hidden) {
restart();
}
}
function start() {
document.addEventListener("visibilitychange", handleVisibilityChange, false);
websock = new WebSocket('ws://' + window.location.hostname + '/ws');
websock.onopen = function(evt) {
console.log('websock open');
$("#conStatus").addClass("color-green");
$("#conStatus").text("Connected");
websockConnected = true;
};
websock.onclose = function(evt) {
console.log('websock close');