From aa9b0a1ec352572d91076a4d0cfa78b53a46c759 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 5 Mar 2024 20:08:57 +0100 Subject: [PATCH] fix(ui): remove WS event listeners at main page unmount MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- ui/web/src/composables/UIClient.ts | 8 ++++++ ui/web/src/views/ChargingStationsView.vue | 32 ++++++++++++++++------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/ui/web/src/composables/UIClient.ts b/ui/web/src/composables/UIClient.ts index 04b703e3..8a86d150 100644 --- a/ui/web/src/composables/UIClient.ts +++ b/ui/web/src/composables/UIClient.ts @@ -53,6 +53,14 @@ export class UIClient { this.ws?.addEventListener(event, listener, options) } + public unregisterWSEventListener( + event: K, + listener: (event: WebSocketEventMap[K]) => void, + options?: boolean | AddEventListenerOptions + ) { + this.ws?.removeEventListener(event, listener, options) + } + public async simulatorState(): Promise { return this.sendRequest(ProcedureName.SIMULATOR_STATE, {}) } diff --git a/ui/web/src/views/ChargingStationsView.vue b/ui/web/src/views/ChargingStationsView.vue index 109803f4..621c7122 100644 --- a/ui/web/src/views/ChargingStationsView.vue +++ b/ui/web/src/views/ChargingStationsView.vue @@ -18,7 +18,7 @@ state.uiServerIndex ] ) - initializeWSEventListeners() + registerWSEventListeners() uiClient.registerWSEventListener( 'open', () => { @@ -41,7 +41,7 @@ getFromLocalStorage('uiServerConfigurationIndex', 0) ] ) - initializeWSEventListeners() + registerWSEventListeners() }, { once: true } ) @@ -115,7 +115,7 @@