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) }