+ procedureName: ProcedureName,
+ requestPayload: RequestPayload
+ ): void {
+ this.uiServer.sendRequest(
+ this.uiServer.buildProtocolRequest(messageId, procedureName, requestPayload)
+ );
+ }
+
+ public sendResponse(messageId: string, responsePayload: ResponsePayload): void {
+ this.uiServer.sendResponse(this.uiServer.buildProtocolResponse(messageId, responsePayload));
+ }
+
+ public logPrefix(modName: string, methodName: string): string {
+ return this.uiServer.logPrefix(modName, methodName, this.version);
+ }
+
+ public deleteBroadcastChannelRequest(uuid: string): void {
+ this.broadcastChannelRequests.delete(uuid);
+ }
+
+ public getBroadcastChannelExpectedResponses(uuid: string): number {
+ return this.broadcastChannelRequests.get(uuid) ?? 0;
+ }
+
+ protected handleProtocolRequest(
+ uuid: string,
+ procedureName: ProcedureName,
+ payload: RequestPayload
+ ): void {
+ this.sendBroadcastChannelRequest(
+ uuid,
+ AbstractUIService.ProcedureNameToBroadCastChannelProcedureNameMap[
+ procedureName
+ ] as BroadcastChannelProcedureName,
+ payload
+ );
+ }
+
+ private sendBroadcastChannelRequest(
+ uuid: string,
+ procedureName: BroadcastChannelProcedureName,
+ payload: BroadcastChannelRequestPayload
+ ): void {
+ if (!Utils.isEmptyArray(payload.hashIds)) {
+ payload.hashIds = payload.hashIds
+ .map((hashId) => {
+ if (this.uiServer.chargingStations.has(hashId) === true) {
+ return hashId;
+ }
+ logger.warn(
+ `${this.logPrefix(
+ moduleName,
+ 'sendBroadcastChannelRequest'
+ )} Charging station with hashId '${hashId}' not found`
+ );
+ })
+ .filter((hashId) => hashId !== undefined);
+ }
+ const expectedNumberOfResponses = !Utils.isEmptyArray(payload.hashIds)
+ ? payload.hashIds.length
+ : this.uiServer.chargingStations.size;
+ this.uiServiceWorkerBroadcastChannel.sendRequest([uuid, procedureName, payload]);
+ this.broadcastChannelRequests.set(uuid, expectedNumberOfResponses);
+ }
+
+ private handleListChargingStations(): ResponsePayload {
+ return {
+ status: ResponseStatus.SUCCESS,
+ chargingStations: [...this.uiServer.chargingStations.values()],
+ } as ResponsePayload;
+ }
+
+ private async handleStartSimulator(): Promise<ResponsePayload> {
+ await Bootstrap.getInstance().start();
+ return { status: ResponseStatus.SUCCESS };