Skip to content

Commit

Permalink
Update reconnect logic
Browse files Browse the repository at this point in the history
  • Loading branch information
havfo committed Jun 7, 2023
1 parent 58b9d2c commit f87c557
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/BaseConnection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type InboundRequest = (request: SocketMessage, respond: (response: any) =
export declare interface BaseConnection {
on(event: 'close', listener: () => void): this;
on(event: 'connect', listener: () => void): this;
on(event: 'reconnect', listener: (attempt: number) => void): this;
on(event: 'reconnect', listener: () => void): this;
on(event: 'notification', listener: InboundNotification): this;
on(event: 'request', listener: InboundRequest): this;
}
Expand Down
7 changes: 5 additions & 2 deletions lib/IOClientConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,12 @@ class IOClientConnection extends BaseConnection_1.BaseConnection {
logger.debug('handleSocket() connected');
this.emit('connect');
});
this.socket.once('disconnect', () => {
this.socket.once('disconnect', (reason) => {
logger.debug('socket disconnected');
this.close();
if (reason === 'io server disconnect')
this.close();
else
this.emit('reconnect');
});
this.socket.on('notification', (notification) => {
logger.debug('"notification" event [notification: %o]', notification);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "edumeet-common",
"version": "0.5.1",
"version": "0.5.2",
"description": "Common code for edumeet",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/BaseConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export declare interface BaseConnection {
// Connection events
on(event: 'close', listener: () => void): this;
on(event: 'connect', listener: () => void): this;
on(event: 'reconnect', listener: (attempt: number) => void): this;
on(event: 'reconnect', listener: () => void): this;

// Inbound messages
on(
Expand Down
7 changes: 5 additions & 2 deletions src/IOClientConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,13 @@ export class IOClientConnection extends BaseConnection {
this.emit('connect');
});

this.socket.once('disconnect', () => {
this.socket.once('disconnect', (reason) => {
logger.debug('socket disconnected');

this.close();
if (reason === 'io server disconnect')
this.close();
else
this.emit('reconnect');
});

this.socket.on('notification', (notification) => {
Expand Down

0 comments on commit f87c557

Please # to comment.