AboutSupportDeveloper GuideVersion 41.129.83.2

Instance created to enable use of a channel as a provider. Allows for communication with the ChannelClients by invoking an action on a single client via dispatch or all clients via publish and to listen for communication from clients by registering an action via register.

Middleware functions receive the following arguments: (action, payload, senderId). The return value of the middleware function will be passed on as the payload from beforeAction, to the action listener, to afterAction unless it is undefined, in which case the most recently defined payload is used. Middleware can be used for side effects.

Hierarchy

  • ChannelBase
    • ChannelProvider

Accessors

Methods

  • Register middleware that fires after the action.

    Parameters

    Returns void

    If the action does not return the payload, then the afterAction will not have access to the payload object.

    Channel Provider:

    (async ()=> {
    const provider = await fin.InterApplicationBus.Channel.create('channelName');

    await provider.register('provider-action', (payload, identity) => {
    return {
    echo: payload
    };
    });

    await provider.afterAction((action, payload, identity) => {
    //the payload can be altered here after handling the action but before sending an acknowledgement.
    payload.sent = date.now();
    return payload;
    });

    })();

    Channel Client:

    (async ()=> {
    const client = await fin.InterApplicationBus.Channel.connect('channelName');

    await client.register('client-action', (payload, identity) => {
    return {
    echo: payload
    };
    });

    await client.afterAction((action, payload, identity) => {
    //the payload can be altered here after handling the action but before sending an acknowledgement.
    payload.sent = date.now();
    return payload;
    });

    })();
  • Register middleware that fires before the action.

    Parameters

    Returns void

    Channel Provider:

    (async ()=> {
    const provider = await fin.InterApplicationBus.Channel.create('channelName');

    provider.register('provider-action', (payload, identity) => {
    console.log(payload, identity);
    return {
    echo: payload
    };
    });

    provider.beforeAction((action, payload, identity) => {
    //The payload can be altered here before handling the action.
    payload.received = Date.now();
    return payload;
    });

    })();

    Channel Client:

    (async ()=> {
    const client = await fin.InterApplicationBus.Channel.connect('channelName');

    client.register('client-action', (payload, identity) => {
    console.log(payload, identity);
    return {
    echo: payload
    };
    });

    client.beforeAction((action, payload, identity) => {
    //The payload can be altered here before handling the action.
    payload.received = Date.now();
    return payload;
    });

    const providerResponse = await client.dispatch('provider-action', { message: 'Hello From the client' });
    console.log(providerResponse);
    })();
  • Destroy the channel, raises disconnected events on all connected channel clients.

    Returns Promise<void>

    (async ()=> {
    const provider = await fin.InterApplicationBus.Channel.create('channelName');

    await provider.destroy();
    })();
  • Dispatch an action to a specified client. Returns a promise for the result of executing that action on the client side.

    Parameters

    • to: Identity | ClientIdentity

      Identity of the target client.

    • action: string

      Name of the action to be invoked by the client.

    • Optionalpayload: any

      Payload to be sent along with the action.

    Returns Promise<any>

    Because multiple clients can share the same name and uuid, when dispatching from a provider to a client, the identity you provide must include the client's unique endpointId property. This endpointId is passed to the provider in both the Provider.onConnection callback and in any registered action callbacks.

    (async ()=> {
    const provider = await fin.InterApplicationBus.Channel.create('channelName');

    await provider.register('provider-action', async (payload, identity) => {
    console.log(payload, identity);
    return await provider.dispatch(identity, 'client-action', 'Hello, World!');
    });
    })();
  • Returns an array with info on every Client connected to the Provider

    Returns Promise<ClientInfo[]>

    const provider = await fin.InterApplicationBus.Channel.create('openfin');
    const client = await fin.InterApplicationBus.Channel.connect('openfin');
    const clientInfo = await provider.getAllClientInfo();

    console.log(clientInfo);

    // [
    // {
    // "uuid": "openfin",
    // "name": "openfin-view",
    // "endpointId": "6d4c7ca8-4a74-4634-87f8-760558229613",
    // "entityType": "view",
    // "url": "https://openfin.co"
    // },
    // {
    // "uuid": "openfin2",
    // "name": "openfin-view2",
    // "endpointId": "4z5d8ab9-2b81-3691-91ex-142179382511",
    // "entityType": "view",
    // "url": "https://example.com"
    // }
    //]
  • Register a listener that is called on every new client connection.

    Returns void

    It is passed the identity of the connecting client and a payload if it was provided to Channel.connect. If you wish to reject the connection, throw an error. Be sure to synchronously provide an onConnection upon receipt of the channelProvider to ensure all potential client connections are caught by the listener.

    Because multiple clients can exist at the same name and uuid, in order to distinguish between individual clients, the identity argument in a provider's onConnection callback contains an endpointId property. When dispatching from a provider to a client, the endpointId property must be provided in order to send an action to a specific client.

    (async ()=> {
    const provider = await fin.InterApplicationBus.Channel.create('channelName');

    provider.onConnection(identity => {
    console.log('Client connected', identity);
    });
    })();

    Reject connection:

    (async ()=> {
    const provider = await fin.InterApplicationBus.Channel.create('channelName');

    provider.onConnection(identity => {
    throw new Error('Connection Rejected');
    });
    })();
  • Register a listener that is called on client disconnection. It is passed the disconnection event of the disconnecting client.

    Returns void

    (async ()=> {
    const provider = await fin.InterApplicationBus.Channel.create('channelName');

    await provider.onDisconnection(evt => {
    console.log('Client disconnected', `uuid: ${evt.uuid}, name: ${evt.name}`);
    });
    })();
  • Register an error handler. This is called before responding on any error.

    Parameters

    • func: ErrorMiddleware

      Channel Provider:

      (async ()=> {
      const provider = await fin.InterApplicationBus.Channel.create('channelName');

      provider.register('provider-action', (payload, identity) => {
      console.log(payload);
      throw new Error('Action error');
      return {
      echo: payload
      };
      });

      provider.onError((action, error, identity) => {
      console.log('uncaught Exception in action:', action);
      console.error(error);
      });

      })();

      Channel Client:

      (async ()=> {
      const client = await fin.InterApplicationBus.Channel.connect('channelName');

      client.register('client-action', (payload, identity) => {
      console.log(payload);
      throw new Error('Action error');
      return {
      echo: payload
      };
      });

      client.onError((action, error, identity) => {
      console.log('uncaught Exception in action:', action);
      console.error(error);
      });
      })();

    Returns void

  • Parameters

    Returns Promise<any>

  • Publish an action and payload to every connected client. Synchronously returns an array of promises for each action (see dispatch).

    Parameters

    • action: string
    • payload: any

    Returns Promise<any>[]

    (async ()=> {
    const provider = await fin.InterApplicationBus.Channel.create('channelName');

    await provider.register('provider-action', async (payload, identity) => {
    console.log(payload, identity);
    return await Promise.all(provider.publish('client-action', { message: 'Broadcast from provider'}));
    });
    })();
  • Register an action to be called by dispatching from any channelClient or channelProvider.

    Parameters

    Returns boolean

    The return value will be sent back as an acknowledgement to the original caller. You can throw an error to send a negative-acknowledgement and the error will reject the promise returned to the sender by the dispatch call. Once a listener is registered for a particular action, it stays in place receiving and responding to incoming messages until it is removed. This messaging mechanism works exactly the same when messages are dispatched from the provider to a client. However, the provider has an additional publish method that sends messages to all connected clients.

    Because multiple clients can share the same name and uuid, in order to distinguish between individual clients, the identity argument in a provider's registered action callback contains an endpointId property. When dispatching from a provider to a client, the endpointId property must be provided in order to send an action to a specific client.

    Channel Provider:

    (async ()=> {
    const provider = await fin.InterApplicationBus.Channel.create('channelName');

    await provider.register('provider-action', (payload, identity) => {
    console.log('Action dispatched by client: ', identity);
    console.log('Payload sent in dispatch: ', payload);

    return { echo: payload };
    });
    })();

    Channel Client:

    (async ()=> {
    const client = await fin.InterApplicationBus.Channel.connect('channelName');

    await client.register('client-action', (payload, identity) => {
    console.log('Action dispatched by client: ', identity);
    console.log('Payload sent in dispatch: ', payload);

    return { echo: payload };
    });
    })();
  • Remove an action by action name.

    Parameters

    • action: string

    Returns void

    (async ()=> {
    const provider = await fin.InterApplicationBus.Channel.create('channelName');

    await provider.register('provider-action', (payload, identity) => {
    console.log(payload);
    return {
    echo: payload
    };
    });

    await provider.remove('provider-action');

    })();
  • Registers a default action. This is used any time an action that has not been registered is invoked.

    Parameters

    Returns void

    Channel Provider:

    (async ()=> {
    const provider = await fin.InterApplicationBus.Channel.create('channelName');

    await provider.setDefaultAction((action, payload, identity) => {
    console.log(`Client with identity ${JSON.stringify(identity)} has attempted to dispatch unregistered action: ${action}.`);

    return {
    echo: payload
    };
    });

    })();

    Channel Client:

    (async ()=> {
    const client = await fin.InterApplicationBus.Channel.connect('channelName');

    await client.setDefaultAction((action, payload, identity) => {
    console.log(`Provider with identity ${JSON.stringify(identity)} has attempted to dispatch unregistered action: ${action}.`);

    return {
    echo: payload
    };
    });

    })();
  • Parameters

    Returns void

  • Parameters

    Returns void

  • Parameters

    Returns Promise<void>