Improved network switching.

This commit is contained in:
softsimon
2020-05-10 12:31:57 +07:00
parent e4d54ebb14
commit 756caf2c53
3 changed files with 38 additions and 30 deletions

View File

@@ -24,14 +24,20 @@ export class WebsocketService {
private onlineCheckTimeout: number;
private onlineCheckTimeoutTwo: number;
private subscription: Subscription;
private network = '';
constructor(
private stateService: StateService,
) {
this.websocketSubject = webSocket<WebsocketResponse | any>(WEB_SOCKET_URL + '/' + this.stateService.network);
this.network = this.stateService.network;
this.websocketSubject = webSocket<WebsocketResponse | any>(WEB_SOCKET_URL + '/' + this.network);
this.startSubscription();
this.stateService.networkChanged$.subscribe((network) => {
if (network === this.network) {
return;
}
this.network = network;
clearTimeout(this.onlineCheckTimeout);
clearTimeout(this.onlineCheckTimeoutTwo);