From 98a5256a3c3b89925e12e87debab6fd1f78aea2e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 1 Aug 2022 15:49:11 +0200 Subject: [PATCH] Add UUIDv4 id to UI protocol message structure MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../ui-server/ui-services/AbstractUIService.ts | 13 +++++++++---- src/types/UIProtocol.ts | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) 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 -- 2.34.1