| 1 | import chalk from 'chalk'; |
| 2 | |
| 3 | import { ServerOptions } from '../../types/ConfigurationData'; |
| 4 | import { ApplicationProtocol } from '../../types/UIProtocol'; |
| 5 | import Configuration from '../../utils/Configuration'; |
| 6 | import { AbstractUIServer } from './AbstractUIServer'; |
| 7 | import { UIServiceUtils } from './ui-services/UIServiceUtils'; |
| 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, |
| 17 | options?: ServerOptions |
| 18 | ): AbstractUIServer | null { |
| 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 | } |
| 26 | switch (applicationProtocol) { |
| 27 | case ApplicationProtocol.WS: |
| 28 | return new UIWebSocketServer(options ?? Configuration.getUIServer().options); |
| 29 | default: |
| 30 | return null; |
| 31 | } |
| 32 | } |
| 33 | } |