reconnect websocket after closed by server
This commit is contained in:
parent
107e0be59f
commit
85c9c79699
@ -76,17 +76,22 @@ export class WebsocketService {
|
|||||||
|
|
||||||
this.stateService.resetChainTip();
|
this.stateService.resetChainTip();
|
||||||
|
|
||||||
this.websocketSubject.complete();
|
this.reconnectWebsocket();
|
||||||
this.subscription.unsubscribe();
|
|
||||||
this.websocketSubject = webSocket<WebsocketResponse>(
|
|
||||||
this.webSocketUrl.replace('{network}', this.network ? '/' + this.network : '')
|
|
||||||
);
|
|
||||||
|
|
||||||
this.startSubscription();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
startSubscription(retrying = false, hasInitData = false) {
|
||||||
if (!hasInitData) {
|
if (!hasInitData) {
|
||||||
this.stateService.isLoadingWebSocket$.next(true);
|
this.stateService.isLoadingWebSocket$.next(true);
|
||||||
@ -237,7 +242,7 @@ export class WebsocketService {
|
|||||||
this.goneOffline = true;
|
this.goneOffline = true;
|
||||||
this.stateService.connectionState$.next(0);
|
this.stateService.connectionState$.next(0);
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
this.startSubscription(true);
|
this.reconnectWebsocket(true);
|
||||||
}, retryDelay);
|
}, retryDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user