From: Jérôme Benoit Date: Mon, 19 Feb 2024 15:20:34 +0000 (+0100) Subject: refactor(ui): revert wrongly introduced code to handle multiples UI X-Git-Tag: v1.2.38~78 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=c25a4046983ef80409cbc4546f944231e8655604;p=e-mobility-charging-stations-simulator.git refactor(ui): revert wrongly introduced code to handle multiples UI Server Signed-off-by: Jérôme Benoit --- diff --git a/ui/web/src/composables/UIClient.ts b/ui/web/src/composables/UIClient.ts index e2266855..9a692041 100644 --- a/ui/web/src/composables/UIClient.ts +++ b/ui/web/src/composables/UIClient.ts @@ -16,7 +16,7 @@ type ResponseHandler = { } export class UIClient { - private static readonly instances: Map = new Map() + private static instance: UIClient | null = null private ws!: WebSocket private responseHandlers: Map @@ -26,16 +26,11 @@ export class UIClient { this.responseHandlers = new Map() } - public static getInstance( - serverId: number, - uiServerConfiguration?: UIServerConfigurationSection - ): UIClient { - if (!UIClient.instances.has(serverId) && uiServerConfiguration != null) { - UIClient.instances.set(serverId, new UIClient(uiServerConfiguration)) - } else if (!UIClient.instances.has(serverId)) { - throw new Error(`UI client instance not found for server id: ${serverId}`) + public static getInstance(uiServerConfiguration: UIServerConfigurationSection): UIClient { + if (UIClient.instance === null) { + UIClient.instance = new UIClient(uiServerConfiguration) } - return UIClient.instances.get(serverId)! + return UIClient.instance } public registerWSEventListener( diff --git a/ui/web/src/main.ts b/ui/web/src/main.ts index ddef6f36..97f0167a 100644 --- a/ui/web/src/main.ts +++ b/ui/web/src/main.ts @@ -14,10 +14,7 @@ const initializeApp = (config: ConfigurationData) => { console.info('Error info:', info) // TODO: add code for UI notifications or other error handling logic } - if (Array.isArray(config.uiServer)) { - throw new Error('Multiple UI server configurations is not yet supported') - } - app.config.globalProperties.$uiClient = UIClient.getInstance(0, config.uiServer) + app.config.globalProperties.$uiClient = UIClient.getInstance(config.uiServer) app.config.globalProperties.$uiClient.registerWSEventListener('open', () => { app.config.globalProperties.$uiClient .listChargingStations() diff --git a/ui/web/src/types/ConfigurationType.ts b/ui/web/src/types/ConfigurationType.ts index 51bd2138..5d0f7679 100644 --- a/ui/web/src/types/ConfigurationType.ts +++ b/ui/web/src/types/ConfigurationType.ts @@ -1,7 +1,7 @@ import type { AuthenticationType, Protocol, ProtocolVersion } from './UIProtocol' export type ConfigurationData = { - uiServer: UIServerConfigurationSection | UIServerConfigurationSection[] + uiServer: UIServerConfigurationSection } export type UIServerConfigurationSection = {