Add helper in LRU cache to get cache key
[e-mobility-charging-stations-simulator.git] / src / charging-station / ui-server / UIWebSocketServer.ts
index fcfc309708811f88eeef7857c6dfec13639f0ce4..c67da00e1f6c8643e0f35032ff759d6bfe0cb0f0 100644 (file)
@@ -1,5 +1,4 @@
 import { Protocol, ProtocolVersion } from '../../types/UIProtocol';
-import WebSocket, { OPEN, Server } from 'ws';
 
 import { AbstractUIServer } from './AbstractUIServer';
 import Configuration from '../../utils/Configuration';
@@ -7,16 +6,17 @@ import { IncomingMessage } from 'http';
 import { ServerOptions } from '../../types/ConfigurationData';
 import UIServiceFactory from './ui-services/UIServiceFactory';
 import Utils from '../../utils/Utils';
+import WebSocket from 'ws';
 import logger from '../../utils/Logger';
 
 export default class UIWebSocketServer extends AbstractUIServer {
   public constructor(options?: ServerOptions) {
     super();
-    this.uiServer = new Server(options ?? Configuration.getUIServer().options);
+    this.server = new WebSocket.Server(options ?? Configuration.getUIServer().options);
   }
 
   public start(): void {
-    this.uiServer.on('connection', (socket: WebSocket, request: IncomingMessage): void => {
+    this.server.on('connection', (socket: WebSocket, request: IncomingMessage): void => {
       const protocolIndex = socket.protocol.indexOf(Protocol.UI);
       const version = socket.protocol.substring(
         protocolIndex + Protocol.UI.length
@@ -40,7 +40,7 @@ export default class UIWebSocketServer extends AbstractUIServer {
   }
 
   public stop(): void {
-    this.uiServer.close();
+    this.server.close();
   }
 
   public sendResponse(message: string): void {
@@ -52,8 +52,8 @@ export default class UIWebSocketServer extends AbstractUIServer {
   }
 
   private broadcastToClients(message: string): void {
-    for (const client of (this.uiServer as Server).clients) {
-      if (client?.readyState === OPEN) {
+    for (const client of (this.server as WebSocket.Server).clients) {
+      if (client?.readyState === WebSocket.OPEN) {
         client.send(message);
       }
     }