}
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>(
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)