Add WebSocket connection close and open support to the UI protocol
[e-mobility-charging-stations-simulator.git] / src / charging-station / ui-server / UIServerFactory.ts
CommitLineData
8114d10e
JB
1import chalk from 'chalk';
2
3import { ServerOptions } from '../../types/ConfigurationData';
fe94fce0
JB
4import { ApplicationProtocol } from '../../types/UIProtocol';
5import Configuration from '../../utils/Configuration';
8114d10e 6import { AbstractUIServer } from './AbstractUIServer';
d5bd1c00 7import { UIServiceUtils } from './ui-services/UIServiceUtils';
fe94fce0
JB
8import UIWebSocketServer from './UIWebSocketServer';
9
10export default class UIServerFactory {
11 private constructor() {
12 // This is intentional
13 }
14
15 public static getUIServerImplementation(
16 applicationProtocol: ApplicationProtocol,
b153c0fd 17 options?: ServerOptions
fe94fce0 18 ): AbstractUIServer | null {
d5bd1c00
JB
19 if (!UIServiceUtils.isLoopback(options?.host)) {
20 console.warn(
21 chalk.magenta(
22 'Loopback address not detected in UI server configuration. This is not recommended.'
23 )
24 );
25 }
fe94fce0
JB
26 switch (applicationProtocol) {
27 case ApplicationProtocol.WS:
b153c0fd 28 return new UIWebSocketServer(options ?? Configuration.getUIServer().options);
fe94fce0
JB
29 default:
30 return null;
31 }
32 }
33}