From: Jérôme Benoit Date: Mon, 1 Aug 2022 13:49:11 +0000 (+0200) Subject: Add UUIDv4 id to UI protocol message structure X-Git-Tag: v1.1.65~25 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=98a5256a3c3b89925e12e87debab6fd1f78aea2e;p=e-mobility-charging-stations-simulator.git Add UUIDv4 id to UI protocol message structure Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ui-server/ui-services/AbstractUIService.ts b/src/charging-station/ui-server/ui-services/AbstractUIService.ts index ba8aa80c..a26af396 100644 --- a/src/charging-station/ui-server/ui-services/AbstractUIService.ts +++ b/src/charging-station/ui-server/ui-services/AbstractUIService.ts @@ -26,11 +26,12 @@ export default abstract class AbstractUIService { } public async messageHandler(request: RawData): Promise { + 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 { diff --git a/src/types/UIProtocol.ts b/src/types/UIProtocol.ts index 1756c0fa..24efff19 100644 --- a/src/types/UIProtocol.ts +++ b/src/types/UIProtocol.ts @@ -19,7 +19,7 @@ export enum ProtocolCommand { STOP_TRANSACTION = 'stopTransaction', } -export type ProtocolRequest = [ProtocolCommand, JsonType]; +export type ProtocolRequest = [string, ProtocolCommand, JsonType]; export type ProtocolRequestHandler = ( payload: JsonType