Tutorial: fdc3.getCurrentChannel

fdc3.getCurrentChannel

Returns the Channel that the entity (window or view) is subscribed to. Returns null if not joined to a channel. When switching between channels, the info (id and displayMetadata) can become stale. We recommend getting a new instance of the current channel when switching to make sure the info is correct. Listeners will still remain set, no need to call those again when getting a new instance, as it will error out.

Example

await fdc3.joinChannel('yellow');
await fdc3.getCurrentChannel();

// switching channels
await fdc3.joinChannel('yellow');
let currentChannel;
currentChannel = await fdc3.getCurrentChannel();

// the channel would look something like this:
{
    id: 'yellow',
    displayMetadata: {
        color: '#E9FF8F',
        name: 'yellow'
    },
    type: 'system',
    addContextListener: f(),
    broadcast: f(),
    getCurrentContext: f()
}

// You can then add a listener:
currentChannel.addContextListener(null, console.log);

// Then if you switched channels, liked this:
await fdc3.joinChannel('red');

// The listener will work, but the info will now be stale, as your actual current channel is red.
// So it would be best here to grab a new instance of the current channel so the info is up to date.
currentChannel = await fdc3.getCurrentChannel();