diff --git a/packages/client/src/websocket.ts b/packages/client/src/websocket.ts index 0b59b1bd4d..6d5aa4507c 100644 --- a/packages/client/src/websocket.ts +++ b/packages/client/src/websocket.ts @@ -222,45 +222,44 @@ export default class WebSocketClient { this.connectFailCount++; // Unbind any Pusher event listeners before disconnecting Pusher instance - // this.unbindPusherEvents(); - // this.unbindGlobalsAndReset(); + this.unbindPusherEvents(); + this.unbindGlobalsAndReset(); - // this.conn?.disconnect(); - // this.conn = null; + this.conn?.disconnect(); + this.conn = null; console.log('websocket closed'); - console.log('[websocket] calling close callbacks'); this.closeCallback?.(this.connectFailCount); this.closeListeners.forEach((listener) => listener(this.connectFailCount)); - // let retryTime = MIN_WEBSOCKET_RETRY_TIME; - - // // If we've failed a bunch of connections then start backing off - // if (this.connectFailCount > MAX_WEBSOCKET_FAILS) { - // retryTime = MIN_WEBSOCKET_RETRY_TIME * this.connectFailCount * this.connectFailCount; - // if (retryTime > MAX_WEBSOCKET_RETRY_TIME) { - // retryTime = MAX_WEBSOCKET_RETRY_TIME; - // } - // } - - // // Applying jitter to avoid thundering herd problems. - // retryTime += Math.random() * JITTER_RANGE; - - // setTimeout( - // () => { - // this.initialize( - // connectionUrl, - // this.currentUser as number, - // this.currentTeamUser, - // this.currentTeam, - // authToken, - // this.currentPresence, - // ); - // }, - // retryTime, - // ); + let retryTime = MIN_WEBSOCKET_RETRY_TIME; + + // If we've failed a bunch of connections then start backing off + if (this.connectFailCount > MAX_WEBSOCKET_FAILS) { + retryTime = MIN_WEBSOCKET_RETRY_TIME * this.connectFailCount * this.connectFailCount; + if (retryTime > MAX_WEBSOCKET_RETRY_TIME) { + retryTime = MAX_WEBSOCKET_RETRY_TIME; + } + } + + // Applying jitter to avoid thundering herd problems. + retryTime += Math.random() * JITTER_RANGE; + + setTimeout( + () => { + this.initialize( + connectionUrl, + this.currentUser as number, + this.currentTeamUser, + this.currentTeam, + authToken, + this.currentPresence, + ); + }, + retryTime, + ); }); this.conn.connection.bind('connected', () => {