close previous testConnect attempts (#4598)

* close previous testConnect attempts

* remove onerror handler when canceling previous attempt

Co-authored-by: Jeremy Letto <jeremy.letto@datasite.com>
This commit is contained in:
Jeremy Letto
2022-03-22 17:42:58 -05:00
committed by GitHub
co-authored by Jeremy Letto
parent 4899b6cfef
commit 6d200d17b7
@@ -8,6 +8,8 @@ import { SessionPersistence } from '../persistence';
export class WebSocketService {
private socket: WebSocket;
private testSocket: WebSocket;
private webClient: WebClient;
private keepAliveService: KeepAliveService;
@@ -104,6 +106,11 @@ export class WebSocketService {
}
private testWebSocket(url: string): void {
if (this.testSocket) {
this.testSocket.onerror = null;
this.testSocket.close();
}
const socket = new WebSocket(url);
socket.binaryType = 'arraybuffer';
@@ -118,5 +125,11 @@ export class WebSocketService {
socket.onerror = () => {
SessionPersistence.testConnectionFailed();
};
socket.onclose = () => {
this.testSocket = null;
}
this.testSocket = socket;
}
}