From: Jérôme Benoit Date: Mon, 20 Nov 2023 20:00:14 +0000 (+0100) Subject: perf(ui): only build WS payload if connection is opened X-Git-Tag: v1.2.26~23 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=3133b91cd6761645ddeabac18e6db8d34a10356e;p=e-mobility-charging-stations-simulator.git perf(ui): only build WS payload if connection is opened Signed-off-by: Jérôme Benoit --- 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`));