Skip to content

Commit

Permalink
fix: Prevent socket disconnections due to invalid auth
Browse files Browse the repository at this point in the history
  • Loading branch information
morgsmccauley committed Aug 9, 2024
1 parent d89bf5c commit 6751b1b
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/helki_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,37 @@ class HelkiClient {

callback(data.body);
});

socket.on('connect_timeout', () => {
this.log.warn('Socket connection timed out');
});

socket.on('reconnecting', async (attempt) => {
this.log.info('Reconnecting to socket. Attempt: ', attempt);

await this.checkRefresh();
socket.io.opts.query.token = this.accessToken;
});

socket.on('reconnect_error', (error) => {
this.log.error('Socket reconnection failed: ', error);
});

socket.on('connect_error', (error) => {
this.log.error('Socket connection failed: ', error);
});

socket.on('disconnect', async (data) => {
this.log.debug('Socket disconnected, attempting reconnect: ', data);

await this.checkRefresh();
socket.io.opts.query.token = this.accessToken;
socket.connect();
});

socket.on('connect', () => {
this.log.debug('Connected to socket');
});
}

private async auth(): Promise<void> {
Expand Down

0 comments on commit 6751b1b

Please sign in to comment.