}
export class UIClient {
- private static readonly instances: Map<number, UIClient> = new Map<number, UIClient>()
+ private static instance: UIClient | null = null
private ws!: WebSocket
private responseHandlers: Map<string, ResponseHandler>
this.responseHandlers = new Map<string, ResponseHandler>()
}
- 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<K extends keyof WebSocketEventMap>(
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()
import type { AuthenticationType, Protocol, ProtocolVersion } from './UIProtocol'
export type ConfigurationData = {
- uiServer: UIServerConfigurationSection | UIServerConfigurationSection[]
+ uiServer: UIServerConfigurationSection
}
export type UIServerConfigurationSection = {