diff --git a/lib/BaseConnection.d.ts b/lib/BaseConnection.d.ts index 3fac108..91bdf5a 100644 --- a/lib/BaseConnection.d.ts +++ b/lib/BaseConnection.d.ts @@ -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; } diff --git a/lib/IOClientConnection.js b/lib/IOClientConnection.js index fdd3b1e..96ec253 100644 --- a/lib/IOClientConnection.js +++ b/lib/IOClientConnection.js @@ -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([ diff --git a/package.json b/package.json index 4d836d5..7e212d2 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/BaseConnection.ts b/src/BaseConnection.ts index 9358f3e..bf3404e 100644 --- a/src/BaseConnection.ts +++ b/src/BaseConnection.ts @@ -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( diff --git a/src/IOClientConnection.ts b/src/IOClientConnection.ts index 05e4429..014f661 100644 --- a/src/IOClientConnection.ts +++ b/src/IOClientConnection.ts @@ -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)) + }) } } \ No newline at end of file