AboutSupportDeveloper GuideVersion 41.129.83.3

The Interop Client API is broken up into two groups:

Content Facing APIs - For Application Developers putting Views into a Platform Window, who care about Context. These are APIs that send out and receive the Context data that flows between applications. Think of this as the Water in the Interop Pipes.

Context Grouping APIs - For Platform Developers, to add and remove Views to and from Context Groups. These APIs are utilized under-the-hood in Platforms, so they don't need to be used to participate in Interop. These are the APIs that decide which entities the context data flows between. Think of these as the valves or pipes that control the flow of Context Data for Interop.


All APIs are available at the fin.me.interop namespace.


You only need 2 things to participate in Interop Context Grouping:


Returned by Interop.connectSync Interop.connectSync.


Context Groups API

Intents API

Hierarchy

  • Base
    • InteropClient

Accessors

  • get me(): Identity
  • Returns Identity

    me should only be accessed from the fin global (FinApi.me); access through entity classes is not guaranteed to behave sensibly in all calling contexts.

Methods

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

    Parameters

    • handler: OpenFin.ContextHandler

      Handler for incoming context.

    • OptionalcontextType: string

      The type of context you wish to handle.

    Returns Promise<{
        unsubscribe: (() => void);
    }>

    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)
    }

    fin.me.interop.addContextHandler(handleIncomingContext);

    Passing in a context type as the second parameter will cause the handler to only be invoked with that context type.

    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)
    }


    fin.me.interop.addContextHandler(handleInstrumentContext, 'instrument')
    fin.me.interop.addContextHandler(handleCountryContext, 'country')
  • Sends an intent to the Interop Broker to resolve.

    Type Parameters

    • T = unknown

    Parameters

    • intent: Intent<OpenFin.IntentMetadata<any>>

      The combination of an action and a context that is passed to an application for resolution.

    Returns Promise<T>

    // View wants to fire an Intent after a user clicks on a ticker
    tickerElement.on('click', (element) => {
    const ticker = element.innerText;
    const intent = {
    name: 'ViewChart',
    context: {type: 'fdc3.instrument', id: { ticker }}
    }

    fin.me.interop.fireIntent(intent);
    })
  • Sends a Context that will be resolved to an Intent by the Interop Broker. This context accepts a metadata property.

    Type Parameters

    • T = unknown

    Parameters

    Returns Promise<T>

    To resolve this info, the function handleFiredIntentByContext is meant to be overridden in the Interop Broker. The format for the response will be determined by the App Provider overriding the function.

    tickerElement.on('click', (element) => {
    const ticker = element.innerText;

    const context = {
    type: 'fdc3.instrument',
    id: {
    ticker
    }
    }

    const intentResolution = await fin.me.interop.fireIntentForContext(context);
    })
  • Gets all clients for a context group.

    Parameters

    • contextGroupId: string

      The id of context group you wish to get clients for.

    Returns Promise<ClientIdentity[]>

    This is primarily used for platform windows. Views within a platform should not have to use this API.

    Returns the Interop-Broker-defined context groups available for an entity to join.

    fin.me.interop.getAllClientsInContextGroup('red')
    .then(clientsInContextGroup => {
    console.log(clientsInContextGroup)
    })
  • Returns the Interop-Broker-defined context groups available for an entity to join. Used by Platform Windows.

    Returns Promise<ContextGroupInfo[]>

    fin.me.interop.getContextGroups()
    .then(contextGroups => {
    contextGroups.forEach(contextGroup => {
    console.log(contextGroup.displayMetadata.name)
    console.log(contextGroup.displayMetadata.color)
    })
    })
  • Gets the last context of the Context Group currently subscribed to. It takes an optional Context Type and returns the last context of that type.

    Parameters

    • OptionalcontextType: string

    Returns Promise<OpenFin.Context>

    await fin.me.interop.joinContextGroup('yellow');
    await fin.me.interop.setContext({ type: 'instrument', id: { ticker: 'FOO' }});
    const currentContext = await fin.me.interop.getCurrentContext();

    // with a specific context
    await fin.me.interop.joinContextGroup('yellow');
    await fin.me.interop.setContext({ type: 'country', id: { ISOALPHA3: 'US' }});
    await fin.me.interop.setContext({ type: 'instrument', id: { ticker: 'FOO' }});
    const currentContext = await fin.me.interop.getCurrentContext('country');
  • Gets display info for a context group

    Parameters

    • contextGroupId: string

      The id of context group you wish to get display info for.

    Returns Promise<undefined | ContextGroupInfo>

    Used by Platform Windows.

    fin.me.interop.getInfoForContextGroup('red')
    .then(contextGroupInfo => {
    console.log(contextGroupInfo.displayMetadata.name)
    console.log(contextGroupInfo.displayMetadata.color)
    })
  • Get information for a particular Intent from the Interop Broker.

    Type Parameters

    • T = unknown

    Returns Promise<T>

    To resolve this info, the function handleInfoForIntent is meant to be overridden in the Interop Broker. The format for the response will be determined by the App Provider overriding the function.

    const intentInfo = await fin.me.interop.getInfoForIntent('ViewChart');
    
  • Get information from the Interop Broker on all Intents that are meant to handle a particular context.

    Type Parameters

    • T = unknown

    Parameters

    Returns Promise<T>

    To resolve this info, the function handleInfoForIntentsByContext is meant to be overridden in the Interop Broker. The format for the response will be determined by the App Provider overriding the function.

    tickerElement.on('click', (element) => {
    const ticker = element.innerText;

    const context = {
    type: 'fdc3.instrument',
    id: {
    ticker
    }
    }

    const intentsInfo = await fin.me.interop.getInfoForIntentByContext(context);
    })
  • Join all Interop Clients at the given identity to context group contextGroupId. If no target is specified, it adds the sender to the context group.

    Parameters

    • contextGroupId: string

      Id of the context group.

    • Optionaltarget: Identity

      Identity of the entity you wish to join to a context group.

    Returns Promise<void>

    Because multiple Channel connections/Interop Clients can potentially exist at a uuid/name combo, we currently join all Channel connections/Interop Clients at the given identity to the context group. If an endpointId is provided (which is unlikely, unless the call is coming from an external adapter), then we only join that single connection to the context group. For all intents and purposes, there will only be 1 connection present in Platform and Browser implmentations, so this point is more-or-less moot. Used by Platform Windows.

    joinViewToContextGroup = async (contextGroupId, view) => {
    await fin.me.interop.joinContextGroup(contextGroupId, view);
    }

    getLastFocusedView()
    .then(lastFocusedViewIdentity => {
    joinViewToContextGroup('red', lastFocusedViewIdentity)
    })
  • Join the current entity to session context group sessionContextGroupId and return a sessionContextGroup instance. If the sessionContextGroup doesn't exist, one will get created.

    Parameters

    • sessionContextGroupId: string

      Id of the context group.

    Returns Promise<SessionContextGroup>

    Session Context Groups do not persist between runs and aren't present on snapshots.

    Say we want to have a Session Context Group that holds UI theme information for all apps to consume:

    My color-picker View:

        const themeSessionContextGroup = await fin.me.interop.joinSessionContextGroup('theme');

    const myColorPickerElement = document.getElementById('color-palette-picker');
    myColorPickerElement.addEventListener('change', event => {
    themeSessionContextGroup.setContext({ type: 'color-palette', selection: event.value });
    });

    In other views:

        const themeSessionContextGroup = await fin.me.interop.joinSessionContextGroup('theme');

    const changeColorPalette = ({ selection }) => {
    // change the color palette to the selection
    };

    // If the context is already set by the time the handler was set, the handler will get invoked immediately with the current context.
    themeSessionContextGroup.addContextHandler(changeColorPalette, 'color-palette');
  • Register a listener that is called when the Interop Client has been disconnected from the Interop Broker. Only one listener per Interop Client can be set.

    Returns Promise<void>

    const listener = (event) => {
    const { type, topic, brokerName} = event;
    console.log(`Disconnected from Interop Broker ${brokerName} `);
    }

    await fin.me.interop.onDisconnection(listener);
  • Adds an intent handler for incoming intents. The last intent sent of the name subscribed to will be received.

    Parameters

    • handler: OpenFin.IntentHandler

      Registered function meant to handle a specific intent type.

    • intentName: string

      The name of an intent.

    • Optionaloptions: any

    Returns Promise<{
        unsubscribe: (() => Promise<void>);
    }>

    const intentHandler = (intent) => {
    const { context } = intent;
    myViewChartHandler(context);
    };

    const subscription = await fin.me.interop.registerIntentHandler(intentHandler, 'ViewChart');

    function myAppCloseSequence() {
    // to unsubscribe the handler, simply call:
    subscription.unsubscribe();
    }
  • Removes the specified target from a context group. If no target is specified, it removes the sender from their context group. Used by Platform Windows.

    Parameters

    • Optionaltarget: Identity

      Identity of the entity you wish to join to a context group.

    Returns Promise<void>

    removeViewFromContextGroup = async (view) => {
    await fin.me.interop.removeFromContextGroup(view);
    }

    getLastFocusedView()
    .then(lastFocusedViewIdentity => {
    removeViewFromContextGroup(lastFocusedViewIdentity)
    })
  • Sets a context for the context group of the current entity.

    Parameters

    Returns Promise<void>

    The entity must be part of a context group in order set a context.

    setInstrumentContext = async (ticker) => {
    fin.me.interop.setContext({type: 'instrument', id: {ticker}})
    }

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