-import type { IncomingMessage } from 'http';
-
-import WebSocket, { RawData } from 'ws';
-
-import BaseError from '../../exception/BaseError';
-import type { ServerOptions } from '../../types/ConfigurationData';
-import type { ProtocolRequest, ProtocolResponse } from '../../types/UIProtocol';
-import { WebSocketCloseEventStatusCode } from '../../types/WebSocket';
-import Configuration from '../../utils/Configuration';
-import logger from '../../utils/Logger';
-import Utils from '../../utils/Utils';
-import { AbstractUIServer } from './AbstractUIServer';
-import UIServiceFactory from './ui-services/UIServiceFactory';
-import { UIServiceUtils } from './ui-services/UIServiceUtils';
-
-const moduleName = 'UIWebSocketServer';
-
-export default class UIWebSocketServer extends AbstractUIServer {
- public constructor(options?: ServerOptions) {
- super();
- this.server = new WebSocket.Server(options ?? Configuration.getUIServer().options);
+import type { IncomingMessage } from 'node:http'
+import type { Duplex } from 'node:stream'
+
+import { StatusCodes } from 'http-status-codes'
+import { type RawData, WebSocket, WebSocketServer } from 'ws'
+
+import { AbstractUIServer } from './AbstractUIServer.js'
+import { UIServerUtils } from './UIServerUtils.js'
+import {
+ type ProtocolRequest,
+ type ProtocolResponse,
+ type UIServerConfiguration,
+ WebSocketCloseEventStatusCode
+} from '../../types/index.js'
+import {
+ Constants,
+ JSONStringifyWithMapSupport,
+ getWebSocketCloseEventStatusString,
+ isNotEmptyString,
+ logPrefix,
+ logger,
+ validateUUID
+} from '../../utils/index.js'
+
+const moduleName = 'UIWebSocketServer'
+
+export class UIWebSocketServer extends AbstractUIServer {
+ private readonly webSocketServer: WebSocketServer
+
+ public constructor (protected readonly uiServerConfiguration: UIServerConfiguration) {
+ super(uiServerConfiguration)
+ this.webSocketServer = new WebSocketServer({
+ handleProtocols: UIServerUtils.handleProtocols,
+ noServer: true
+ })