Hook the OCPP 2.0 stack into the main code
[e-mobility-charging-stations-simulator.git] / src / charging-station / ui-server / UIServerFactory.ts
index bbbb66b9c2fd67b01e2deb604345ae95314a7b36..2a125af07971fe9b724a06f45cf8c04b5e03c040 100644 (file)
@@ -1,11 +1,11 @@
 import chalk from 'chalk';
 
-import type { ServerOptions } from '../../types/ConfigurationData';
+import type { UIServerConfiguration } from '../../types/ConfigurationData';
 import { ApplicationProtocol } from '../../types/UIProtocol';
 import Configuration from '../../utils/Configuration';
 import type { AbstractUIServer } from './AbstractUIServer';
-import { UIServiceUtils } from './ui-services/UIServiceUtils';
 import UIHttpServer from './UIHttpServer';
+import { UIServerUtils } from './UIServerUtils';
 import UIWebSocketServer from './UIWebSocketServer';
 
 export default class UIServerFactory {
@@ -14,21 +14,20 @@ export default class UIServerFactory {
   }
 
   public static getUIServerImplementation(
-    applicationProtocol: ApplicationProtocol,
-    options?: ServerOptions
+    uiServerConfiguration?: UIServerConfiguration
   ): AbstractUIServer | null {
-    if (!UIServiceUtils.isLoopback(options?.host)) {
+    if (UIServerUtils.isLoopback(uiServerConfiguration.options?.host) === false) {
       console.warn(
-        chalk.magenta(
+        chalk.yellow(
           'Loopback address not detected in UI server configuration. This is not recommended.'
         )
       );
     }
-    switch (applicationProtocol) {
+    switch (uiServerConfiguration?.type ?? Configuration.getUIServer().type) {
       case ApplicationProtocol.WS:
-        return new UIWebSocketServer(options ?? Configuration.getUIServer().options);
+        return new UIWebSocketServer(uiServerConfiguration ?? Configuration.getUIServer());
       case ApplicationProtocol.HTTP:
-        return new UIHttpServer(options ?? Configuration.getUIServer().options);
+        return new UIHttpServer(uiServerConfiguration ?? Configuration.getUIServer());
       default:
         return null;
     }