Index

Index

Type aliases

Listener

Listener type alias, generic type that can be used to refer any context or intent listener.

Functions

addContextListener

  • Adds a listener for incoming context broadcasts from the desktop agent.

    To unsubscribe, use the returned ContextListener.

    Parameters

    • handler: function

      The handler function to call when we receive a broadcast context.

    Returns ContextListener

addEventListener

  • addEventListener(eventType: "channel-changed", handler: function): void
  • Event that is fired whenever a window changes from one channel to another. This captures events from all channels (including the default channel).

    See also ChannelBase.addEventListener, for subscribing to events of a particular context channel.

    Parameters

    • eventType: "channel-changed"

      The event type.

    • handler: function

      The handler to call when the event is fired.

    Returns void

addIntentListener

  • addIntentListener(intent: string, handler: function): IntentListener
  • Adds a listener for incoming intents from the Agent.

    If the handler function returns a defined value, this value will be returned to the caller of raiseIntent in the data property of the IntentResolution object. If the value returned by the handler is a Promise, this will be resolved before passing to the raiseIntent caller. If multiple handlers are registered by a target application for a given intent, the fist defined return value to be returned and resolved (if a Promise) will be used.

    To unsubscribe, use the returned IntentListener.

    Parameters

    • intent: string

      The name of the intent to listen for.

    • handler: function

      The handler to call when we get sent an intent.

    Returns IntentListener

broadcast

  • broadcast(context: Context): Promise<void>
  • Publishes context to other apps on the desktop. Any apps using addContextListener will receive this.

     agent.broadcast(context);

    Only windows in the same channel as the broadcasting window will receive the context. All windows will initially be in the same channel (referred to as the default channel). See ContextChannels for more details.

    Note that windows do not receive their own broadcasts. If the window calling broadcast has also added one or more context listeners, then those listeners will not fire as a result of this broadcast.

    throws

    TypeError if context is not a valid Context.

    Parameters

    • context: Context

      The context to broadcast.

    Returns Promise<void>

findIntent

  • Find out more information about a particular intent by passing its name, and optionally its context.

    findIntent is effectively granting programmatic access to the desktop agent's resolver. A promise resolving to the intent, its metadata and metadata about the apps registered to handle it is returned. This can be used to raise the intent against a specific app.

    For example, I know 'StartChat' exists as a concept, and want to know more about it.

    const appIntent = await agent.findIntent("StartChat");

    This returns a single AppIntent (some fields omitted for brevity, see Application for full list of apps fields):

    {
         intent: { name: "StartChat", displayName: "Chat" },
         apps: [{ name: "Skype" }, { name: "Symphony" }, { name: "Slack" }]
    }

    We can then raise the intent against a particular app

    await agent.raiseIntent(appIntent.intent.name, context, appIntent.apps[0].name);
    throws

    If context is passed, an FDC3Error with a SendContextError code.

    throws

    If context is passed, TypeError if context is not a valid Context.

    Parameters

    • intent: string

      The intent name to find.

    • Optional context: Context

      An optional context to send to find the intent.

    Returns Promise<AppIntent>

findIntentsByContext

  • Find all the available intents for a particular context.

    findIntentsByContext is effectively granting programmatic access to the desktop agent's resolver. A promise resolving to all the intents, their metadata and metadata about the apps registered to handle it is returned, based on the context export types the intents have registered.

    An empty array will be returned if there are no available intents for the given context.

    For example, I have a context object and I want to know what I can do with it, so I look for intents...

    const appIntents = await agent.findIntentsByContext(context);

    This returns an array of AppIntent objects such as the following (some fields omitted for brevity, see Application for full list of apps fields):

    [
       {
          intent: { name: "StartCall", displayName: "Call" },
          apps: [{ name: "Skype" }]
      },
      {
          intent: { name: "StartChat", displayName: "Chat" },
          apps: [{ name: "Skype" }, { name: "Symphony" }, { name: "Slack" }]
      }
    ]

    We could now use this by taking one of the intents, and raising it.

    // Select a particular intent to raise
    const selectedIntent = appIntents[1];
    
    // Raise the intent, passing the given context, letting the user select which app to use
    await agent.raiseIntent(selectedIntent.intent.name, context);
    
    // Raise the intent, passing the given context, targeting a particular app
    const selectedApp = selectedIntent.apps[0];
    await agent.raiseIntent(selectedIntent.intent.name, context, selectedApp.name);
    throws

    FDC3Error with a SendContextError code.

    throws

    TypeError if context is not a valid Context.

    Parameters

    • context: Context

      Returned intents must support this context.

    Returns Promise<AppIntent[]>

open

  • Launches/links to an app by name. The application will be started if it is not already running.

    If a Context object is passed in, this object will be provided to the opened application via a ContextListener.

    If opening errors, it returns an FDC3Error with a string from the ApplicationError export enumeration.

        // No context
        agent.open('myApp');
        // With context
        agent.open('myApp', context);
    throws

    FDC3Error with an ApplicationError code.

    throws

    If context is passed, FDC3Error with a SendContextError code.

    throws

    If context is passed, TypeError if context is not a valid Context.

    Parameters

    • name: AppName

      The AppName to launch.

    • Optional context: Context

      A context to pass to the app post-launch.

    Returns Promise<void>

raiseIntent

  • Raises an intent to the desktop agent to resolve. Intents can be either targeted or non-targeted, determined by the presence or absense of the target argument. For non-targeted intents, the service will search the directory and any running applications to find an application that can handle the given intent and context. If there are multiple such applications, the end user will be asked to select which application they wish to use.

    If the application isn't already running, it will be started by the service. The intent data will then be passed to the target application's intent listener. The promise returned by this function resolves when the service has confirmed that the target application has been started its intent listener has completed successfully.

    The returned IntentResolution object indicates which application handled the intent (if the intent is a targeted intent, this will always be the value passed as target), and contains the data returned by the target applications intent listener (if any).

    // Raise an intent to start a chat with a given contact
    const intentR = await agent.raiseIntent("StartChat", context);
    // Use the IntentResolution object to target the same chat app with a new context
    agent.raiseIntent("StartChat", newContext, intentR.source);
    throws

    FDC3Error with a ResolveError code.

    throws

    FDC3Error with an ApplicationError code.

    throws

    FDC3Error with a SendContextError code.

    throws

    TypeError if context is not a valid Context.

    Parameters

    • intent: string

      The intent name to raise.

    • context: Context

      The context that will be sent with this intent.

    • Optional target: AppName

      An optional AppName to send the intent to.

    Returns Promise<IntentResolution>

removeEventListener

  • removeEventListener(eventType: "channel-changed", handler: function): void
  • Unsubscribes from a particular event.

    Has no effect if eventType isn't a valid event, or listener isn't a handler registered against eventType.

    Parameters

    Returns void