-import { ProtocolCommand, ProtocolRequestHandler } from '../../../../types/UIProtocol';
+import { ProtocolCommand, ProtocolRequestHandler, ProtocolVersion } from '../../../../types/UIProtocol';
import AbstractUIService from '../AbstractUIService';
import BaseError from '../../../../exception/BaseError';
constructor(webSocketServer: WebSocketServer) {
super(webSocketServer);
this.messageHandlers = new Map<ProtocolCommand, ProtocolRequestHandler>([
+ [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<string, unknown>): Promise<void> {
+ async handleMessage(version: ProtocolVersion, command: ProtocolCommand, payload: Record<string, unknown>): Promise<void> {
let messageResponse: Record<string, unknown>;
if (this.messageHandlers.has(command) && command !== ProtocolCommand.UNKNOWN) {
try {
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<string, unknown>) {
+ return this.chargingStations;
}
private handleStartTransaction(payload: Record<string, unknown>) { }