Skip to content

Commit c3f52ea

Browse files
authored
Merge pull request #1305 from finos/async-listener-and-PrivateChannel-events
Async listener and private channel events
2 parents af0268d + 2ed30e6 commit c3f52ea

12 files changed

Lines changed: 409 additions & 149 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1010

1111
* Added clarification that `id` field values SHOULD always be strings to context schema definition (a restriction that can't easily be represented in the generated types). ([#1149](https://github.com/finos/FDC3/pull/1149))
1212
* Added requirement that Standard versions SHOULD avoid the use unions in context and API definitions wherever possible as these can be hard to replicate and MUST avoid unions of primitive types as these can be impossible to replicate in other languages. ([#120](https://github.com/finos/FDC3/pull/1200))
13-
* Added reference materials and supported platforms information for FDC3 in .NET via the [finos/fdc3-dotnet](https://github.com/finos/fdc3-dotnet) project. ([#1108](https://github.com/finos/FDC3/pull/1108))
13+
* Added `addEventListener` to the `DesktopAgent` API to provide support for event listener for non-context and non-intent events, including a `userChannelChanged` event ([#1207](https://github.com/finos/FDC3/pull/1207))
14+
* Added an `async` `addEventListener` function to the `PrivateChannel` API to replace the deprecated, synchronous `onAddContextListener`, `onUnsubscribe` and `onDisconnect` functions and to keep consistency with the DesktopAgent API. ([#1305](https://github.com/finos/FDC3/pull/1305))
1415

1516
### Changed
1617

18+
* `Listener.unsubscribe()` was made async (the return type was changed from `void` to `Promise<void>`) for consistency with the rest of the API. ([#1305](https://github.com/finos/FDC3/pull/1305))
19+
* Added reference materials and supported platforms information for FDC3 in .NET via the [finos/fdc3-dotnet](https://github.com/finos/fdc3-dotnet) project. ([#1108](https://github.com/finos/FDC3/pull/1108))
1720
* The supported platforms page in the FDC3 documentation was moved into the API section as the information it provides all relates to FDC3 Desktop Agent API implementations. ([#1108](https://github.com/finos/FDC3/pull/1108))
1821

1922
### Deprecated
2023

2124
* Made `IntentMetadata.displayName` optional as it is deprecated. ([#1280](https://github.com/finos/FDC3/pull/1280))
25+
* Deprecated `PrivateChannel`'s synchronous `onAddContextListener`, `onUnsubscribe` and `onDisconnect` functions in favour of an `async` `addEventListener` function consistent with the one added to `DesktopAgent` in #1207. ([#1305](https://github.com/finos/FDC3/pull/1305))
2226

2327
### Fixed
2428

docs/api/ref/DesktopAgent.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ interface DesktopAgent {
4848
leaveCurrentChannel() : Promise<void>;
4949

5050
// non-context events
51-
addEventListener(type: FDC3EventType | null, handler: EventHandler): Promise<Listener>;
51+
addEventListener(type: FDC3EventTypes | null, handler: EventHandler): Promise<Listener>;
5252

5353
//implementation info
5454
getInfo(): Promise<ImplementationMetadata>;
@@ -183,7 +183,7 @@ var contactListener = await _desktopAgent.AddContextListener<Contact>("fdc3.cont
183183
<TabItem value="ts" label="TypeScript/JavaScript">
184184
185185
```ts
186-
addEventListener(type: FDC3EventType | null, handler: EventHandler): Promise<Listener>;
186+
addEventListener(type: FDC3EventTypes | null, handler: EventHandler): Promise<Listener>;
187187
```
188188
189189
</TabItem>
@@ -210,12 +210,11 @@ Whenever the handler function is called it will be passed an event object with d
210210
const listener = await fdc3.addEventListener(null, event => { ... });
211211
212212
// listener for a specific event type that logs its details
213-
const userChannelChangedListener = await fdc3.addEventListener(FDC3EventType.USER_CHANNEL_CHANGED, event => {
213+
const userChannelChangedListener = await fdc3.addEventListener("userChannelChanged ", event => {
214214
console.log(`Received event ${event.type}\n\tDetails: ${event.details}`);
215215
//do something else with the event
216216
});
217217
```
218-
219218
</TabItem>
220219
<TabItem value="dotnet" label=".NET">
221220
@@ -226,6 +225,12 @@ Not implemented
226225
</TabItem>
227226
</Tabs>
228227
228+
**See also:**
229+
230+
- [`FDC3EventTypes`](./Events#fdc3eventtypes)
231+
- [`FDC3Event`](./Events#fdc3event)
232+
- [`EventHandler`](./Events#eventhandler)
233+
229234
### `addIntentListener`
230235
231236
<Tabs groupId="lang">

docs/api/ref/Events.md

Lines changed: 113 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,152 @@
22
title: Events
33
---
44

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)
622

723
## `EventHandler`
824

925
```ts
10-
type EventHandler = (event: FDC3Event) => void;
26+
type EventHandler = (event: ApiEvent) => void;
1127
```
1228

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.
1430

15-
Used when attaching listeners to events.
31+
Used when attaching listeners to events.
1632

1733
**See also:**
18-
- [`DesktopAgent.addEventListener`](DesktopAgent#addEventListener)
19-
- [`FDC3Event`](#fdc3event)
2034

21-
## `FDC3EventType`
35+
- [`DesktopAgent.addEventListener`](DesktopAgent#addeventlistener)
36+
- [`PrivateChannel.addEventListener`](PrivateChannel#addeventlistener)
37+
- [`ApiEvent`](#apievent)
38+
39+
## `FDC3EventTypes`
40+
2241
```ts
23-
enum FDC3EventType {
24-
USER_CHANNEL_CHANGED = "USER_CHANNEL_CHANGED"
25-
}
42+
type FDC3EventTypes = "userChannelChanged";
2643
```
2744

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.
2946

3047
**See also:**
31-
- [`DesktopAgent.addEventListener`](DesktopAgent#addEventListener)
48+
49+
- [`DesktopAgent.addEventListener`](DesktopAgent#addeventlistener)
3250

3351
## `FDC3Event`
3452

3553
```ts
36-
interface FDC3Event {
37-
readonly type: FDC3EventType;
54+
interface FDC3Event extends ApiEvent{
55+
readonly type: FDC3EventTypes;
3856
readonly details: any;
3957
}
4058
```
4159

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.
4363

4464
**See also:**
45-
- [`DesktopAgent.addEventListener`](DesktopAgent#addEventListener)
46-
- [`FDC3EventType`](#fdc3eventtype)
4765

66+
- [`DesktopAgent.addEventListener`](DesktopAgent#addeventlistener)
67+
- [`FDC3EventTypes`](#fdc3eventtypes)
4868

4969
### `FDC3ChannelChangedEvent`
70+
5071
```ts
5172
interface FDC3ChannelChangedEvent extends FDC3Event {
52-
readonly type: FDC3EventType.USER_CHANNEL_CHANGED;
73+
readonly type: "userChannelChanged";
5374
readonly details: {
5475
currentChannelId: string | null
5576
};
5677
}
5778
```
5879

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

Comments
 (0)