Class: InteropBroker

InteropBroker

THE INTEROP API IS EXPERIMENTAL. IF YOU WOULD LIKE TO USE IT, PLEASE USE OUR DEFAULT IMPLEMENTATION IN BROWSER

The Interop Broker is responsible for keeping track of the Interop state of the Platform, and for directing messages to the proper locations.


There are 2 ways to inject custom functionality into the Interop Broker:

1. Configuration

At the moment, you can configure the default context groups for the Interop Broker without having to override it. To do so, include the interopBrokerConfiguration contextGroups option in your platform options in your manifest. This is the preferred method.

{
     "runtime": {
         "arguments": "--v=1 --inspect",
         "version": "alpha-v19"
     },
     "platform": {
         "uuid": "platform_customization_local",
         "applicationIcon": "https://openfin.github.io/golden-prototype/favicon.ico",
         "autoShow": false,
         "providerUrl": "http://localhost:5555/provider.html",
         "interopBrokerConfiguration": {
             "contextGroups": [
                 {
                     "id": "green",
                     "displayMetadata": {
                         "color": "#00CC88",
                         "name": "green"
                     }
                 },
                 {
                     "id": "purple",
                     "displayMetadata": {
                         "color": "#8C61FF",
                         "name": "purple"
                     }
                 },
             ]
         }
     }
}

2. Overriding

Similarly to how Platform Overriding works, you can override functions in the Interop Broker in fin.Platform.init. An example of that is shown below. Overriding isConnectionAuthorized and isActionAuthorized will allow you to control allowed connections and allowed actions.

However, if there is custom functionality you wish to include in the Interop Broker, please let us know. We would like to provide better configuration options so that you don't have to continually maintain your own override code.

fin.Platform.init({
    overrideCallback: async (Provider) => {
        class Override extends Provider {
            async getSnapshot() {
                console.log('before getSnapshot')
                const snapshot = await super.getSnapshot();
                console.log('after getSnapshot')
                return snapshot;
            }

            async applySnapshot({ snapshot, options }) {
                console.log('before applySnapshot')
                const originalPromise = super.applySnapshot({ snapshot, options });
                console.log('after applySnapshot')

                return originalPromise;
            }
        };
        return new Override();
    },
    interopOverride: async (InteropBroker, provider, options, ...args) => {
        class Override extends InteropBroker {
            async joinContextGroup(channelName = 'default', target) {
                console.log('before super joinContextGroup')
                super.joinContextGroup(channelName, target);
                console.log('after super joinContextGroup')
            }
        }

        options.systemChannels = [
            {
                id: 'green',
                displayMetadata: {
                    color: '#00CC88',
                    name: 'green'
                }
            },
            {
                id: 'purple',
                displayMetadata: {
                    color: '#8C61FF',
                    name: 'purple'
                }
            },
            {
                id: 'orange',
                displayMetadata: {
                    color: '#FF8C4C',
                    name: 'orange'
                }
            },
            {
                id: 'red',
                displayMetadata: {
                    color: '#FF5E60',
                    name: 'red'
                }
            }
        ];
      return new Override(provider, options, ...args);
  }
});

Methods

(async) addClientToContextGroup(addClientToContextGroupOptions, clientIdentity) → {Promise.<void>}

EXPERIMENTAL

Helper function for InteropBroker.joinContextGroup. Does the work of actually adding the client to the Context Group. Used by Platform Windows.

Parameters:
Name Type Description
addClientToContextGroupOptions AddClientToContextGroupOptions

Contains the contextGroupId

clientIdentity ClientIdentity

Identity of the client sender.

Returns:
Type
Promise.<void>

getAllClientsInContextGroup(getAllClientsInContextGroupOptions) → {Promise.<Array.<ClientIdentity>>}

EXPERIMENTAL

Gets all clients for a context group. Used by Platform Windows.

Parameters:
Name Type Description
getAllClientsInContextGroupOptions GetAllClientsInContextGroupOptions

Contains contextGroupId, the context group you wish to get clients for.

Returns:
Type
Promise.<Array.<ClientIdentity>>

