X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcharging-station%2Fui-websocket-services%2FAbstractUIService.ts;h=9fd577cdc37ec5b2c896edc76f1276ed93f097b0;hb=e3822d6f1b40477f7308ad70c290ed2c4106c585;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..9fd577cd 100644 --- a/src/charging-station/ui-websocket-services/AbstractUIService.ts +++ b/src/charging-station/ui-websocket-services/AbstractUIService.ts @@ -1,7 +1,7 @@ import { ProtocolCommand, ProtocolRequestHandler } from '../../types/UIProtocol'; import BaseError from '../../exception/BaseError'; -import { JsonType } from '../../types/JsonType'; +import { JsonObject } from '../../types/JsonType'; import UIWebSocketServer from '../UIWebSocketServer'; import logger from '../../utils/Logger'; @@ -16,12 +16,12 @@ export default abstract class AbstractUIService { ]); } - public async handleMessage(command: ProtocolCommand, payload: JsonType): Promise { - let messageResponse: JsonType; + public async messageHandler(command: ProtocolCommand, payload: JsonObject): Promise { + let messageResponse: JsonObject; 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 JsonObject; } 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: JsonObject): string { return JSON.stringify([command, payload]); } - private handleListChargingStations(): Set { - return this.uiWebSocketServer.chargingStations; + private handleListChargingStations(): string[] { + return Array.from(this.uiWebSocketServer.chargingStations); } }