AboutSupportDeveloper GuideVersion 36.122.80.11

A messaging bus that allows for pub/sub messaging between different applications.

Hierarchy

  • Base
    • InterApplicationBus

Properties

Channel: Channel
events: {
    subscriberAdded: string;
    subscriberRemoved: string;
} = ...

Type declaration

  • subscriberAdded: string
  • subscriberRemoved: string
on: any
removeAllListeners: any

Accessors

  • get me(): Identity
  • Provides access to the OpenFin representation of the current code context (usually a document such as a View or Window), as well as to the current Interop context.

    Useful for debugging in the devtools console, where this will intelligently type itself based on the context in which the devtools panel was opened.

    Returns Identity

Methods

  • Publishes a message to all applications running on OpenFin Runtime that are subscribed to the specified topic.

    Parameters

    • topic: string

      The topic on which the message is sent

    • message: any

      The message to be published. Can be either a primitive data type (string, number, or boolean) or composite data type (object, array) that is composed of other primitive or composite data types

    Returns Promise<void>

    Example

    fin.InterApplicationBus.publish('topic', 'hello').then(() => console.log('Published')).catch(err => console.log(err));
    
  • Sends a message to a specific application on a specific topic.

    Parameters

    • destination: {
          name?: string;
          uuid: string;
      }

      The identity of the application to which the message is sent

      • Optional name?: string
      • uuid: string
    • topic: string

      The topic on which the message is sent

    • message: any

      The message to be sent. Can be either a primitive data type (string, number, or boolean) or composite data type (object, array) that is composed of other primitive or composite data types

    Returns Promise<void>

    Example

    fin.InterApplicationBus.send(fin.me, 'topic', 'Hello there!').then(() => console.log('Message sent')).catch(err => console.log(err));
    
  • Subscribes to messages from the specified application on the specified topic.

    Parameters

    • source: {
          name?: string;
          uuid: string;
      }

      This object is described in the Identity in the typedef

      • Optional name?: string
      • uuid: string
    • topic: string

      The topic on which the message is sent

    • listener: any

      A function that is called when a message has been received. It is passed the message, uuid and name of the sending application. The message can be either a primitive data type (string, number, or boolean) or composite data type (object, array) that is composed of other primitive or composite data types

    Returns Promise<void>

    Example

    // subscribe to a specified application
    fin.InterApplicationBus.subscribe(fin.me, 'topic', sub_msg => console.log(sub_msg)).then(() => console.log('Subscribed to the specified application')).catch(err => console.log(err));

    // subscribe to wildcard
    fin.InterApplicationBus.subscribe({ uuid: '*' }, 'topic', sub_msg => console.log(sub_msg)).then(() => console.log('Subscribed to *')).catch(err => console.log(err));
  • Unsubscribes to messages from the specified application on the specified topic.

    Parameters

    • source: {
          name?: string;
          uuid: string;
      }

      This object is described in the Identity in the typedef

      • Optional name?: string
      • uuid: string
    • topic: string

      The topic on which the message is sent

    • listener: any

      A callback previously registered with subscribe()

    Returns Promise<void>

    Remarks

    If you are listening to all apps on a topic, (i.e you passed { uuid:'*' } to the subscribe function) then you need to pass { uuid:'*' } to unsubscribe as well. If you are listening to a specific application, (i.e you passed { uuid:'some_app' } to the subscribe function) then you need to provide the same identifier to unsubscribe, unsubscribing to * on that same topic will not unhook your initial listener otherwise.

    Example

    const listener = console.log;

    // If any application publishes a message on topic `foo`, our listener will be called.
    await fin.InterApplicationBus.subscribe({ uuid:'*' }, 'foo', listener)

    // When you want to unsubscribe, you need to specify the uuid of the app you'd like to
    // unsubscribe from (or `*`) and provide the same function you gave the subscribe function
    await fin.InterApplicationBus.unsubscribe({ uuid:'*' }, 'foo', listener)