X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FUIServiceWorkerBroadcastChannel.ts;h=e323056cd2c6456b8eb0f83759a30a2cbf473a4b;hb=ce784b19f3b0c9de3525613468772f8a125a2632;hp=7e4cc87720f81e10dacb625c00ed1474a821260d;hpb=f53c88d034b52b702f258174713e2952fa6df397;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/UIServiceWorkerBroadcastChannel.ts b/src/charging-station/UIServiceWorkerBroadcastChannel.ts index 7e4cc877..e323056c 100644 --- a/src/charging-station/UIServiceWorkerBroadcastChannel.ts +++ b/src/charging-station/UIServiceWorkerBroadcastChannel.ts @@ -1,4 +1,4 @@ -import { ResponsePayload, ResponseStatus } from '../types/UIProtocol'; +import { type ResponsePayload, ResponseStatus } from '../types/UIProtocol'; import type { BroadcastChannelResponse, BroadcastChannelResponsePayload, @@ -29,11 +29,14 @@ export default class UIServiceWorkerBroadcastChannel extends WorkerBroadcastChan } private responseHandler(messageEvent: MessageEvent): void { - if (this.isRequest(messageEvent.data) === true) { + const validatedMessageEvent = this.validateMessageEvent(messageEvent); + if (validatedMessageEvent === false) { return; } - const [uuid, responsePayload] = this.validateMessageEvent(messageEvent) - .data as BroadcastChannelResponse; + if (this.isRequest(validatedMessageEvent.data) === true) { + return; + } + const [uuid, responsePayload] = validatedMessageEvent.data as BroadcastChannelResponse; if (this.responses.has(uuid) === false) { this.responses.set(uuid, { responsesExpected: this.uiService.getBroadcastChannelExpectedResponses(uuid), @@ -56,11 +59,12 @@ export default class UIServiceWorkerBroadcastChannel extends WorkerBroadcastChan } private buildResponsePayload(uuid: string): ResponsePayload { - const responsesStatus = this.responses - .get(uuid) - ?.responses.every((response) => response.status === ResponseStatus.SUCCESS) - ? ResponseStatus.SUCCESS - : ResponseStatus.FAILURE; + const responsesStatus = + this.responses + .get(uuid) + ?.responses.every(({ status }) => status === ResponseStatus.SUCCESS) === true + ? ResponseStatus.SUCCESS + : ResponseStatus.FAILURE; return { status: responsesStatus, hashIdsSucceeded: this.responses @@ -97,7 +101,7 @@ export default class UIServiceWorkerBroadcastChannel extends WorkerBroadcastChan private messageErrorHandler(messageEvent: MessageEvent): void { logger.error( `${this.uiService.logPrefix(moduleName, 'messageErrorHandler')} Error at handling message:`, - { messageEvent } + messageEvent ); } }