X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Fui-server%2FUIWebSocketServer.ts;h=c67da00e1f6c8643e0f35032ff759d6bfe0cb0f0;hb=ec69050249d8e32aa6ec786ff271179200bfb88e;hp=fcfc309708811f88eeef7857c6dfec13639f0ce4;hpb=b153c0fd46bdc1dc8006e4dac4d4dfa739ff7707;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ui-server/UIWebSocketServer.ts b/src/charging-station/ui-server/UIWebSocketServer.ts index fcfc3097..c67da00e 100644 --- a/src/charging-station/ui-server/UIWebSocketServer.ts +++ b/src/charging-station/ui-server/UIWebSocketServer.ts @@ -1,5 +1,4 @@ import { Protocol, ProtocolVersion } from '../../types/UIProtocol'; -import WebSocket, { OPEN, Server } from 'ws'; import { AbstractUIServer } from './AbstractUIServer'; import Configuration from '../../utils/Configuration'; @@ -7,16 +6,17 @@ 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 AbstractUIServer { public constructor(options?: ServerOptions) { super(); - this.uiServer = new Server(options ?? Configuration.getUIServer().options); + this.server = new WebSocket.Server(options ?? Configuration.getUIServer().options); } public start(): void { - this.uiServer.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 @@ -40,7 +40,7 @@ export default class UIWebSocketServer extends AbstractUIServer { } public stop(): void { - this.uiServer.close(); + this.server.close(); } public sendResponse(message: string): void { @@ -52,8 +52,8 @@ export default class UIWebSocketServer extends AbstractUIServer { } private broadcastToClients(message: string): void { - for (const client of (this.uiServer as Server).clients) { - if (client?.readyState === OPEN) { + for (const client of (this.server as WebSocket.Server).clients) { + if (client?.readyState === WebSocket.OPEN) { client.send(message); } }