getContextGroups() → {Promise.<Array.<ContextGroupInfo>>}

EXPERIMENTAL

Returns the Interop-Broker-defined context groups available for an entity to join. Because this function is used in the rest of the Interop Broker to fetch the Context Groups, overriding this allows you to customize the Context Groups for the Interop Broker. However, we recommend customizing the context groups through configuration instead. Used by Platform Windows.

Returns:
Type
Promise.<Array.<ContextGroupInfo>>

getInfoForContextGroup(getInfoForContextGroupOptions) → {Promise.<ContextGroupInfo>}

EXPERIMENTAL

Gets display info for a context group Used by Platform Windows.

Parameters:
Name Type Description
getInfoForContextGroupOptions GetInfoForContextGroupOptions

Contains contextGroupId, the context group you wish to get display info for.

Returns:
Type
Promise.<ContextGroupInfo>

(async) handleFiredIntent(intent) → {Promise.<void>}

EXPERIMENTAL

Responsible for launching of applications that can handle a given intent, and delegation of intents to those applications. Must be overridden.

Parameters:
Name Type Description
intent Intent

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

Tutorials:
Returns:
Type
Promise.<void>

(async) isActionAuthorized(_action, _payload, _identity)

Called before every action to check if this entity should be allowed to take the action. Return false to prevent the action

Parameters:
Name Type Description
_action

the string action to authorize in camel case

_payload

the data being sent for this action

_identity

the connection attempting to dispatch this action

(async) isConnectionAuthorized(_id, _connectionPayload)

Can be used to completely prevent a connection. Return false to prevent connections. Allows all connections by default.

Parameters:
Name Type Description
_id

the identity tryinc to connect

_connectionPayload

optional payload to use in custom implementations, will be undefined by default

(async) joinContextGroup(joinContextGroupOptions, senderIdentity) → {Promise.<void>}

EXPERIMENTAL

Join all connections at the given identity (or just one if endpointId provided) to context group contextGroupId. If no target is specified, it adds the sender to the context group. joinContextGroup is responsible for checking connections at the incoming identity. It calls InteropBroker.addClientToContextGroup to actually group the client. Used by Platform Windows.

Parameters:
Name Type Description
joinContextGroupOptions JoinContextGroupOptions

Id of the Context Group and identity of the entity to join to the group.

senderIdentity ClientIdentity

Identity of the client sender.

Returns:
Type
Promise.<void>

(async) removeClientFromContextGroup() → {Promise.<void>}

EXPERIMENTAL

Helper function for InteropBroker.removeFromContextGroup. Does the work of actually removing the client from the Context Group. Used by Platform Windows.

Properties:
Name Type Description
clientIdentity ClientIdentity

Identity of the client sender.

Returns:
Type
Promise.<void>

(async) removeFromContextGroup(removeFromContextGroupOptions, senderIdentity) → {Promise.<void>}

EXPERIMENTAL

Removes the specified target from a context group. If no target is specified, it removes the sender from their context group. removeFromContextGroup is responsible for checking connections at the incoming identity. It calls InteropBroker.removeClientFromContextGroup to actually ungroup the client. Used by Platform Windows.

Parameters:
Name Type Description
removeFromContextGroupOptions RemoveFromContextGroupOptions

Contains the target identity to remove.

senderIdentity ClientIdentity

Identity of the client sender.

Returns:
Type
Promise.<void>

setContext(setContextOptions, clientIdentity) → {void}

EXPERIMENTAL

Sets a context for the context group of the incoming current entity.

Parameters:
Name Type Description
setContextOptions SetContextOptions

New context to set.

clientIdentity ClientIdentity

Identity of the client sender.

Returns:
Type
void

(async) setIntentTarget(intent, target) → {Promise.<void>}

EXPERIMENTAL

Should be called in InteropBroker.handleFiredIntent. While handleFiredIntent is responsible for launching applications, setIntentTarget is used to tell the InteropBroker which application should receive the intent when it is ready.

Parameters:
Name Type Description
intent Intent

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

target Identity

Identity of the target that will handle the intent.

Returns:
Type
Promise.<void>