From 7f0d723e694412fb185059b816cc6e9d15521daa Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 1 Apr 2020 10:51:07 +0200 Subject: [PATCH] Propagate incognito status change to server --- assets/js/common/ws.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/assets/js/common/ws.js b/assets/js/common/ws.js index 8fd5a056..0cb78fd4 100644 --- a/assets/js/common/ws.js +++ b/assets/js/common/ws.js @@ -72,6 +72,14 @@ class UserWebSocket { }); } + /** + * Get current connection status with the server + */ + static get IsConnected() { + return this.hasOwnProperty("ws") + && this.ws.readyState == WebSocket.OPEN; + } + /** * Handles websocket errors */ @@ -210,4 +218,11 @@ class UserWebSocket { // It is a success queue.res(msg.data); } -} \ No newline at end of file +} + + +// Register some events +document.addEventListener("incognitoStatusChanged", (e) => { + if(UserWebSocket.IsConnected) + ws("$main/set_incognito", {enable: e.detail.enabled}) +}) \ No newline at end of file