X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FWorkerBroadcastChannel.ts;h=12a877c12add623365c0c8c6c6068c62841000d2;hb=6812b4e11d45a0d6179a266687c7ad9aa6e3b538;hp=d1d430c3a0c39230aef0c00dd5de5660b25e42a0;hpb=4e3ff94d15f16cbeb7f65d14525bca7af3c551fd;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/WorkerBroadcastChannel.ts b/src/charging-station/WorkerBroadcastChannel.ts index d1d430c3..12a877c1 100644 --- a/src/charging-station/WorkerBroadcastChannel.ts +++ b/src/charging-station/WorkerBroadcastChannel.ts @@ -1,13 +1,25 @@ import { BroadcastChannel } from 'worker_threads'; -import { BroadcastChannelRequest } from '../types/WorkerBroadcastChannel'; +import { BroadcastChannelRequest, BroadcastChannelResponse } from '../types/WorkerBroadcastChannel'; -export default class WorkerBroadcastChannel extends BroadcastChannel { - constructor() { +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; + } }