From: Jérôme Benoit Date: Tue, 6 Sep 2022 21:02:23 +0000 (+0200) Subject: UI server: factor services registration X-Git-Tag: v1.1.72~16 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=143498c8a5507fbf23c13a032cf9c5ebf285675d;p=e-mobility-charging-stations-simulator.git UI server: factor services registration Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ui-server/AbstractUIServer.ts b/src/charging-station/ui-server/AbstractUIServer.ts index a55d0070..48151dc4 100644 --- a/src/charging-station/ui-server/AbstractUIServer.ts +++ b/src/charging-station/ui-server/AbstractUIServer.ts @@ -12,6 +12,7 @@ import { ResponsePayload, } from '../../types/UIProtocol'; import type AbstractUIService from './ui-services/AbstractUIService'; +import UIServiceFactory from './ui-services/UIServiceFactory'; export abstract class AbstractUIServer { public readonly chargingStations: Map; @@ -35,6 +36,12 @@ export abstract class AbstractUIServer { return [id, responsePayload]; } + protected registerProtocolVersionUIService(version: ProtocolVersion): void { + if (this.uiServices.has(version) === false) { + this.uiServices.set(version, UIServiceFactory.getUIServiceImplementation(version, this)); + } + } + protected isBasicAuthEnabled(): boolean { return ( this.uiServerConfiguration.authentication?.enabled === true && diff --git a/src/charging-station/ui-server/UIHttpServer.ts b/src/charging-station/ui-server/UIHttpServer.ts index ce52ed4b..4db72bf7 100644 --- a/src/charging-station/ui-server/UIHttpServer.ts +++ b/src/charging-station/ui-server/UIHttpServer.ts @@ -16,7 +16,6 @@ import { 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 = 'UIHttpServer'; @@ -97,9 +96,7 @@ export default class UIHttpServer extends AbstractUIServer { error ); }); - if (this.uiServices.has(version) === false) { - this.uiServices.set(version, UIServiceFactory.getUIServiceImplementation(version, this)); - } + this.registerProtocolVersionUIService(version); if (req.method === 'POST') { const bodyBuffer = []; req diff --git a/src/charging-station/ui-server/UIWebSocketServer.ts b/src/charging-station/ui-server/UIWebSocketServer.ts index ea54bec0..f789d396 100644 --- a/src/charging-station/ui-server/UIWebSocketServer.ts +++ b/src/charging-station/ui-server/UIWebSocketServer.ts @@ -11,7 +11,6 @@ import { WebSocketCloseEventStatusCode } from '../../types/WebSocket'; 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'; @@ -40,9 +39,7 @@ export default class UIWebSocketServer extends AbstractUIServer { ); ws.close(WebSocketCloseEventStatusCode.CLOSE_PROTOCOL_ERROR); } - if (this.uiServices.has(version) === false) { - this.uiServices.set(version, UIServiceFactory.getUIServiceImplementation(version, this)); - } + this.registerProtocolVersionUIService(version); ws.on('message', (rawData) => { const request = this.validateRawDataRequest(rawData); if (request === false) {