-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.ts
30 lines (25 loc) · 1.02 KB
/
options.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import browser from 'webextension-polyfill';
import {createBroadcastEventRuntime} from './src/BroadcastEventRuntime';
import {createMessageRuntime} from './src/MessageRuntime';
import {createPersistentPort} from './src/PersistentPort';
import {initTransportAPI} from './src/TransportAPI';
import {internalPacketTypeRouter} from './src/utils/internalPacketTypeRouter';
export function initPegasusTransport(): void {
const port = createPersistentPort('options');
const messageRuntime = createMessageRuntime('options', async (message) =>
port.postMessage(message),
);
port.onMessage((packet) =>
internalPacketTypeRouter(packet, {eventRuntime, messageRuntime}),
);
const eventRuntime = createBroadcastEventRuntime('options', async (event) => {
port.postMessage(event);
});
initTransportAPI({
browser: browser,
emitBroadcastEvent: eventRuntime.emitBroadcastEvent,
onBroadcastEvent: eventRuntime.onBroadcastEvent,
onMessage: messageRuntime.onMessage,
sendMessage: messageRuntime.sendMessage,
});
}