Add a configuration section for the UI WS server
[e-mobility-charging-stations-simulator.git] / src / charging-station / UIWebSocketServer.ts
index f941b138d505540f3fa3c12bee916ffda4e28ec8..5903b85c48cad0112b0eacee9a64dc6f09e9ed0d 100644 (file)
@@ -1,24 +1,25 @@
 import { Protocol, ProtocolCommand, ProtocolRequest, ProtocolVersion } from '../types/UIProtocol';
+import WebSocket, { OPEN, Server, ServerOptions } from 'ws';
 
 import AbstractUIService from './UIWebSocketServices/AbstractUIService';
 import BaseError from '../exception/BaseError';
+import Configuration from '../utils/Configuration';
 import { IncomingMessage } from 'http';
 import UIServiceFactory from './UIWebSocketServices/UIServiceFactory';
 import Utils from '../utils/Utils';
-import WebSocket from 'ws';
 import logger from '../utils/Logger';
 
-export default class UIWebSocketServer extends WebSocket.Server {
+export default class UIWebSocketServer extends Server {
   public uiService: AbstractUIService;
 
-  public constructor(options?: WebSocket.ServerOptions, callback?: () => void) {
+  public constructor(options?: ServerOptions, callback?: () => void) {
     // Create the WebSocket Server
-    super(options ?? { port: 80 }, callback);
+    super(options ?? Configuration.getUIWebSocketServer().options, callback);
   }
 
   public broadcastToClients(message: string | Record<string, unknown>): void {
     for (const client of this.clients) {
-      if (client?.readyState === WebSocket.OPEN) {
+      if (client?.readyState === OPEN) {
         client.send(message);
       }
     }