cleanup and unit tests (#4434)

* put socket.updateHistory behind SessionCommand

* rename /websocket files from .tsx to .ts

* add unit tests to websocket commands

* complete unit tests for webClient commands

* secure wss

Co-authored-by: Jeremy Letto <jeremy.letto@datasite.com>
This commit is contained in:
Jeremy Letto 2021-10-17 15:15:09 -05:00 committed by GitHub
parent e9ba195d7d
commit f75ff2a7c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 611 additions and 48 deletions

View file

@ -0,0 +1,43 @@
import { Subject } from "rxjs";
import { WebSocketService } from "./WebSocketService";
export class KeepAliveService {
private socket: WebSocketService;
private keepalivecb: NodeJS.Timeout;
private lastPingPending: boolean;
public disconnected$ = new Subject<void>();
constructor(socket: WebSocketService) {
this.socket = socket;
}
public startPingLoop(interval: number, ping: Function): void {
this.keepalivecb = setInterval(() => {
// check if the previous ping got no reply
if (this.lastPingPending) {
this.disconnected$.next();
}
// stop the ping loop if we"re disconnected
if (!this.socket.checkReadyState(WebSocket.OPEN)) {
this.endPingLoop();
return;
}
this.lastPingPending = true;
ping(() => this.lastPingPending = false);
}, interval);
}
public endPingLoop() {
clearInterval(this.keepalivecb);
this.keepalivecb = null;
}
public resetPingFlag() {
this.lastPingPending = false;
}
}