Skip to content

Function: createMultiplexedEndpoint()

createMultiplexedEndpoint(baseEndpoint, name): Channel<any>

Creates a multiplexed endpoint that allows multiple channels over a single PostMessageEndpoint

Parameters

baseEndpoint

PostMessageEndpointBase<any>

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

Released under the MIT License.