From 3133b91cd6761645ddeabac18e6db8d34a10356e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 20 Nov 2023 21:00:14 +0100 Subject: [PATCH] perf(ui): only build WS payload if connection is opened 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 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ui/web/src/composables/UIClient.ts b/ui/web/src/composables/UIClient.ts index b78d6a0b..387d73d2 100644 --- a/ui/web/src/composables/UIClient.ts +++ b/ui/web/src/composables/UIClient.ts @@ -145,13 +145,12 @@ export class UIClient { data: RequestPayload, ): Promise { return new Promise((resolve, reject) => { - const uuid = crypto.randomUUID(); - const msg = JSON.stringify([uuid, command, data]); - if (this.ws.readyState !== WebSocket.OPEN) { this.openWS(); } if (this.ws.readyState === WebSocket.OPEN) { + const uuid = crypto.randomUUID(); + const msg = JSON.stringify([uuid, command, data]); const sendTimeout = setTimeout(() => { this.deleteResponseHandler(uuid); return reject(new Error(`Send request '${command}' message timeout`)); -- 2.34.1