X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FWorkerBroadcastChannel.ts;h=12a877c12add623365c0c8c6c6068c62841000d2;hb=53e5fd67dea2dd83ec9c34d963dd6e502ec46f5c;hp=2099d695ab683e75d315151e02c9c5914eb6cedd;hpb=02a6943a30a9a6c93e5dcbdb79aa8d9746ae368e;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/WorkerBroadcastChannel.ts b/src/charging-station/WorkerBroadcastChannel.ts index 2099d695..12a877c1 100644 --- a/src/charging-station/WorkerBroadcastChannel.ts +++ b/src/charging-station/WorkerBroadcastChannel.ts @@ -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; + } }