Introduce a websocket ping check that closes the socket if no response.
This commit is contained in:
parent
b60d9cdfbc
commit
5d4ce44627
@ -74,6 +74,10 @@ class WebsocketHandler {
|
|||||||
'git-commit': this.latestGitCommitHash
|
'git-commit': this.latestGitCommitHash
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (parsedMessage.action === 'ping') {
|
||||||
|
client.send(JSON.stringify({'pong': true}));
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,8 @@ export class WebsocketService {
|
|||||||
private trackingTxId: string | null = null;
|
private trackingTxId: string | null = null;
|
||||||
private trackingAddress: string | null = null;
|
private trackingAddress: string | null = null;
|
||||||
private latestGitCommit = '';
|
private latestGitCommit = '';
|
||||||
|
private onlineCheckTimeout: number;
|
||||||
|
private onlineCheckTimeoutTwo: number;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private stateService: StateService,
|
private stateService: StateService,
|
||||||
@ -107,13 +109,12 @@ export class WebsocketService {
|
|||||||
}
|
}
|
||||||
this.stateService.isOffline$.next(false);
|
this.stateService.isOffline$.next(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.startOnlineCheck();
|
||||||
},
|
},
|
||||||
(err: Error) => {
|
(err: Error) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
this.goneOffline = true;
|
this.goOffline();
|
||||||
this.stateService.isOffline$.next(true);
|
|
||||||
console.log('Error, retrying in 10 sec');
|
|
||||||
window.setTimeout(() => this.startSubscription(), 10000);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,4 +136,26 @@ export class WebsocketService {
|
|||||||
this.websocketSubject.next({action: 'want', data: data});
|
this.websocketSubject.next({action: 'want', data: data});
|
||||||
this.lastWant = data;
|
this.lastWant = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
goOffline() {
|
||||||
|
this.goneOffline = true;
|
||||||
|
this.stateService.isOffline$.next(true);
|
||||||
|
console.log('Error, retrying in 10 sec');
|
||||||
|
window.setTimeout(() => this.startSubscription(), 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
startOnlineCheck() {
|
||||||
|
clearTimeout(this.onlineCheckTimeout);
|
||||||
|
clearTimeout(this.onlineCheckTimeoutTwo);
|
||||||
|
|
||||||
|
this.onlineCheckTimeout = window.setTimeout(() => {
|
||||||
|
this.websocketSubject.next({action: 'ping'});
|
||||||
|
this.onlineCheckTimeoutTwo = window.setTimeout(() => {
|
||||||
|
if (!this.goneOffline) {
|
||||||
|
this.websocketSubject.complete();
|
||||||
|
this.goOffline();
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
}, 10000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user