From 75d330088ea1b87d03e1001d0a636636e6e289e0 Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Wed, 15 Oct 2025 09:34:58 -0600 Subject: [PATCH] ws reconnect --- src/public/index.html | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/public/index.html b/src/public/index.html index 499947c..677c5fb 100644 --- a/src/public/index.html +++ b/src/public/index.html @@ -57,15 +57,14 @@ } } - ws = new WebSocket(`${window.location.protocol == "https:" ? "wss" : "ws"}://${window.location.host}/ws${window.location.search}`); - ws.onopen = function(evt) { - print("READY"); + function ws_onopen(evt) { + print("CONNECTED"); } - ws.onclose = function(evt) { - print("CLOSE"); + function ws_onclose(evt) { + print("CLOSED"); ws = null; } - ws.onmessage = function(evt) { + function ws_onmessage(evt) { console.log("evt.data:", evt.data) const data = JSON.parse(evt.data); @@ -89,9 +88,22 @@ print(data.QuietText); } } - ws.onerror = function(evt) { + function ws_onerror(evt) { print("ERROR: " + evt.data); } + function ws_ensure_connected() { + if (ws) { + return; + } + print("CONNECTING..."); + ws = new WebSocket(`${window.location.protocol == "https:" ? "wss" : "ws"}://${window.location.host}/ws${window.location.search}`); + ws.onerror = ws_onerror; + ws.onmessage = ws_onmessage; + ws.onclose = ws_onclose; + ws.onopen = ws_onopen; + } + setInterval(ws_ensure_connected, 1000); + ws_ensure_connected(); document.getElementById("send").onclick = function(evt) { if (!ws || !input.value) {