X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=ui%2Fweb%2Fsrc%2Fcomposables%2FUIClient.ts;h=9a6920418d3adb255f64a8e97e50be35e9586640;hb=c25a4046983ef80409cbc4546f944231e8655604;hp=81a322d31c73d1d2a0222f2086fa6d498e796a22;hpb=f292861c82c819c87719364485f5bba141eb51fa;p=e-mobility-charging-stations-simulator.git diff --git a/ui/web/src/composables/UIClient.ts b/ui/web/src/composables/UIClient.ts index 81a322d3..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( @@ -212,8 +207,10 @@ export class UIClient { reject(responsePayload) break default: - console.error( - `Response status for procedure '${procedureName}' not supported: '${responsePayload.status}'` + reject( + new Error( + `Response status for procedure '${procedureName}' not supported: '${responsePayload.status}'` + ) ) } this.responseHandlers.delete(uuid)