UI server: logging and code refinements
[e-mobility-charging-stations-simulator.git] / src / charging-station / WorkerBroadcastChannel.ts
CommitLineData
32de5a57
LM
1import { BroadcastChannel } from 'worker_threads';
2
02a6943a 3import { BroadcastChannelRequest, BroadcastChannelResponse } from '../types/WorkerBroadcastChannel';
4e3ff94d 4
6c8f5d90
JB
5export default abstract class WorkerBroadcastChannel extends BroadcastChannel {
6 protected constructor() {
32de5a57
LM
7 super('worker');
8 }
4e3ff94d
JB
9
10 public sendRequest(request: BroadcastChannelRequest): void {
11 this.postMessage(request);
12 }
02a6943a 13
6c8f5d90 14 protected sendResponse(response: BroadcastChannelResponse): void {
02a6943a
JB
15 this.postMessage(response);
16 }
6c8f5d90
JB
17
18 protected isRequest(message: any): boolean {
19 return Array.isArray(message) && message.length === 3;
20 }
21
22 protected isResponse(message: any): boolean {
23 return Array.isArray(message) && message.length === 2;
24 }
32de5a57 25}