import { Protocol, ProtocolVersion } from '../../types/UIProtocol';
-import WebSocket, { OPEN, Server, ServerOptions } from 'ws';
-import AbstractUIService from './ui-services/AbstractUIService';
+import { AbstractUIServer } from './AbstractUIServer';
import Configuration from '../../utils/Configuration';
import { IncomingMessage } from 'http';
+import { ServerOptions } from '../../types/ConfigurationData';
import UIServiceFactory from './ui-services/UIServiceFactory';
import Utils from '../../utils/Utils';
+import WebSocket from 'ws';
import logger from '../../utils/Logger';
-export default class UIWebSocketServer extends Server {
- public readonly chargingStations: Set<string>;
- public readonly uiServices: Map<ProtocolVersion, AbstractUIService>;
-
- public constructor(options?: ServerOptions, callback?: () => void) {
- // Create the WebSocket Server
- super(options ?? Configuration.getUIServer().options, callback);
- this.chargingStations = new Set<string>();
- this.uiServices = new Map<ProtocolVersion, AbstractUIService>();
+export default class UIWebSocketServer extends AbstractUIServer {
+ public constructor(options?: ServerOptions) {
+ super();
+ this.server = new WebSocket.Server(options ?? Configuration.getUIServer().options);
}
public start(): void {
- this.on('connection', (socket: WebSocket, request: IncomingMessage): void => {
+ this.server.on('connection', (socket: WebSocket, request: IncomingMessage): void => {
const protocolIndex = socket.protocol.indexOf(Protocol.UI);
const version = socket.protocol.substring(
protocolIndex + Protocol.UI.length
}
public stop(): void {
- this.close();
+ this.server.close();
}
public sendResponse(message: string): void {
}
private broadcastToClients(message: string): void {
- for (const client of this.clients) {
- if (client?.readyState === OPEN) {
+ for (const client of (this.server as WebSocket.Server).clients) {
+ if (client?.readyState === WebSocket.OPEN) {
client.send(message);
}
}