} from '../types/WorkerBroadcastChannel';
import { ResponseStatus } from '../ui/web/src/type/UIProtocol';
import logger from '../utils/Logger';
-import ChargingStation from './ChargingStation';
+import type ChargingStation from './ChargingStation';
import WorkerBroadcastChannel from './WorkerBroadcastChannel';
const moduleName = 'ChargingStationWorkerBroadcastChannel';
if (this.isResponse(messageEvent.data)) {
return;
}
+ 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;
case BroadcastChannelProcedureName.STOP_CHARGING_STATION:
await this.chargingStation.stop();
break;
+ case BroadcastChannelProcedureName.OPEN_CONNECTION:
+ this.chargingStation.openWSConnection();
+ break;
+ case BroadcastChannelProcedureName.CLOSE_CONNECTION:
+ this.chargingStation.closeWSConnection();
+ break;
default:
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
- throw new BaseError(`Unknown broadcast channel command: ${command}`);
+ throw new BaseError(`Unknown worker broadcast channel command: ${command}`);
}
}