ws reconnect

main
Bel LaPointe 2025-10-15 09:34:58 -06:00
parent eecb67bbaa
commit 75d330088e
1 changed files with 19 additions and 7 deletions

View File

@ -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) {