From 55cb005cbf021628a34680405c9ce00bf9aa0c2f Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Fri, 20 Jun 2025 19:18:56 +0200 Subject: [PATCH] automatically reconnect ws --- static/webui/script.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/static/webui/script.js b/static/webui/script.js index fe065efe..a6b1fa03 100644 --- a/static/webui/script.js +++ b/static/webui/script.js @@ -1,16 +1,22 @@ -window.ws = new WebSocket("/custom/ws"); -window.ws.onmessage = (e) => { - const msg = JSON.parse(e.data); - if ("ports" in msg) { - location.port = (location.protocol == "https:" ? msg.ports.https : msg.ports.http); - } - if ("config_reloaded" in msg) { - //window.is_admin = undefined; - if (single.getCurrentPath() == "/webui/cheats") { - single.loadRoute("/webui/cheats"); +function openWebSocket() { + window.ws = new WebSocket("/custom/ws"); + window.ws.onmessage = (e) => { + const msg = JSON.parse(e.data); + if ("ports" in msg) { + location.port = (location.protocol == "https:" ? msg.ports.https : msg.ports.http); } - } -}; + if ("config_reloaded" in msg) { + //window.is_admin = undefined; + if (single.getCurrentPath() == "/webui/cheats") { + single.loadRoute("/webui/cheats"); + } + } + }; + window.ws.onclose = function() { + setTimeout(openWebSocket, 3000); + }; +} +openWebSocket(); let loginOrRegisterPending = false; window.registerSubmit = false;