Function: createMultiplexedEndpoint()
createMultiplexedEndpoint(
baseEndpoint
,name
):Channel
<any
>
Creates a multiplexed endpoint that allows multiple channels over a single PostMessageEndpoint
Parameters
baseEndpoint
The base endpoint to multiplex
name
string
= ''
Optional name for debugging
Returns
Channel
<any
>
The root channel for creating sub-channels
@NO_SIDE_EFFECTS
Example
typescript
const mux = createMultiplexedEndpoint(endpoint, 'MyApp')
// Create main channel
const mainChannel = mux.createSubChannel<MainData>('main')
// Create sub-channel
const configChannel = mainChannel.createSubChannel<ConfigData>('config')
// Send and receive messages
configChannel.postMessage({ setting: 'value' })
configChannel.addEventListener('message', (event) => {
console.log('Config:', event.data)
})