ws reconnect
parent
eecb67bbaa
commit
75d330088e
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue