X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Fui-websocket-services%2FAbstractUIService.ts;h=42cfa428f1373cc36e1b67bca96661d1eebf6b19;hb=3e0905a14af7b7e0a96e859d6c4c615044845d54;hp=2dd6a2008465dbf29a336b7e010156bbb676f33b;hpb=9f2e313013116428f5bce2be59e2f5c07502c026;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ui-websocket-services/AbstractUIService.ts b/src/charging-station/ui-websocket-services/AbstractUIService.ts index 2dd6a200..42cfa428 100644 --- a/src/charging-station/ui-websocket-services/AbstractUIService.ts +++ b/src/charging-station/ui-websocket-services/AbstractUIService.ts @@ -16,12 +16,12 @@ export default abstract class AbstractUIService { ]); } - public async handleMessage(command: ProtocolCommand, payload: JsonType): Promise { + public async messageHandler(command: ProtocolCommand, payload: JsonType): Promise { let messageResponse: JsonType; if (this.messageHandlers.has(command)) { try { // Call the method to build the message response - messageResponse = await this.messageHandlers.get(command)(payload) as JsonType; + messageResponse = (await this.messageHandlers.get(command)(payload)) as JsonType; } catch (error) { // Log logger.error(this.uiWebSocketServer.logPrefix() + ' Handle message error: %j', error); @@ -29,20 +29,23 @@ export default abstract class AbstractUIService { } } else { // Throw exception - throw new BaseError(`${command} is not implemented to handle message payload ${JSON.stringify(payload, null, 2)}`); + throw new BaseError( + `${command} is not implemented to handle message payload ${JSON.stringify( + payload, + null, + 2 + )}` + ); } // Send the built message response this.uiWebSocketServer.broadcastToClients(this.buildProtocolMessage(command, messageResponse)); } - protected buildProtocolMessage( - command: ProtocolCommand, - payload: JsonType, - ): string { + protected buildProtocolMessage(command: ProtocolCommand, payload: JsonType): string { return JSON.stringify([command, payload]); } - private handleListChargingStations(): Set { - return this.uiWebSocketServer.chargingStations; + private handleListChargingStations(): string[] { + return Array.from(this.uiWebSocketServer.chargingStations); } }