From 352f58e09acda3c7ce17128f3b1cf378cba7e2c4 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Fri, 31 Dec 2021 00:45:50 +0000 Subject: [PATCH] clear pong timer for any incoming data --- src/websocket-client.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/websocket-client.ts b/src/websocket-client.ts index 2eca7c7..1398585 100644 --- a/src/websocket-client.ts +++ b/src/websocket-client.ts @@ -544,6 +544,9 @@ export class WebsocketClient extends EventEmitter { private onWsMessage(event, wsKey: WsKey) { try { + // any message can clear the pong timer - wouldn't get a message if the ws dropped + this.clearPongTimer(wsKey); + const msg = JSON.parse(event && event.data || event); if ('success' in msg || msg?.pong) { this.onWsMessageResponse(msg, wsKey); @@ -579,7 +582,6 @@ export class WebsocketClient extends EventEmitter { private onWsMessageResponse(response: any, wsKey: WsKey) { if (isWsPong(response)) { this.logger.silly('Received pong', { ...loggerCategory, wsKey }); - this.clearPongTimer(wsKey); } else { this.emit('response', response); }