1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-21 09:38:01 +02:00
joplin/packages/lib/utils/ipc/WorkerToWindowMessenger.ts
2024-08-02 14:51:49 +01:00

24 lines
730 B
TypeScript

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);
}
}