Tutorial: fdc3.addContextListener

fdc3.addContextListener

Add a listener for incoming context. If an entity is part of a context group, and then sets its context listener, it will receive all of its declared contexts.

This is a wrapper for interop.addContextHandler.

Example

function handleIncomingContext(contextInfo) {
    const { type, id } = contextInfo;
    switch (type) {
        case 'fdc3.instrument':
            handleInstrumentContext(contextInfo);
            break;
        case 'fdc3.country':
            handleCountryContext(contextInfo);
            break;

        default:
            break;
    }
}


function handleInstrumentContext(contextInfo) {
    const { type, id } = contextInfo;
    console.log('contextInfo for instrument', contextInfo)
}

function handleCountryContext(contextInfo) {
    const { type, id } = contextInfo;
    console.log('contextInfo for country', contextInfo)
}

fdc3.addContextListener(handleIncomingContext);