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 'instrument':
            handleInstrumentContext(contextInfo);
            break;
        case '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);