Fix WS connection closing

This commit is contained in:
Aleksandr Kraiz
2022-05-21 11:22:39 +04:00
parent 246070d064
commit 5ffc5ed00c

View File

@@ -99,7 +99,9 @@ export default class PriceFeedSubscription<S extends SubscriptionType> {
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<S extends SubscriptionType> {
kill() {
if (this.heartbeatInterval) clearInterval(this.heartbeatInterval);
this.ws?.close();
this.ws?.close(4000);
}
}