From 79bdf7b3e76ab3a7480615f5e7ee157d6566ce5a Mon Sep 17 00:00:00 2001 From: Chrystian Huot Date: Mon, 13 Jul 2020 08:24:48 -0400 Subject: [PATCH] Always reconnect websocket --- .../rdio-scanner/rdio-scanner.service.ts | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/client/src/app/components/rdio-scanner/rdio-scanner.service.ts b/client/src/app/components/rdio-scanner/rdio-scanner.service.ts index 138a912..00d99d8 100644 --- a/client/src/app/components/rdio-scanner/rdio-scanner.service.ts +++ b/client/src/app/components/rdio-scanner/rdio-scanner.service.ts @@ -722,10 +722,20 @@ export class AppRdioScannerService implements OnDestroy { this.webSocket.close(); this.webSocket = undefined; - - clearTimeout(this.webSocketTimeout); - clearInterval(this.webSocketInterval); } + + if (this.webSocketTimeout) { + clearTimeout(this.webSocketTimeout); + + this.webSocketTimeout = undefined; + } + + if (this.webSocketInterval) { + clearInterval(this.webSocketInterval); + + this.webSocketInterval = undefined; + } + } private webSocketKeepAlive(): void { @@ -751,11 +761,7 @@ export class AppRdioScannerService implements OnDestroy { this.webSocket = new WebSocket(webSocketUrl); - this.webSocket.onclose = (ev: CloseEvent) => { - if (ev.code !== 1000) { - this.webSocketReconnect(); - } - }; + this.webSocket.onclose = () => this.webSocketReconnect(); this.webSocket.onerror = () => { };