X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcharging-station%2FWebSocketServices%2Fui%2F0.0.1%2FUIService.ts;h=f2db451240135a182d0921cac1bcc28c9a19f121;hb=ee0f106b09f38b1561d970ea4377eb199389298e;hp=8ca0c6dc9495624c0d0f376b89547f35cf157b48;hpb=3b04a25c2969e6f6d60c4b394656863673614e88;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/WebSocketServices/ui/0.0.1/UIService.ts b/src/charging-station/WebSocketServices/ui/0.0.1/UIService.ts index 8ca0c6dc..f2db4512 100644 --- a/src/charging-station/WebSocketServices/ui/0.0.1/UIService.ts +++ b/src/charging-station/WebSocketServices/ui/0.0.1/UIService.ts @@ -1,4 +1,4 @@ -import { ProtocolCommand, ProtocolRequestHandler } from '../../../../types/UIProtocol'; +import { ProtocolCommand, ProtocolRequestHandler, ProtocolVersion } from '../../../../types/UIProtocol'; import AbstractUIService from '../AbstractUIService'; import BaseError from '../../../../exception/BaseError'; @@ -11,12 +11,13 @@ export default class UIService extends AbstractUIService { constructor(webSocketServer: WebSocketServer) { super(webSocketServer); this.messageHandlers = new Map([ + [ProtocolCommand.LIST_CHARGING_STATIONS, this.handleListChargingStations.bind(this)], [ProtocolCommand.START_TRANSACTION, this.handleStartTransaction.bind(this)], [ProtocolCommand.STOP_TRANSACTION, this.handleStopTransaction.bind(this)], ]); } - async handleMessage(command: ProtocolCommand, payload: Record): Promise { + async handleMessage(version: ProtocolVersion, command: ProtocolCommand, payload: Record): Promise { let messageResponse: Record; if (this.messageHandlers.has(command) && command !== ProtocolCommand.UNKNOWN) { try { @@ -32,7 +33,11 @@ export default class UIService extends AbstractUIService { throw new BaseError(`${command} is not implemented to handle message payload ${JSON.stringify(payload, null, 2)}`); } // Send the built response - this.webSocketServer.broadcastToClients(messageResponse); + this.webSocketServer.broadcastToClients(this.buildProtocolMessage(version, command, messageResponse)); + } + + private handleListChargingStations(payload: Record) { + return this.chargingStations; } private handleStartTransaction(payload: Record) { }