-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathgetMessenger.ts
22 lines (19 loc) · 1.01 KB
/
getMessenger.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import type { Schema } from './schema'
import { createBridgeTransport } from './transports/bridge'
import { createExtensionTransport } from './transports/extension'
import { createTabTransport } from './transports/tab'
import type { Transport } from './transports/types'
import { createWindowTransport } from './transports/window'
const transportsForConnection = {
'wallet:inpage': createBridgeTransport('wallet:inpage'),
'background:inpage': createBridgeTransport('background:inpage'),
'background:wallet': createExtensionTransport('background:wallet'),
'wallet:contentScript': createTabTransport('wallet:contentScript'),
'background:contentScript': createTabTransport('background:contentScript'),
'contentScript:inpage': createWindowTransport('contentScript:inpage'),
} as const
type Connection = keyof typeof transportsForConnection
export type Messenger = Transport<Connection, Schema>
export function getMessenger(connection: Connection): Messenger {
return transportsForConnection[connection] as Messenger
}