Automatically reload page when WebSocket connection is closed

This commit is contained in:
Pierre HUBERT 2020-03-30 13:48:40 +02:00
parent 98c2f53a3a
commit 7d9b035e57

View File

@ -27,7 +27,7 @@ class UserWebSocket {
// Wait for connection // Wait for connection
this.ws.addEventListener("open", () => console.log("Connected to websocket!")) this.ws.addEventListener("open", () => console.log("Connected to websocket!"))
this.ws.addEventListener("error", (e) => this.Error(e)) this.ws.addEventListener("error", (e) => this.Error(e))
this.ws.addEventListener("close", (e) => this.Error(e)); this.ws.addEventListener("close", (e) => this.Closed(e));
} catch(e) { } catch(e) {
this.Error(e); this.Error(e);
@ -45,9 +45,14 @@ class UserWebSocket {
/** /**
* When we get disconnected from the websocket * When we get disconnected from the websocket
*/ */
static async Disconnected(e) { static async Closed(e) {
console.error(e) console.error("WS closed", e)
alert("Disconnected from the server !");
const num_seconds = ComunicWeb.__config.productionMode ? 5 : 0.5;
notify("Disconnected from the server, page will be reloaded in "+num_seconds+" seconds !", "danger");
setTimeout(() => ComunicWeb.common.system.restart(), num_seconds*1000);
} }
/** /**