From d4b453f0e59f475247577255aa37f602a5c67fba Mon Sep 17 00:00:00 2001 From: Adhiraj Singh Date: Wed, 2 Dec 2020 14:21:06 +0530 Subject: [PATCH] Bug fix for sendLoginReq --- src/WAConnection/1.Validation.ts | 4 ++++ src/WAConnection/3.Connect.ts | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/WAConnection/1.Validation.ts b/src/WAConnection/1.Validation.ts index 5ff250d..2386af6 100644 --- a/src/WAConnection/1.Validation.ts +++ b/src/WAConnection/1.Validation.ts @@ -48,6 +48,10 @@ export class WAConnection extends Base { else json.push ('takeover') // send login every 10s const sendLoginReq = () => { + if (this.conn.readyState !== this.conn.OPEN) { + this.logger.warn('Received login timeout req when WS not open, ignoring...') + return + } this.logger.debug('sending login request') this.sendJSON(json, tag) this.initTimeout = setTimeout(sendLoginReq, 10_000) diff --git a/src/WAConnection/3.Connect.ts b/src/WAConnection/3.Connect.ts index 81a41f4..1851312 100644 --- a/src/WAConnection/3.Connect.ts +++ b/src/WAConnection/3.Connect.ts @@ -86,7 +86,8 @@ export class WAConnection extends Base { 'Sec-WebSocket-Extensions': 'permessage-deflate; client_max_window_bits', } }) - this.conn.addEventListener('message', ({data}) => this.onMessageRecieved(data as any)) + + this.conn.on('message', data => this.onMessageRecieved(data as any)) this.conn.on ('open', async () => { this.startKeepAliveRequest()