Skip to content

Commit

Permalink
Feat/add socket.io manager events (#10)
Browse files Browse the repository at this point in the history
* retransmit socket.io manager events
  • Loading branch information
pnts-se authored Aug 22, 2023
1 parent aa98f15 commit 2a6a108
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/BaseConnection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export declare interface BaseConnection {
on(event: 'close', listener: () => void): this;
on(event: 'connect', listener: () => void): this;
on(event: 'reconnect', listener: () => void): this;
on(event: 'reconnect_attempt', listener: (attempt: number) => void): this;
on(event: 'reconnect_error', listener: (error: Error) => void): this;
on(event: 'error', listener: (error: Error) => void): this;
on(event: 'notification', listener: InboundNotification): this;
on(event: 'request', listener: InboundRequest): this;
}
Expand Down
10 changes: 10 additions & 0 deletions lib/IOClientConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ class IOClientConnection extends BaseConnection_1.BaseConnection {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(error) => result(error, null));
});
// Listen and re-transmit events from manager.
this.socket.io.on("error", (error) => {
this.emit("error", (error));
});
this.socket.io.on("reconnect_attempt", (attempt) => {
this.emit("reconnect_attempt", (attempt));
});
this.socket.io.on("reconnect_error", (error) => {
this.emit("reconnect_error", (error));
});
}
}
__decorate([
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.2",
"version": "0.6.0",
"description": "Common code for edumeet",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
3 changes: 3 additions & 0 deletions src/BaseConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export declare interface BaseConnection {
on(event: 'close', listener: () => void): this;
on(event: 'connect', listener: () => void): this;
on(event: 'reconnect', listener: () => void): this;
on(event: 'reconnect_attempt', listener: (attempt: number) => void): this;
on(event: 'reconnect_error', listener: (error: Error) => void): this;
on(event: 'error', listener: (error: Error) => void): this;

// Inbound messages
on(
Expand Down
11 changes: 11 additions & 0 deletions src/IOClientConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,16 @@ export class IOClientConnection extends BaseConnection {
(error: any) => result(error, null)
);
});

// Listen and re-transmit events from manager.
this.socket.io.on("error", (error: Error) => {
this.emit("error", (error))
})
this.socket.io.on("reconnect_attempt", (attempt: number) => {
this.emit("reconnect_attempt", (attempt))
})
this.socket.io.on("reconnect_error", (error: Error) => {
this.emit("reconnect_error", (error))
})
}
}

0 comments on commit 2a6a108

Please sign in to comment.