OpenFin FDC3 app development

OpenFin simplifies FDC3 application development by providing a built-in DesktopAgent (called the Interop Broker), automatically connecting applications to the Interop Broker, and providing built-in System Channel and App Channel management.

Here is a quick introduction to OpenFin's new paradigm for FDC3 support.

In the past, FDC3 application developers had to create and connect to a DesktopAgent, manage channels, and perform other tasks to meet the FDC3 standard. This is what the new, simplified FDC3 paradigm looks like:

  • Every Platform automatically comes with a DesktopAgent, which we call the Interop Broker. Application developers can simply use the APIs that are automatically available. You can read more about them in the FDC3 API reference documentation.
  • Every view in a platform automatically connects to the Interop Broker for you.
  • We take care of System Channel management for you, if you use OpenFin Workspace as your platform. Workspace comes with a color picker channel management system built into the UI. Your app only has to listen to incoming context messages and broadcast its own context messages.
    You can read the Introduction to Workspace or the Workspace Developer Quick Start for more information on OpenFin Workspace.
  • We take care of App Channel management for you as well, if you use OpenFin Workspace as your platform. Your platform applications can then communicate with each other on a channel name or channel names of your choosing.

The core APIs

As an application developer, you only need to use a few APIs if you use OpenFin Workspace. This applies whether you are using contexts, intents, or app channels.

The core APIs for contexts

fdc3.addContextListener: Declares a handler for incoming context events.

Code 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);

fdc3.broadcast: Sends a context to all other members of the context group.

Code example:

setInstrumentContext = async (ticker) => {
    fdc3.broadcast({type: 'fdc3.instrument', id: {ticker}})
}

// The user clicks an instrument of interest. 
// Set that Instrument context so the rest of our workflow updates with information for that instrument
instrumentElement.on('click', (evt) => {
    setInstrumentContext(evt.ticker)
})

The core APIs for intents

fdc3.addIntentListener: Declares a handler for incoming intent events.

Code example:

const contextHandler = (context) => {
    myViewChartListener(context);
};

const listener = fdc3.addIntentListener('ViewChart', contextHandler);

function myAppCloseSequence() {
    // to unsubscribe the handler, simply call:
    listener.unsubscribe();
}

fdc3.raiseIntent: Raises an intent event.

Code example:

tickerElement.on('click', (element) => {
    const ticker = element.innerText;
    const context = { type: 'fdc3.instrument', id: { ticker } };

    fdc3.raiseIntent('ViewChart', context);
})

// Passing in a target app
tickerElement.on('click', (element) => {
    const ticker = element.innerText;
    const context = { type: 'fdc3.instrument', id: { ticker } };

    fdc3.raiseIntent('ViewChart', context, 'skype');

    // The shape of the intent that will then come in through InteropBroker.handleFiredIntent will be:
    {
        name: 'ViewChart',
        context: { type: 'fdc3.instrument', id: { ticker } },
        metadata: { target: 'skype' }
    }
})

The core APIs for App Channels

fdc3.getOrCreateChannel: Returns the specified App Channel, or creates the channel if not already created and returns the channel.

To communicate on an app channel, use fdc3.addContextListener to listen to App Channel events, and fdc3.broadcast to broadcast channel events on the App Channel. For code examples on how to use these methods, see the examples in The core APIs for contexts.