diff --git a/src/services/OrionAggregator/ws/index.ts b/src/services/OrionAggregator/ws/index.ts index 4ea7e0b..db8e06b 100644 --- a/src/services/OrionAggregator/ws/index.ts +++ b/src/services/OrionAggregator/ws/index.ts @@ -144,6 +144,8 @@ const isSubType = (subType: string): subType is keyof Subscription => Object.val class OrionAggregatorWS { private ws: WebSocket | undefined; + private isClosedIntentionally: boolean = false; + private subscriptions: Partial<{ [K in keyof Subscription]: Partial> }> = {}; @@ -254,6 +256,7 @@ class OrionAggregatorWS { } destroy() { + this.isClosedIntentionally = true; this.ws?.close(); delete this.ws; } @@ -261,7 +264,7 @@ class OrionAggregatorWS { init(isReconnect = false) { this.ws = new WebSocket(this.wsUrl); this.ws.onclose = (e) => { - if (this.ws) this.init(true); + if (!this.isClosedIntentionally) this.init(true); }; this.ws.onopen = () => { // Re-subscribe to all subscriptions diff --git a/src/services/PriceFeed/ws/PriceFeedSubscription.ts b/src/services/PriceFeed/ws/PriceFeedSubscription.ts index 513f9f8..36f257b 100644 --- a/src/services/PriceFeed/ws/PriceFeedSubscription.ts +++ b/src/services/PriceFeed/ws/PriceFeedSubscription.ts @@ -74,6 +74,8 @@ export default class PriceFeedSubscription { if (this.heartbeatInterval) clearInterval(this.heartbeatInterval); - if (this.ws) this.init(); + if (!this.isClosedIntentionally) this.init(); }; this.heartbeatInterval = setInterval(() => { @@ -117,7 +119,7 @@ export default class PriceFeedSubscription