@ariva-mds/mds
Version:
Stock market data
33 lines (32 loc) • 849 B
JavaScript
export class MdsConnectionState {
constructor(timeoutMs = 20000) {
this.isConnected = false;
this.isAuthenticated = false;
this.lastUpdate = new Date();
this.timeoutMs = timeoutMs;
}
connectionOpened() {
this.isConnected = true;
this.isAuthenticated = false;
this.lastUpdate = new Date();
}
connectionClosed() {
this.isConnected = false;
this.isAuthenticated = false;
}
authenticationAccepted() {
this.isAuthenticated = true;
}
authenticationEnded() {
this.isAuthenticated = false;
}
messageReceived() {
this.lastUpdate = new Date();
}
isTimedOut() {
return Date.now() - this.lastUpdate.getTime() >= this.timeoutMs;
}
forcedDisconnect() {
this.lastUpdate = new Date();
}
}