From 61fa1034d14f9dc26e124be84dccc563896c4f49 Mon Sep 17 00:00:00 2001 From: alexa Date: Sat, 1 Jun 2024 18:02:27 +0200 Subject: [PATCH] try reconnecting if closed --- ui/live/LiveInstance.mjs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ui/live/LiveInstance.mjs b/ui/live/LiveInstance.mjs index 1b838ad..89819cd 100644 --- a/ui/live/LiveInstance.mjs +++ b/ui/live/LiveInstance.mjs @@ -35,16 +35,25 @@ export class LiveInstance { } this.server = new WebSocket(encodeURI(`${res.data}?cid=${connectSid}`)); this.server.onopen = () => { + console.log("Connected to live server!"); this.onStart(); }; this.server.onclose = () => { this.onStop(); + setTimeout(() => { + console.log("Reconnecting to live server..."); + this.start(); + }, 1000); }; + this.server.onerror = (error) => { + console.error("WebSocket error", error); + } + this.server.onmessage = (event) => { const data = JSON.parse(event.data); - console.log(data); + console.log('Received live message', data); switch (data.type) { case "message": addMessage(data.message.channelId, data.message);