From 5ffc5ed00c8c84d4025541c0228edb7b6dc2eb91 Mon Sep 17 00:00:00 2001 From: Aleksandr Kraiz Date: Sat, 21 May 2022 11:22:39 +0400 Subject: [PATCH] Fix WS connection closing --- src/services/PriceFeed/ws/PriceFeedSubscription.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/services/PriceFeed/ws/PriceFeedSubscription.ts b/src/services/PriceFeed/ws/PriceFeedSubscription.ts index ae93f54..4e34390 100644 --- a/src/services/PriceFeed/ws/PriceFeedSubscription.ts +++ b/src/services/PriceFeed/ws/PriceFeedSubscription.ts @@ -99,7 +99,9 @@ export default class PriceFeedSubscription { this.callback(parseResult.data); }; - this.ws.onclose = () => this.init(); + this.ws.onclose = (e) => { + if (e.code !== 4000) this.init(); + }; this.heartbeatInterval = setInterval(() => { this.ws?.send('heartbeat'); @@ -108,6 +110,6 @@ export default class PriceFeedSubscription { kill() { if (this.heartbeatInterval) clearInterval(this.heartbeatInterval); - this.ws?.close(); + this.ws?.close(4000); } }