X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Fbroadcast-channel%2FUIServiceWorkerBroadcastChannel.ts;h=b385be7fc47aae52e67eaac792dc4f59256c81a1;hb=08b58f0020986c0ad1b55e562aaf325a47b9d58c;hp=25d62962fbed2dcad29ec0fe6e0064fb1b0e0cdd;hpb=7671fa0be211e944f027ebd83f3a0ad64c2ef2d6;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/broadcast-channel/UIServiceWorkerBroadcastChannel.ts b/src/charging-station/broadcast-channel/UIServiceWorkerBroadcastChannel.ts index 25d62962..b385be7f 100644 --- a/src/charging-station/broadcast-channel/UIServiceWorkerBroadcastChannel.ts +++ b/src/charging-station/broadcast-channel/UIServiceWorkerBroadcastChannel.ts @@ -6,16 +6,16 @@ import { type ResponsePayload, ResponseStatus, } from '../../types'; -import { Utils, logger } from '../../utils'; +import { isNullOrUndefined, logger } from '../../utils'; import type { AbstractUIService } from '../ui-server/ui-services/AbstractUIService'; const moduleName = 'UIServiceWorkerBroadcastChannel'; -type Responses = { +interface Responses { responsesExpected: number; responsesReceived: number; responses: BroadcastChannelResponsePayload[]; -}; +} export class UIServiceWorkerBroadcastChannel extends WorkerBroadcastChannel { private readonly uiService: AbstractUIService; @@ -24,8 +24,8 @@ export class UIServiceWorkerBroadcastChannel extends WorkerBroadcastChannel { constructor(uiService: AbstractUIService) { super(); this.uiService = uiService; - this.onmessage = this.responseHandler.bind(this) as (message: MessageEvent) => void; - this.onmessageerror = this.messageErrorHandler.bind(this) as (message: MessageEvent) => void; + this.onmessage = this.responseHandler.bind(this) as (message: unknown) => void; + this.onmessageerror = this.messageErrorHandler.bind(this) as (message: unknown) => void; this.responses = new Map(); } @@ -45,9 +45,9 @@ export class UIServiceWorkerBroadcastChannel extends WorkerBroadcastChannel { responses: [responsePayload], }); } else if ( - this.responses.get(uuid)?.responsesReceived <= this.responses.get(uuid)?.responsesExpected + this.responses.get(uuid)!.responsesReceived <= this.responses.get(uuid)!.responsesExpected ) { - this.responses.get(uuid).responsesReceived++; + ++this.responses.get(uuid)!.responsesReceived; this.responses.get(uuid)?.responses.push(responsePayload); } if ( @@ -70,31 +70,31 @@ export class UIServiceWorkerBroadcastChannel extends WorkerBroadcastChannel { status: responsesStatus, hashIdsSucceeded: this.responses .get(uuid) - ?.responses.filter(({ hashId }) => !Utils.isNullOrUndefined(hashId)) + ?.responses.filter(({ hashId }) => !isNullOrUndefined(hashId)) .map(({ status, hashId }) => { if (status === ResponseStatus.SUCCESS) { return hashId; } - }), + }) as string[], ...(responsesStatus === ResponseStatus.FAILURE && { hashIdsFailed: this.responses .get(uuid) - ?.responses.filter(({ hashId }) => !Utils.isNullOrUndefined(hashId)) + ?.responses.filter(({ hashId }) => !isNullOrUndefined(hashId)) .map(({ status, hashId }) => { if (status === ResponseStatus.FAILURE) { return hashId; } - }), + }) as string[], }), ...(responsesStatus === ResponseStatus.FAILURE && { responsesFailed: this.responses .get(uuid) - ?.responses.filter((response) => !Utils.isNullOrUndefined(response)) + ?.responses.filter((response) => !isNullOrUndefined(response)) .map((response) => { if (response.status === ResponseStatus.FAILURE) { return response; } - }), + }) as BroadcastChannelResponsePayload[], }), }; } @@ -102,7 +102,7 @@ export class UIServiceWorkerBroadcastChannel extends WorkerBroadcastChannel { private messageErrorHandler(messageEvent: MessageEvent): void { logger.error( `${this.uiService.logPrefix(moduleName, 'messageErrorHandler')} Error at handling message:`, - messageEvent + messageEvent, ); } }