X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FUIWebSocketServer.ts;h=110695512093e77426937d1ecc3b74fbb858e139;hb=e3822d6f1b40477f7308ad70c290ed2c4106c585;hp=bc10db1cc785d5659c12418e91288e9a38a6beba;hpb=1f5df42ad17d09d3a1f53f6618eba325a403d7ad;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/UIWebSocketServer.ts b/src/charging-station/UIWebSocketServer.ts index bc10db1c..11069551 100644 --- a/src/charging-station/UIWebSocketServer.ts +++ b/src/charging-station/UIWebSocketServer.ts @@ -1,4 +1,4 @@ -import { Protocol, ProtocolCommand, ProtocolRequest, ProtocolVersion } from '../types/UiProtocol'; +import { Protocol, ProtocolCommand, ProtocolRequest, ProtocolVersion } from '../types/UIProtocol'; import WebSocket, { OPEN, Server, ServerOptions } from 'ws'; import AbstractUIService from './ui-websocket-services/AbstractUIService'; @@ -23,7 +23,7 @@ export default class UIWebSocketServer extends Server { } } - public broadcastToClients(message: string | Record): void { + public broadcastToClients(message: string): void { for (const client of this.clients) { if (client?.readyState === OPEN) { client.send(message); @@ -34,9 +34,13 @@ export default class UIWebSocketServer extends Server { public start(): void { this.on('connection', (socket: WebSocket, request: IncomingMessage): void => { const protocolIndex = socket.protocol.indexOf(Protocol.UI); - const version = socket.protocol.substring(protocolIndex + Protocol.UI.length) as ProtocolVersion; + const version = socket.protocol.substring( + protocolIndex + Protocol.UI.length + ) as ProtocolVersion; if (!this.uiServices.has(version)) { - throw new BaseError(`Could not find a UI service implementation for UI protocol version ${version}`); + throw new BaseError( + `Could not find a UI service implementation for UI protocol version ${version}` + ); } // FIXME: check connection validity socket.on('message', (messageData) => { @@ -47,9 +51,16 @@ export default class UIWebSocketServer extends Server { } else { throw new BaseError('UI protocol request is not iterable'); } - this.uiServices.get(version).handleMessage(command, payload).catch(() => { - logger.error(`${this.logPrefix()} Error while handling command %s message: %j`, command, payload); - }); + this.uiServices + .get(version) + .messageHandler(command, payload) + .catch(() => { + logger.error( + `${this.logPrefix()} Error while handling command %s message: %j`, + command, + payload + ); + }); }); socket.on('error', (error) => { logger.error(`${this.logPrefix()} Error on WebSocket: %j`, error);