mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-14 06:02:36 +03:00
OP-2481 Fixup
This commit is contained in:
@@ -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<Record<string, Subscription[K]>>
|
||||
}> = {};
|
||||
@@ -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
|
||||
|
||||
@@ -74,6 +74,8 @@ export default class PriceFeedSubscription<T extends SubscriptionType = Subscrip
|
||||
|
||||
readonly type: T;
|
||||
|
||||
private isClosedIntentionally: boolean = false;
|
||||
|
||||
constructor(
|
||||
type: T,
|
||||
url: string,
|
||||
@@ -108,7 +110,7 @@ export default class PriceFeedSubscription<T extends SubscriptionType = Subscrip
|
||||
|
||||
this.ws.onclose = (e) => {
|
||||
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<T extends SubscriptionType = Subscrip
|
||||
}
|
||||
|
||||
kill() {
|
||||
this.isClosedIntentionally = true;
|
||||
this.ws?.close();
|
||||
delete this.ws;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user