UI protocol: cleanup version handling code
[e-mobility-charging-stations-simulator.git] / src / charging-station / ui-server / UIWebSocketServer.ts
index 83d074cf3414edd9afd1d53b3b6abe64adfda735..4ac5d23561abcdd9e25a29a8fd12d22d37ba18d8 100644 (file)
@@ -28,16 +28,16 @@ export default class UIWebSocketServer extends AbstractUIServer {
 
   public start(): void {
     this.webSocketServer.on('connection', (ws: WebSocket, req: IncomingMessage): void => {
-      const [protocol, version] = UIServiceUtils.getProtocolAndVersion(ws.protocol);
-      if (UIServiceUtils.isProtocolAndVersionSupported(protocol, version) === false) {
+      if (UIServiceUtils.isProtocolAndVersionSupported(ws.protocol) === false) {
         logger.error(
           `${this.logPrefix(
             moduleName,
             'start.server.onconnection'
-          )} Unsupported UI protocol version: '${protocol}${version}'`
+          )} Unsupported UI protocol version: '${ws.protocol}'`
         );
         ws.close(WebSocketCloseEventStatusCode.CLOSE_PROTOCOL_ERROR);
       }
+      const [, version] = UIServiceUtils.getProtocolAndVersion(ws.protocol);
       this.registerProtocolVersionUIService(version);
       ws.on('message', (rawData) => {
         const request = this.validateRawDataRequest(rawData);