Skip to content

Commit

Permalink
try reconnecting if closed
Browse files Browse the repository at this point in the history
  • Loading branch information
targoninc-alex committed Jun 1, 2024
1 parent bf77658 commit 61fa103
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion ui/live/LiveInstance.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 61fa103

Please sign in to comment.