import RemoteMessenger from './RemoteMessenger'; import { SerializableData } from './types'; export default class WorkerToWindowMessenger extends RemoteMessenger { public constructor(channelId: string, localApi: LocalInterface|null) { super(channelId, localApi); self.addEventListener('message', this.handleMessageEvent); this.onReadyToReceive(); } private handleMessageEvent = (event: MessageEvent) => { void this.onMessage(event.data); }; protected override postMessage(message: SerializableData): void { self.postMessage(message); } protected override onClose(): void { self.removeEventListener('message', this.handleMessageEvent); } }