perf(ui): only build WS payload if connection is opened
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 20 Nov 2023 20:00:14 +0000 (21:00 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 20 Nov 2023 20:00:14 +0000 (21:00 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
ui/web/src/composables/UIClient.ts

index b78d6a0b7fc2ed9dd41d09509ee26c953ac3114e..387d73d27529bfaf91e25f068bd9612ce53fb33c 100644 (file)
@@ -145,13 +145,12 @@ export class UIClient {
     data: RequestPayload,
   ): Promise<ResponsePayload> {
     return new Promise<ResponsePayload>((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`));