Commit | Line | Data |
---|---|---|
8114d10e JB |
1 | import chalk from 'chalk'; |
2 | ||
3 | import { ServerOptions } from '../../types/ConfigurationData'; | |
fe94fce0 JB |
4 | import { ApplicationProtocol } from '../../types/UIProtocol'; |
5 | import Configuration from '../../utils/Configuration'; | |
8114d10e | 6 | import { AbstractUIServer } from './AbstractUIServer'; |
d5bd1c00 | 7 | import { UIServiceUtils } from './ui-services/UIServiceUtils'; |
fe94fce0 JB |
8 | import UIWebSocketServer from './UIWebSocketServer'; |
9 | ||
10 | export 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 | } |