UI server: permit to address all charging stations
[e-mobility-charging-stations-simulator.git] / src / charging-station / UIServiceWorkerBroadcastChannel.ts
index d50d514a469496159b5aad15f752bde3c3a0d031..c64a7ccc2212d021189b373278ad8d5a804961bc 100644 (file)
@@ -1,4 +1,5 @@
-import { BroadcastChannelResponse, MessageEvent } from '../types/WorkerBroadcastChannel';
+import type { ResponsePayload } from '../types/UIProtocol';
+import type { BroadcastChannelResponse, MessageEvent } from '../types/WorkerBroadcastChannel';
 import logger from '../utils/Logger';
 import type AbstractUIService from './ui-server/ui-services/AbstractUIService';
 import WorkerBroadcastChannel from './WorkerBroadcastChannel';
@@ -19,9 +20,12 @@ export default class UIServiceWorkerBroadcastChannel extends WorkerBroadcastChan
     if (this.isRequest(messageEvent.data)) {
       return;
     }
+    this.validateMessageEvent(messageEvent);
     const [uuid, responsePayload] = messageEvent.data as BroadcastChannelResponse;
+    // TODO: handle multiple responses for the same uuid
+    delete responsePayload.hashId;
 
-    this.uiService.sendResponse(uuid, responsePayload);
+    this.uiService.sendResponse(uuid, responsePayload as ResponsePayload);
   }
 
   private messageErrorHandler(messageEvent: MessageEvent): void {