UI Server: dedupe some code in helpers
[e-mobility-charging-stations-simulator.git] / src / charging-station / ChargingStationWorkerBroadcastChannel.ts
index 9e88b4189372eaa030de37cfe159e4cdb3a89044..42448275432337772fe80a691a5364840680f068 100644 (file)
@@ -38,15 +38,27 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca
     if (this.isResponse(messageEvent.data)) {
       return;
     }
-    if (Array.isArray(messageEvent.data) === false) {
-      throw new BaseError('Worker broadcast channel protocol request is not an array');
-    }
+    this.validateMessageEvent(messageEvent);
 
     const [uuid, command, requestPayload] = messageEvent.data as BroadcastChannelRequest;
 
-    if (requestPayload?.hashId !== this.chargingStation.hashId) {
+    if (
+      requestPayload?.hashId === undefined &&
+      (requestPayload?.hashIds as string[])?.includes(this.chargingStation.hashId) === false
+    ) {
+      return;
+    }
+    if (
+      requestPayload?.hashIds === undefined &&
+      requestPayload?.hashId !== this.chargingStation.hashId
+    ) {
       return;
     }
+    if (requestPayload?.hashId !== undefined) {
+      logger.warn(
+        `${this.chargingStation.logPrefix()} ${moduleName}.requestHandler: 'hashId' field usage in PDU is deprecated, use 'hashIds' instead`
+      );
+    }
 
     let responsePayload: BroadcastChannelResponsePayload;
     let commandResponse: CommandResponse;