import { BroadcastChannelRequest, BroadcastChannelResponse } from '../types/WorkerBroadcastChannel';
-export default class WorkerBroadcastChannel extends BroadcastChannel {
- constructor() {
+export default abstract class WorkerBroadcastChannel extends BroadcastChannel {
+ protected constructor() {
super('worker');
}
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;
+ }
}