Fix Json type definition naming
[e-mobility-charging-stations-simulator.git] / src / charging-station / UIWebSocketServer.ts
index a899076338709c1a19baa10d6d91e88fa7101473..110695512093e77426937d1ecc3b74fbb858e139 100644 (file)
@@ -7,7 +7,7 @@ import Configuration from '../utils/Configuration';
 import { IncomingMessage } from 'http';
 import UIServiceFactory from './ui-websocket-services/UIServiceFactory';
 import Utils from '../utils/Utils';
-import getLogger from '../utils/Logger';
+import logger from '../utils/Logger';
 
 export default class UIWebSocketServer extends Server {
   public readonly chargingStations: Set<string>;
@@ -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,12 +51,19 @@ export default class UIWebSocketServer extends Server {
         } else {
           throw new BaseError('UI protocol request is not iterable');
         }
-        this.uiServices.get(version).handleMessage(command, payload).catch(() => {
-          getLogger().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) => {
-        getLogger().error(`${this.logPrefix()} Error on WebSocket: %j`, error);
+        logger.error(`${this.logPrefix()} Error on WebSocket: %j`, error);
       });
     });
   }