Skip to content

Commit

Permalink
Fix reconnection
Browse files Browse the repository at this point in the history
  • Loading branch information
ryo33 committed Feb 11, 2024
1 parent d72cfb9 commit d2fe953
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,27 +178,29 @@
} else {
socketUrl = "wss://hug-server.shuttleapp.rs/websocket"
}
socket = new WebSocket(socketUrl);
let backoff = 1000;
socket.onclose = () => {
setTimeout(() => {
socket = new WebSocket(socketUrl);
backoff *= 2;
}, backoff);
}
socket.onopen = () => {
backoff = 1000;
console.log('WebSocket Open');
}
socket.onerror = (error) => {
console.log('WebSocket Error ' + error);
}
socket.onmessage = (event) => {
on_output(event.data)
}

// register event handlers for input/output.
document.push = payload => socket.send(payload);
let connect = socketUrl => {
socket = new WebSocket(socketUrl);
socket.onopen = () => {
backoff = 1000;
// register event handlers for input/output.
document.push = payload => socket.send(payload);
console.log('WebSocket Open');
}
socket.onmessage = (event) => {
on_output(event.data)
}
socket.onerror = (error) => {
console.log('WebSocket Error ' + error);
}
socket.onclose = () => {
setTimeout(() => {
connect(socketUrl);
backoff *= 2;
}, backoff);
}
};
connect(socketUrl);

// join room by key
if (params.get("key")) {
Expand Down

0 comments on commit d2fe953

Please sign in to comment.