Merge pull request #3706 from mempool/mononaut/reconnect-dead-websocket

reconnect websocket after closed by server
This commit is contained in:
softsimon 2023-11-30 18:26:18 +09:00 committed by GitHub
commit 6b978f9262
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -76,17 +76,22 @@ export class WebsocketService {
this.stateService.resetChainTip();
this.websocketSubject.complete();
this.subscription.unsubscribe();
this.websocketSubject = webSocket<WebsocketResponse>(
this.webSocketUrl.replace('{network}', this.network ? '/' + this.network : '')
);
this.startSubscription();
this.reconnectWebsocket();
});
}
}
reconnectWebsocket(retrying = false, hasInitData = false) {
console.log('reconnecting websocket');
this.websocketSubject.complete();
this.subscription.unsubscribe();
this.websocketSubject = webSocket<WebsocketResponse>(
this.webSocketUrl.replace('{network}', this.network ? '/' + this.network : '')
);
this.startSubscription(retrying, hasInitData);
}
startSubscription(retrying = false, hasInitData = false) {
if (!hasInitData) {
this.stateService.isLoadingWebSocket$.next(true);
@ -237,7 +242,7 @@ export class WebsocketService {
this.goneOffline = true;
this.stateService.connectionState$.next(0);
window.setTimeout(() => {
this.startSubscription(true);
this.reconnectWebsocket(true);
}, retryDelay);
}