X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FWorkerBroadcastChannel.ts;h=12a877c12add623365c0c8c6c6068c62841000d2;hb=db2336d96424096d5570606680824af180e33c3a;hp=563da4588b564210ab65992ee084e3a7430231fe;hpb=32de5a575189d226213641f5ee36004f8454cb50;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/WorkerBroadcastChannel.ts b/src/charging-station/WorkerBroadcastChannel.ts index 563da458..12a877c1 100644 --- a/src/charging-station/WorkerBroadcastChannel.ts +++ b/src/charging-station/WorkerBroadcastChannel.ts @@ -1,7 +1,25 @@ import { BroadcastChannel } from 'worker_threads'; -export default class WorkerBroadcastChannel extends BroadcastChannel { - constructor() { +import { BroadcastChannelRequest, BroadcastChannelResponse } from '../types/WorkerBroadcastChannel'; + +export default abstract class WorkerBroadcastChannel extends BroadcastChannel { + protected constructor() { super('worker'); } + + public sendRequest(request: BroadcastChannelRequest): void { + this.postMessage(request); + } + + 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; + } }