Skip to content

Commit

Permalink
Merge branch 'revert-ws-tests' into 'master'
Browse files Browse the repository at this point in the history
reverts test reconnecting ws via pusher

See merge request kchat/webapp!551
  • Loading branch information
antonbuks committed Oct 10, 2023
2 parents c2188ad + ba04eb4 commit 23b0749
Showing 1 changed file with 30 additions and 31 deletions.
61 changes: 30 additions & 31 deletions packages/client/src/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 23b0749

Please sign in to comment.