Skip to content

Commit

Permalink
fix: don't stack up reopeners
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Nov 12, 2020
1 parent ed6d7c1 commit be3f146
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/dapp-svelte-wallet/ui/src/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ export function makeWebSocket(path, { onOpen, onMessage, onClose }) {
}

const RECONNECT_BACKOFF_SECONDS = 3;
let reopenTimeout;
function reopen() {
console.log(`Reconnecting in ${RECONNECT_BACKOFF_SECONDS} seconds`);
setTimeout(openSocket, RECONNECT_BACKOFF_SECONDS * 1000);
reopenTimeout = setTimeout(openSocket, RECONNECT_BACKOFF_SECONDS * 1000);
}

let socket = null;
Expand All @@ -31,6 +32,7 @@ export function makeWebSocket(path, { onOpen, onMessage, onClose }) {
if (socket) {
return;
}
clearTimeout(reopenTimeout);
socket = new WebSocket(`${wsurl}`);
retryStrategy = reopen;

Expand Down

0 comments on commit be3f146

Please sign in to comment.