X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FUIServiceWorkerBroadcastChannel.ts;h=5139b678c2d47ea168c495a3afbf264f7a62d517;hb=07561812b72072b6d9f20997be86a42ee88e15a2;hp=e7615e611e30f3b7f895bb06caf14dff79fe0645;hpb=6d9876e7b9b024879f1463aa7407c6874c5ca06b;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/UIServiceWorkerBroadcastChannel.ts b/src/charging-station/UIServiceWorkerBroadcastChannel.ts index e7615e61..5139b678 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)) { + 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), @@ -58,7 +61,7 @@ export default class UIServiceWorkerBroadcastChannel extends WorkerBroadcastChan private buildResponsePayload(uuid: string): ResponsePayload { const responsesStatus = this.responses .get(uuid) - ?.responses.every((response) => response.status === ResponseStatus.SUCCESS) + ?.responses.every(({ status }) => status === ResponseStatus.SUCCESS) ? ResponseStatus.SUCCESS : ResponseStatus.FAILURE; return { @@ -81,13 +84,23 @@ export default class UIServiceWorkerBroadcastChannel extends WorkerBroadcastChan }) .filter((hashId) => hashId !== undefined), }), + ...(responsesStatus === ResponseStatus.FAILURE && { + responsesFailed: this.responses + .get(uuid) + ?.responses.map((response) => { + if (response.status === ResponseStatus.FAILURE) { + return response; + } + }) + .filter((response) => response !== undefined), + }), }; } private messageErrorHandler(messageEvent: MessageEvent): void { logger.error( `${this.uiService.logPrefix(moduleName, 'messageErrorHandler')} Error at handling message:`, - { messageEvent } + messageEvent ); } }