Add UUIDv4 id to UI protocol message structure
[e-mobility-charging-stations-simulator.git] / src / charging-station / ui-server / ui-services / AbstractUIService.ts
index ba8aa80c374583e22c3101b517d0a27c52c0225b..a26af3967ccc35f192111f2d8b44d4e778249a8a 100644 (file)
@@ -26,11 +26,12 @@ export default abstract class AbstractUIService {
   }
 
   public async messageHandler(request: RawData): Promise<void> {
+    let messageId: string;
     let command: ProtocolCommand;
     let payload: JsonType;
     const protocolRequest = JSON.parse(request.toString()) as ProtocolRequest;
     if (Utils.isIterable(protocolRequest)) {
-      [command, payload] = protocolRequest;
+      [messageId, command, payload] = protocolRequest;
     } else {
       throw new BaseError('UI protocol request is not iterable');
     }
@@ -55,11 +56,15 @@ export default abstract class AbstractUIService {
       );
     }
     // Send the message response
-    this.uiServer.sendResponse(this.buildProtocolMessage(command, messageResponse));
+    this.uiServer.sendResponse(this.buildProtocolMessage(messageId, command, messageResponse));
   }
 
-  protected buildProtocolMessage(command: ProtocolCommand, payload: JsonType): string {
-    return JSON.stringify([command, payload]);
+  protected buildProtocolMessage(
+    messageId: string,
+    command: ProtocolCommand,
+    payload: JsonType
+  ): string {
+    return JSON.stringify([messageId, command, payload]);
   }
 
   private handleListChargingStations(): JsonType {