refactor(simulator): switch to internal modules export/import design
[e-mobility-charging-stations-simulator.git] / src / charging-station / ui-server / UIWebSocketServer.ts
index e217305f2e1e42f9644ad25f1467aceab57fa12b..c05ec6251278da2d3eed84711f975d7fb6e32ff1 100644 (file)
@@ -4,17 +4,19 @@ import type internal from 'stream';
 import { StatusCodes } from 'http-status-codes';
 import WebSocket, { type RawData, WebSocketServer } from 'ws';
 
-import { AbstractUIServer } from './AbstractUIServer';
-import { UIServerUtils } from './UIServerUtils';
-import type { UIServerConfiguration } from '../../types/ConfigurationData';
-import type { ProtocolRequest, ProtocolResponse } from '../../types/UIProtocol';
-import { WebSocketCloseEventStatusCode } from '../../types/WebSocket';
-import logger from '../../utils/Logger';
-import Utils from '../../utils/Utils';
+import {
+  type ProtocolRequest,
+  type ProtocolResponse,
+  type UIServerConfiguration,
+  WebSocketCloseEventStatusCode,
+} from '../../types';
+import { logger } from '../../utils/Logger';
+import { Utils } from '../../utils/Utils';
+import { AbstractUIServer, UIServerUtils } from '../internal';
 
 const moduleName = 'UIWebSocketServer';
 
-export default class UIWebSocketServer extends AbstractUIServer {
+export class UIWebSocketServer extends AbstractUIServer {
   private readonly webSocketServer: WebSocketServer;
 
   public constructor(protected readonly uiServerConfiguration: UIServerConfiguration) {
@@ -49,7 +51,7 @@ export default class UIWebSocketServer extends AbstractUIServer {
         this.responseHandlers.set(requestId, ws);
         this.uiServices
           .get(version)
-          .requestHandler(request)
+          ?.requestHandler(request)
           .catch(() => {
             /* Error caught by AbstractUIService */
           });
@@ -145,14 +147,16 @@ export default class UIWebSocketServer extends AbstractUIServer {
     }
   }
 
-  public logPrefix(modName?: string, methodName?: string, prefixSuffix?: string): string {
+  public logPrefix = (modName?: string, methodName?: string, prefixSuffix?: string): string => {
     const logMsgPrefix = prefixSuffix
       ? `UI WebSocket Server ${prefixSuffix}`
       : 'UI WebSocket Server';
     const logMsg =
-      modName && methodName ? ` ${logMsgPrefix} | ${modName}.${methodName}:` : ` ${logMsgPrefix} |`;
+      Utils.isNotEmptyString(modName) && Utils.isNotEmptyString(methodName)
+        ? ` ${logMsgPrefix} | ${modName}.${methodName}:`
+        : ` ${logMsgPrefix} |`;
     return Utils.logPrefix(logMsg);
-  }
+  };
 
   private broadcastToClients(message: string): void {
     for (const client of this.webSocketServer.clients) {