Skip to content

Commit

Permalink
Merge pull request #65 from morgsmccauley/fix/socket-auth-disconnect
Browse files Browse the repository at this point in the history
fix: Prevent socket disconnections due to invalid auth
  • Loading branch information
duggan authored Aug 9, 2024
2 parents d89bf5c + 45478a1 commit 602cf6e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"displayName": "Technotherm",
"name": "homebridge-technotherm",
"version": "1.2.0",
"version": "1.2.1",
"description": "Controls for Technotherm electric radiators.",
"license": "Apache-2.0",
"repository": {
Expand Down
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 602cf6e

Please sign in to comment.