Skip to content

Commit

Permalink
Fix reconnects not being recognized
Browse files Browse the repository at this point in the history
If we reconnect too quickly the signalling server won't have the time to
add our information to the database yet and the reconnect won't
recognize us. This can be fixed by waiting a little bit before we
reconnect.
  • Loading branch information
erikdubbelboer committed Jun 16, 2024
1 parent ffa75e2 commit c067641
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/signaling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ export default class Signaling extends EventEmitter<SignalingListeners> {
ws.removeEventListener('error', onError)
ws.removeEventListener('message', onMessage)
ws.removeEventListener('close', onClose)
this.reconnect()

// Don't try to reconnect too quickly, give the server a chance
// to store our disconnection in the db, so when we reconnect
// it recognizes us.
setTimeout(() => {
this.reconnect()
}, 100)
}
}
const onMessage = (ev: MessageEvent): void => {
Expand All @@ -68,7 +74,13 @@ export default class Signaling extends EventEmitter<SignalingListeners> {
ws.removeEventListener('error', onError)
ws.removeEventListener('message', onMessage)
ws.removeEventListener('close', onClose)
this.reconnect()

// Don't try to reconnect too quickly, give the server a chance
// to store our disconnection in the db, so when we reconnect
// it recognizes us.
setTimeout(() => {
this.reconnect()
}, 100)
}
ws.addEventListener('open', onOpen)
ws.addEventListener('error', onError)
Expand Down

0 comments on commit c067641

Please sign in to comment.