Improve payload type checking in OCPP, UI and Broadcast Channel
[e-mobility-charging-stations-simulator.git] / src / charging-station / WorkerBroadcastChannel.ts
index 2099d695ab683e75d315151e02c9c5914eb6cedd..12a877c12add623365c0c8c6c6068c62841000d2 100644 (file)
@@ -2,8 +2,8 @@ import { BroadcastChannel } from 'worker_threads';
 
 import { BroadcastChannelRequest, BroadcastChannelResponse } from '../types/WorkerBroadcastChannel';
 
-export default class WorkerBroadcastChannel extends BroadcastChannel {
-  constructor() {
+export default abstract class WorkerBroadcastChannel extends BroadcastChannel {
+  protected constructor() {
     super('worker');
   }
 
@@ -11,7 +11,15 @@ export default class WorkerBroadcastChannel extends BroadcastChannel {
     this.postMessage(request);
   }
 
-  public sendResponse(response: BroadcastChannelResponse): void {
+  protected sendResponse(response: BroadcastChannelResponse): void {
     this.postMessage(response);
   }
+
+  protected isRequest(message: any): boolean {
+    return Array.isArray(message) && message.length === 3;
+  }
+
+  protected isResponse(message: any): boolean {
+    return Array.isArray(message) && message.length === 2;
+  }
 }