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'); }