From c9c6246c4cd113a688f66fe36cd6475cb2585e38 Mon Sep 17 00:00:00 2001 From: Jannis Mattheis Date: Thu, 28 Nov 2019 21:04:03 +0100 Subject: [PATCH] Properly close ui websocket connections on browser close --- ui/src/index.tsx | 4 ++++ ui/src/message/WebSocketStore.ts | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ui/src/index.tsx b/ui/src/index.tsx index 2d22cfd..64ac1b1 100644 --- a/ui/src/index.tsx +++ b/ui/src/index.tsx @@ -75,6 +75,10 @@ const initStores = (): StoreMapping => { stores.currentUser.tryAuthenticate().catch(() => {}); + window.onbeforeunload = () => { + stores.wsStore.close(); + }; + ReactDOM.render( diff --git a/ui/src/message/WebSocketStore.ts b/ui/src/message/WebSocketStore.ts index c077083..fdd022e 100644 --- a/ui/src/message/WebSocketStore.ts +++ b/ui/src/message/WebSocketStore.ts @@ -50,5 +50,5 @@ export class WebSocketStore { this.ws = ws; }; - public close = () => this.ws && this.ws.close(); + public close = () => this.ws && this.ws.close(1000, 'WebSocketStore#close'); }