X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=ui%2Fweb%2Fsrc%2Fcomposables%2FUIClient.ts;h=bbb4a4499b233a6aead4703eaf1b3de93004e32e;hb=4ed03b6ec8110ad11b67ead121145c80995f69df;hp=3e7856e483115bb6911a76a345efff0430638566;hpb=3c8798b163014a2f28c3e559bf1685bdc61fd3e0;p=e-mobility-charging-stations-simulator.git diff --git a/ui/web/src/composables/UIClient.ts b/ui/web/src/composables/UIClient.ts index 3e7856e4..bbb4a449 100644 --- a/ui/web/src/composables/UIClient.ts +++ b/ui/web/src/composables/UIClient.ts @@ -1,4 +1,4 @@ -import Utils from './Utils'; +import { promiseWithTimeout } from './Utils'; import { ProcedureName, type ProtocolResponse, @@ -14,7 +14,7 @@ type ResponseHandler = { reject: (reason?: unknown) => void; }; -export default class UIClient { +export class UIClient { private static instance: UIClient | null = null; private ws!: WebSocket; @@ -71,7 +71,7 @@ export default class UIClient { public async startTransaction( hashId: string, connectorId: number, - idTag: string | undefined + idTag: string | undefined, ): Promise { return this.sendRequest(ProcedureName.START_TRANSACTION, { hashIds: [hashId], @@ -82,7 +82,7 @@ export default class UIClient { public async stopTransaction( hashId: string, - transactionId: number | undefined + transactionId: number | undefined, ): Promise { return this.sendRequest(ProcedureName.STOP_TRANSACTION, { hashIds: [hashId], @@ -92,7 +92,7 @@ export default class UIClient { public async startAutomaticTransactionGenerator( hashId: string, - connectorId: number + connectorId: number, ): Promise { return this.sendRequest(ProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR, { hashIds: [hashId], @@ -102,7 +102,7 @@ export default class UIClient { public async stopAutomaticTransactionGenerator( hashId: string, - connectorId: number + connectorId: number, ): Promise { return this.sendRequest(ProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR, { hashIds: [hashId], @@ -113,7 +113,7 @@ export default class UIClient { private openWS(): void { this.ws = new WebSocket( `ws://${config.uiServer.host}:${config.uiServer.port}`, - config.uiServer.protocol + config.uiServer.protocol, ); this.ws.onmessage = this.responseHandler.bind(this); this.ws.onerror = (errorEvent) => { @@ -128,7 +128,7 @@ export default class UIClient { id: string, procedureName: ProcedureName, resolve: (value: ResponsePayload | PromiseLike) => void, - reject: (reason?: unknown) => void + reject: (reason?: unknown) => void, ): void { this.responseHandlers.set(id, { procedureName, resolve, reject }); } @@ -143,11 +143,11 @@ export default class UIClient { private async sendRequest( command: ProcedureName, - data: RequestPayload + data: RequestPayload, ): Promise { let uuid: string; - return Utils.promiseWithTimeout( - new Promise((resolve, reject) => { + return promiseWithTimeout( + new Promise((resolve, reject) => { uuid = crypto.randomUUID(); const msg = JSON.stringify([uuid, command, data]); @@ -166,7 +166,7 @@ export default class UIClient { Error(`Send request '${command}' message timeout`), () => { this.responseHandlers.delete(uuid); - } + }, ); } @@ -174,7 +174,7 @@ export default class UIClient { const response = JSON.parse(messageEvent.data) as ProtocolResponse; if (Array.isArray(response) === false) { - throw new Error(`Response not an array: ${JSON.stringify(response, null, 2)}`); + throw new Error(`Response not an array: ${JSON.stringify(response, undefined, 2)}`); } const [uuid, responsePayload] = response; @@ -192,7 +192,7 @@ export default class UIClient { } this.deleteResponseHandler(uuid); } else { - throw new Error(`Not a response to a request: ${JSON.stringify(response, null, 2)}`); + throw new Error(`Not a response to a request: ${JSON.stringify(response, undefined, 2)}`); } } }