1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-18 09:35:20 +02:00
joplin/packages/lib/utils/ipc/WorkerToWindowMessenger.ts

24 lines
730 B
TypeScript
Raw Normal View History

import RemoteMessenger from './RemoteMessenger';
import { SerializableData } from './types';
export default class WorkerToWindowMessenger<LocalInterface, RemoteInterface> extends RemoteMessenger<LocalInterface, RemoteInterface> {
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);
}
}