From 86d9e769f20e6fb70db1d37872bcff6c47d2cb88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Thu, 25 Mar 2021 11:31:49 +0100 Subject: [PATCH] disconnect socket on system disconnect event. --- src/component/internal/messages.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/component/internal/messages.ts b/src/component/internal/messages.ts index 0e1266cb..daf4c97e 100644 --- a/src/component/internal/messages.ts +++ b/src/component/internal/messages.ts @@ -40,6 +40,7 @@ export interface NekoEvents { } export class NekoMessages extends EventEmitter { + private websocket: NekoWebSocket private state: NekoState private _log: Logger @@ -48,7 +49,9 @@ export class NekoMessages extends EventEmitter { this._log = new Logger('messages') this.state = state - websocket.on('message', async (event: string, payload: any) => { + this.websocket = websocket + + this.websocket.on('message', async (event: string, payload: any) => { // @ts-ignore if (typeof this[event] === 'function') { // @ts-ignore @@ -95,6 +98,7 @@ export class NekoMessages extends EventEmitter { protected [EVENT.SYSTEM_DISCONNECT]({ message }: message.SystemDisconnect) { this._log.debug('EVENT.SYSTEM_DISCONNECT') + this.websocket.disconnect(new Error(message)) this.emit('connection.disconnect', message) }