|
2 | 2 | title: Events |
3 | 3 | --- |
4 | 4 |
|
5 | | -In addition to intent and context events, the FDC3 API may be used to listen for other types of events via the `addEventListener()` function. |
| 5 | +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. |
| 6 | + |
| 7 | +## `ApiEvent` |
| 8 | + |
| 9 | +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. |
| 10 | + |
| 11 | +```ts |
| 12 | +interface ApiEvent { |
| 13 | + readonly type: string; |
| 14 | + readonly details: any; |
| 15 | +} |
| 16 | +``` |
| 17 | + |
| 18 | +**See also:** |
| 19 | + |
| 20 | +- [`FDC3Event`](#fdc3event) |
| 21 | +- [`PrivateChannelEvent`](#privatechannelevent) |
6 | 22 |
|
7 | 23 | ## `EventHandler` |
8 | 24 |
|
9 | 25 | ```ts |
10 | | -type EventHandler = (event: FDC3Event) => void; |
| 26 | +type EventHandler = (event: ApiEvent) => void; |
11 | 27 | ``` |
12 | 28 |
|
13 | | -Describes a callback that handles non-context and non-intent events. Provides the details of the event. |
| 29 | +Describes a callback that handles non-context and non-intent events. Provides the details of the event. |
14 | 30 |
|
15 | | -Used when attaching listeners to events. |
| 31 | +Used when attaching listeners to events. |
16 | 32 |
|
17 | 33 | **See also:** |
18 | | -- [`DesktopAgent.addEventListener`](DesktopAgent#addEventListener) |
19 | | -- [`FDC3Event`](#fdc3event) |
20 | 34 |
|
21 | | -## `FDC3EventType` |
| 35 | +- [`DesktopAgent.addEventListener`](DesktopAgent#addeventlistener) |
| 36 | +- [`PrivateChannel.addEventListener`](PrivateChannel#addeventlistener) |
| 37 | +- [`ApiEvent`](#apievent) |
| 38 | + |
| 39 | +## `FDC3EventTypes` |
| 40 | + |
22 | 41 | ```ts |
23 | | -enum FDC3EventType { |
24 | | - USER_CHANNEL_CHANGED = "USER_CHANNEL_CHANGED" |
25 | | -} |
| 42 | +type FDC3EventTypes = "userChannelChanged"; |
26 | 43 | ``` |
27 | 44 |
|
28 | | -Enumeration defining the types of (non-context and non-intent) events that may be received via the FDC3 API's `addEventListener` function. |
| 45 | +Type defining valid type strings for DesktopAgent interface events. |
29 | 46 |
|
30 | 47 | **See also:** |
31 | | -- [`DesktopAgent.addEventListener`](DesktopAgent#addEventListener) |
| 48 | + |
| 49 | +- [`DesktopAgent.addEventListener`](DesktopAgent#addeventlistener) |
32 | 50 |
|
33 | 51 | ## `FDC3Event` |
34 | 52 |
|
35 | 53 | ```ts |
36 | | -interface FDC3Event { |
37 | | - readonly type: FDC3EventType; |
| 54 | +interface FDC3Event extends ApiEvent{ |
| 55 | + readonly type: FDC3EventTypes; |
38 | 56 | readonly details: any; |
39 | 57 | } |
40 | 58 | ``` |
41 | 59 |
|
42 | | -Type representing the format of event objects that may be received via the FDC3 API's `addEventListener` function. Will always include both `type` and `details`, which describe type of the event and any additional details respectively. |
| 60 | +Type representing the format of event objects that may be received via the FDC3 API's `addEventListener` function. |
| 61 | + |
| 62 | +Events will always include both `type` and `details` properties, which describe the type of the event and any additional details respectively. |
43 | 63 |
|
44 | 64 | **See also:** |
45 | | -- [`DesktopAgent.addEventListener`](DesktopAgent#addEventListener) |
46 | | -- [`FDC3EventType`](#fdc3eventtype) |
47 | 65 |
|
| 66 | +- [`DesktopAgent.addEventListener`](DesktopAgent#addeventlistener) |
| 67 | +- [`FDC3EventTypes`](#fdc3eventtypes) |
48 | 68 |
|
49 | 69 | ### `FDC3ChannelChangedEvent` |
| 70 | + |
50 | 71 | ```ts |
51 | 72 | interface FDC3ChannelChangedEvent extends FDC3Event { |
52 | | - readonly type: FDC3EventType.USER_CHANNEL_CHANGED; |
| 73 | + readonly type: "userChannelChanged"; |
53 | 74 | readonly details: { |
54 | 75 | currentChannelId: string | null |
55 | 76 | }; |
56 | 77 | } |
57 | 78 | ``` |
58 | 79 |
|
59 | | -Type representing the format of USER_CHANNEL_CHANGED 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. |
| 80 | +Type representing the format of `userChannelChanged` events. |
| 81 | + |
| 82 | +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. |
| 83 | + |
| 84 | +## `PrivateChannelEventTypes` |
| 85 | + |
| 86 | +```ts |
| 87 | +type PrivateChannelEventTypes = "addContextListener" | "unsubscribe" | "disconnect"; |
| 88 | +``` |
| 89 | + |
| 90 | +Type defining valid type strings for Private Channel events. |
| 91 | + |
| 92 | +**See also:** |
| 93 | + |
| 94 | +- [`PrivateChannel.addEventListener`](PrivateChannel#addeventlistener) |
| 95 | + |
| 96 | +## `PrivateChannelEvent` |
| 97 | + |
| 98 | +```ts |
| 99 | +interface PrivateChannelEvent extends ApiEvent { |
| 100 | + readonly type: PrivateChannelEventTypes; |
| 101 | + readonly details: any; |
| 102 | +} |
| 103 | +``` |
| 104 | + |
| 105 | +Type defining the format of event objects that may be received via a PrivateChannel's `addEventListener` function. |
| 106 | + |
| 107 | +**See also:** |
| 108 | + |
| 109 | +- [`PrivateChannel.addEventListener`](PrivateChannel#addeventlistener) |
| 110 | +- [`PrivateChannelEventTypes`](#privatechanneleventtypes) |
| 111 | + |
| 112 | +### `PrivateChannelAddContextListenerEvent` |
| 113 | + |
| 114 | +```ts |
| 115 | +interface PrivateChannelAddContextListenerEvent extends PrivateChannelEvent { |
| 116 | + readonly type: "addContextListener"; |
| 117 | + readonly details: { |
| 118 | + contextType: string | null |
| 119 | + }; |
| 120 | +} |
| 121 | +``` |
| 122 | + |
| 123 | +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). |
| 124 | + |
| 125 | +The context type of the listener added is provided as `details.contextType`, which will be `null` if all event types are being listened to. |
| 126 | + |
| 127 | +### `PrivateChannelUnsubscribeEvent` |
| 128 | + |
| 129 | +```ts |
| 130 | +interface PrivateChannelUnsubscribeEvent extends PrivateChannelEvent { |
| 131 | + readonly type: "unsubscribe"; |
| 132 | + readonly details: { |
| 133 | + contextType: string | null |
| 134 | + }; |
| 135 | +} |
| 136 | +``` |
| 137 | + |
| 138 | +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. |
| 139 | + |
| 140 | +The context type of the listener removed is provided as `details.contextType`, which will be `null` if all event types were being listened to. |
| 141 | + |
| 142 | +### `PrivateChannelDisconnectEvent` |
| 143 | + |
| 144 | +```ts |
| 145 | +export interface PrivateChannelDisconnectEvent extends PrivateChannelEvent { |
| 146 | + readonly type: "disconnect"; |
| 147 | + readonly details: null | undefined; |
| 148 | +} |
| 149 | +``` |
| 150 | + |
| 151 | +Type defining the format of events representing a remote app being terminated or is 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. |
| 152 | + |
| 153 | +No details are provided. |
0 commit comments