Tutorial: fdc3v2.createPrivateChannel

fdc3v2.createPrivateChannel

Returns a Channel with an auto-generated identity that is intended for private communication between applications. Primarily used to create channels that will be returned to other applications via an IntentResolution for a raised intent.

Example

fdc3.addIntentListener('ViewChart', async (context) => {
    const channel = await fdc3.createPrivateChannel();
    const symbol = context.id.ticker;

    // This gets called when the remote side adds a context listener
    const addContextListener = channel.onAddContextListener((contextType) => {
        // broadcast price quotes as they come in from our quote feed
        feed.onQuote(symbol, (price) => {
          channel.broadcast({ type: "price", price});
        });
    });

    // This gets called when the remote side calls Listener.unsubscribe()
    const unsubscriberListener = channel.onUnsubscribe((contextType) => {
        feed.stop(symbol);
    });

    // This gets called if the remote side closes
    const disconnectListener = channel.onDisconnect(() => {
        feed.stop(symbol);
    });

    return channel;
});