X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FUIServiceWorkerBroadcastChannel.ts;h=d9e746393d32b03f6062787a8924d819d864bf1d;hb=2896e06dc8d72adf7150b23c941079f622f6f37c;hp=e323056cd2c6456b8eb0f83759a30a2cbf473a4b;hpb=c56450e3b2ecbe265caadd9f87a9ef0bf231a70f;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/UIServiceWorkerBroadcastChannel.ts b/src/charging-station/UIServiceWorkerBroadcastChannel.ts index e323056c..d9e74639 100644 --- a/src/charging-station/UIServiceWorkerBroadcastChannel.ts +++ b/src/charging-station/UIServiceWorkerBroadcastChannel.ts @@ -1,12 +1,12 @@ -import { type ResponsePayload, ResponseStatus } from '../types/UIProtocol'; -import type { - BroadcastChannelResponse, - BroadcastChannelResponsePayload, - MessageEvent, -} from '../types/WorkerBroadcastChannel'; -import logger from '../utils/Logger'; -import type AbstractUIService from './ui-server/ui-services/AbstractUIService'; -import WorkerBroadcastChannel from './WorkerBroadcastChannel'; +import { type AbstractUIService, WorkerBroadcastChannel } from './internal'; +import { + type BroadcastChannelResponse, + type BroadcastChannelResponsePayload, + type MessageEvent, + type ResponsePayload, + ResponseStatus, +} from '../types'; +import { logger } from '../utils/Logger'; const moduleName = 'UIServiceWorkerBroadcastChannel'; @@ -16,7 +16,7 @@ type Responses = { responses: BroadcastChannelResponsePayload[]; }; -export default class UIServiceWorkerBroadcastChannel extends WorkerBroadcastChannel { +export class UIServiceWorkerBroadcastChannel extends WorkerBroadcastChannel { private readonly uiService: AbstractUIService; private readonly responses: Map; @@ -47,7 +47,7 @@ export default class UIServiceWorkerBroadcastChannel extends WorkerBroadcastChan this.responses.get(uuid)?.responsesReceived <= this.responses.get(uuid)?.responsesExpected ) { this.responses.get(uuid).responsesReceived++; - this.responses.get(uuid).responses.push(responsePayload); + this.responses.get(uuid)?.responses.push(responsePayload); } if ( this.responses.get(uuid)?.responsesReceived === this.responses.get(uuid)?.responsesExpected @@ -69,31 +69,31 @@ export default class UIServiceWorkerBroadcastChannel extends WorkerBroadcastChan status: responsesStatus, hashIdsSucceeded: this.responses .get(uuid) - ?.responses.map(({ status, hashId }) => { + ?.responses.filter(({ hashId }) => hashId !== undefined) + .map(({ status, hashId }) => { if (status === ResponseStatus.SUCCESS) { return hashId; } - }) - .filter((hashId) => hashId !== undefined), + }), ...(responsesStatus === ResponseStatus.FAILURE && { hashIdsFailed: this.responses .get(uuid) - ?.responses.map(({ status, hashId }) => { + ?.responses.filter(({ hashId }) => hashId !== undefined) + .map(({ status, hashId }) => { if (status === ResponseStatus.FAILURE) { return hashId; } - }) - .filter((hashId) => hashId !== undefined), + }), }), ...(responsesStatus === ResponseStatus.FAILURE && { responsesFailed: this.responses .get(uuid) - ?.responses.map((response) => { + ?.responses.filter((response) => response !== undefined) + .map((response) => { if (response.status === ResponseStatus.FAILURE) { return response; } - }) - .filter((response) => response !== undefined), + }), }), }; }