Skip to main content
Version: Next

Events

In addition to intent and context events, the FDC3 API and PrivateChannel API may be used to listen for other types of events via their addEventListener() functions.

ApiEvent

Type defining a basic event object that may be emitted by an FDC3 API interface such as DesktopAgent or PrivateChannel. There are more specific event types defined for each interface.

interface ApiEvent {
readonly type: string;
readonly details: any;
}

See also:

EventHandler

type EventHandler = (event: ApiEvent) => void;

Describes a callback that handles non-context and non-intent events. Provides the details of the event.

Used when attaching listeners to events.

See also:

FDC3EventTypes

type FDC3EventTypes = "userChannelChanged" | "contextCleared";

Type defining valid type strings for DesktopAgent interface events.

See also:

ChannelEventTypes

type ChannelEventTypes = "contextCleared";

Type defining valid type strings for Channel interface events.

See also:

FDC3Event

interface FDC3Event extends ApiEvent{
readonly type: FDC3EventTypes;
readonly details: any;
}

Type representing the format of event objects that may be received via the FDC3 API's addEventListener function.

Events will always include both type and details properties, which describe the type of the event and any additional details respectively.

See also:

FDC3ChannelChangedEvent

interface FDC3ChannelChangedEvent extends FDC3Event {
readonly type: "userChannelChanged";
readonly details: {
currentChannelId: string | null
};
}

Type representing the format of userChannelChanged events.

The identity of the channel joined is provided as details.currentChannelId, which will be null if the app is no longer joined to any channel.

Desktop Agents MUST emit this event after applying a User channel membership change when the app has registered a matching event listener. When the app initiated the change by calling joinUserChannel, the event MUST be dispatched before the returned promise resolves.

FDC3ContextClearedEvent

export interface FDC3ContextClearedEvent extends FDC3Event {
readonly type: 'contextCleared';
readonly details: {
channelId: string;
contextType: string | null;
};
}

Type representing the format of contextCleared events.

The channel on which context was cleared is identified by details.channelId. This field is included for events received through both DesktopAgent.addEventListener and Channel.addEventListener, allowing the same event handler to be used with either API.

The specific type of context is defined in details.contextType, which will be null if all contexts on the channel were cleared.

PrivateChannelEventTypes

type PrivateChannelEventTypes = ChannelEventTypes | "addContextListener" | "unsubscribe" | "disconnect";

Type defining valid type strings for Private Channel events. Private Channels support the contextCleared event defined by ChannelEventTypes, in addition to their lifecycle events.

See also:

PrivateChannelEvent

interface PrivateChannelEvent extends ApiEvent {
readonly type: PrivateChannelEventTypes;
readonly details: any;
}

Type defining the format of event objects that may be received via a PrivateChannel's addEventListener function.

All PrivateChannel events identify the channel to which they relate through details.channelId. The corresponding DACP event payloads use the field name privateChannelId; Desktop Agent API implementations expose that value as channelId for consistency with other channel-related events.

See also:

PrivateChannelAddContextListenerEvent

interface PrivateChannelAddContextListenerEvent extends PrivateChannelEvent {
readonly type: "addContextListener";
readonly details: {
channelId: string;
contextType: string | null
};
}

Type defining the format of events representing a context listener being added to the channel (addContextListener). Desktop Agents MUST fire this event for each invocation of addContextListener on the channel, including those that occurred before this handler was registered (to prevent race conditions).

The channel is identified by details.channelId. The context type of the listener added is provided as details.contextType, which will be null if all event types are being listened to.

PrivateChannelUnsubscribeEvent

interface PrivateChannelUnsubscribeEvent extends PrivateChannelEvent {
readonly type: "unsubscribe";
readonly details: {
channelId: string;
contextType: string | null
};
}

Type defining the format of events representing a context listener removed from the channel (Listener.unsubscribe()). Desktop Agents MUST call this when disconnect() is called by the other party, for each listener that they had added.

The channel is identified by details.channelId. The context type of the listener removed is provided as details.contextType, which will be null if all event types were being listened to.

PrivateChannelDisconnectEvent

export interface PrivateChannelDisconnectEvent extends PrivateChannelEvent {
readonly type: "disconnect";
readonly details: {
channelId: string;
};
}

Type defining the format of events representing a remote app being terminated or otherwise disconnecting from the PrivateChannel. This event is fired in addition to unsubscribe events that will also be fired for any context listeners the disconnecting app had added. The channel is identified by details.channelId.