Skip to content

Commit 57602f5

Browse files
authored
Merge pull request #1441 from kemerava/feature/dot-net-events
Adding .NET docs for Events to API reference
2 parents 97f9809 + 406db09 commit 57602f5

4 files changed

Lines changed: 223 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
2727
* Added testing policy to [Contributing](CONTRIBUTING) page to address ([810](https://github.com/finos/FDC3/issues/810))
2828
* Added the ability to control logging to the JS console from getAgent() and the DesktopAgentProxy via arguments to getAgent(). ([#1495](https://github.com/finos/FDC3/pull/1495))
2929
* Added the ability for a browser-based DesktopAgent to control the timeouts used in the DesktopAgentProxy when making calls to it, via properties in WCP3Handshake message. ([#1497](https://github.com/finos/FDC3/pull/1497))
30-
30+
* Added .NET docs for Events to API reference. ([#1441](https://github.com/finos/FDC3/pull/1441))
3131

3232
### Changed
3333

@@ -112,7 +112,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
112112
* Further clarified the difference between the behavior of User channels and other channel types on joinUserChannel/addContextListener. ([#971](https://github.com/finos/FDC3/pull/971))
113113
* Clarified description of the behavior of `IntentResolution.getResult()` when the intent handler returned void (which is not an error). ([#1004](https://github.com/finos/FDC3/pull/1004))
114114
* An error was fixed in the appD schema where launch details sub-schemas were combined with `oneOf`, rather than `anyOf`. This causes validation errors for web or online native apps as their details elements overlap on a `url` field. ([#1034](https://github.com/finos/FDC3/pull/1034))
115-
* The appD `icon` and `screenshot` sub-schemas were updated to require the `src` value is set and restrict additional values, ensuring that common mistakes (such as using a `url` rather than `src` field are caught by the schemas when used to validate. ([#1037](https://github.com/finos/FDC3/pull/1037))
115+
* The appD `icon` and `screenshot` sub-schemas were updated to require the `src` value is set and restrict additional values, ensuring that common mistakes (such as using a `url` rather than `src` field are caught by the schemas when used to validate). ([#1037](https://github.com/finos/FDC3/pull/1037))
116116
* Linting, spell checking other corrections were applied to markdown syntax throughout the FDC3 documentation ([#1032](https://github.com/finos/FDC3/pull/1032))
117117
* Corrected bad example URLs in the App Directory overview/discovery page in the current and past versions as they did not agree with the paths provided in the API specification and OpenAPI schema. ([#1060](https://github.com/finos/FDC3/pull/1060))
118118

website/docs/api/ref/DesktopAgent.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ interface IDesktopAgent
9090
Task<IPrivateChannel> CreatePrivateChannel();
9191
Task<IEnumerable<IChannel>> GetUserChannels();
9292

93+
// non-context events
94+
Task<IListener> AddEventListener(string? eventType, Fdc3EventHandler handler);
95+
9396
// OPTIONAL channel management functions
9497
Task JoinUserChannel(string channelId);
9598
Task<IChannel?> GetCurrentChannel();
@@ -189,8 +192,8 @@ addEventListener(type: FDC3EventTypes | null, handler: EventHandler): Promise<L
189192
</TabItem>
190193
<TabItem value="dotnet" label=".NET">
191194
192-
```
193-
Not implemented
195+
```csharp
196+
Task<IListener> AddEventListener(string? eventType, Fdc3EventHandler handler);
194197
```
195198
196199
</TabItem>
@@ -210,16 +213,20 @@ Whenever the handler function is called it will be passed an event object with d
210213
const listener = await fdc3.addEventListener(null, event => { ... });
211214
212215
// listener for a specific event type that logs its details
213-
const userChannelChangedListener = await fdc3.addEventListener("userChannelChanged ", event => {
216+
const userChannelChangedListener = await fdc3.addEventListener("userChannelChanged", event => {
214217
console.log(`Received event ${event.type}\n\tDetails: ${event.details}`);
215218
//do something else with the event
216219
});
217220
```
218221
</TabItem>
219222
<TabItem value="dotnet" label=".NET">
220223
221-
```
222-
Not implemented
224+
```csharp
225+
var listener = await _desktopAgent.AddEventListener(null, (event) => { ... });
226+
227+
var userChannelChangedListener = await _desktopAgent.AddEventListener("userChannelChanged", (event) => {
228+
System.Diagnostics.Debug.Write($"Received event ${event.Type}\n\tDetails: ${event.Details}");
229+
});
223230
```
224231
225232
</TabItem>

website/docs/api/ref/Events.md

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,34 @@
22
title: Events
33
---
44

5+
import Tabs from '@theme/Tabs';
6+
import TabItem from '@theme/TabItem';
7+
58
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.
69

710
## `ApiEvent`
811

912
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.
1013

14+
15+
<Tabs groupId="lang">
16+
<TabItem value="ts" label="TypeScript/JavaScript">
17+
1118
```ts
1219
interface ApiEvent {
1320
readonly type: string;
1421
readonly details: any;
1522
}
1623
```
24+
</TabItem>
25+
<TabItem value="dotnet" label=".NET">
26+
27+
```
28+
Not implemented, as ApiEvent and Fdc3Event definitions are the same, given .NET can not restrict on a string enum. Use IFdc3Event instead
29+
```
30+
31+
</TabItem>
32+
</Tabs>
1733

1834
**See also:**
1935

@@ -22,9 +38,21 @@ interface ApiEvent {
2238

2339
## `EventHandler`
2440

41+
<Tabs groupId="lang">
42+
<TabItem value="ts" label="TypeScript/JavaScript">
43+
2544
```ts
2645
type EventHandler = (event: ApiEvent) => void;
2746
```
47+
</TabItem>
48+
<TabItem value="dotnet" label=".NET">
49+
50+
```csharp
51+
public delegate void Fdc3EventHandler(IFdc3Event fdc3Event);
52+
```
53+
54+
</TabItem>
55+
</Tabs>
2856

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

@@ -38,9 +66,24 @@ Used when attaching listeners to events.
3866

3967
## `FDC3EventTypes`
4068

69+
<Tabs groupId="lang">
70+
<TabItem value="ts" label="TypeScript/JavaScript">
71+
4172
```ts
4273
type FDC3EventTypes = "userChannelChanged";
4374
```
75+
</TabItem>
76+
<TabItem value="dotnet" label=".NET">
77+
78+
```csharp
79+
public static class Fdc3EventType
80+
{
81+
public const string UserChannelChanged = "userChannelChanged";
82+
}
83+
```
84+
85+
</TabItem>
86+
</Tabs>
4487

4588
Type defining valid type strings for DesktopAgent interface events.
4689

@@ -50,12 +93,40 @@ Type defining valid type strings for DesktopAgent interface events.
5093

5194
## `FDC3Event`
5295

96+
<Tabs groupId="lang">
97+
<TabItem value="ts" label="TypeScript/JavaScript">
98+
5399
```ts
54100
interface FDC3Event extends ApiEvent{
55101
readonly type: FDC3EventTypes;
56102
readonly details: any;
57103
}
58104
```
105+
</TabItem>
106+
<TabItem value="dotnet" label=".NET">
107+
108+
```csharp
109+
public interface IFdc3Event
110+
{
111+
public string Type { get; }
112+
public object? Details { get; }
113+
}
114+
115+
public class Fdc3Event : IFdc3Event
116+
{
117+
public string Type { get; }
118+
public object? Details { get; }
119+
120+
public Fdc3Event(string type, object? details = null)
121+
{
122+
this.Type = type ?? throw new ArgumentNullException(nameof(type));
123+
this.Details = details;
124+
}
125+
}
126+
```
127+
128+
</TabItem>
129+
</Tabs>
59130

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

@@ -68,6 +139,9 @@ Events will always include both `type` and `details` properties, which describe
68139

69140
### `FDC3ChannelChangedEvent`
70141

142+
<Tabs groupId="lang">
143+
<TabItem value="ts" label="TypeScript/JavaScript">
144+
71145
```ts
72146
interface FDC3ChannelChangedEvent extends FDC3Event {
73147
readonly type: "userChannelChanged";
@@ -76,16 +150,63 @@ interface FDC3ChannelChangedEvent extends FDC3Event {
76150
};
77151
}
78152
```
153+
</TabItem>
154+
<TabItem value="dotnet" label=".NET">
155+
156+
```csharp
157+
public interface IFdc3ChannelChangedEventDetails
158+
{
159+
string? CurrentChannelId { get; }
160+
}
161+
public class Fdc3ChannelChangedEventDetails : IFdc3ChannelChangedEventDetails
162+
{
163+
public string? CurrentChannelId { get; }
164+
165+
public Fdc3ChannelChangedEventDetails(string? channelId)
166+
{
167+
this.CurrentChannelId = channelId;
168+
}
169+
}
170+
171+
public class Fdc3ChannelChangedEvent : Fdc3Event
172+
{
173+
public Fdc3ChannelChangedEvent(string? channelId)
174+
: base(Fdc3EventType.UserChannelChanged, new Fdc3ChannelChangedEventDetails(channelId))
175+
{
176+
}
177+
}
178+
```
179+
180+
</TabItem>
181+
</Tabs>
182+
79183

80184
Type representing the format of `userChannelChanged` events.
81185

82186
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.
83187

84188
## `PrivateChannelEventTypes`
85189

190+
<Tabs groupId="lang">
191+
<TabItem value="ts" label="TypeScript/JavaScript">
192+
86193
```ts
87194
type PrivateChannelEventTypes = "addContextListener" | "unsubscribe" | "disconnect";
88195
```
196+
</TabItem>
197+
<TabItem value="dotnet" label=".NET">
198+
199+
```csharp
200+
public static class Fdc3PrivateChannelEventType
201+
{
202+
public const string AddContextListener = "addContextListener";
203+
public const string Unsubscribe = "unsubscribe";
204+
public const string Disconnect = "disconnect";
205+
}
206+
```
207+
208+
</TabItem>
209+
</Tabs>
89210

90211
Type defining valid type strings for Private Channel events.
91212

@@ -95,12 +216,37 @@ Type defining valid type strings for Private Channel events.
95216

96217
## `PrivateChannelEvent`
97218

219+
<Tabs groupId="lang">
220+
<TabItem value="ts" label="TypeScript/JavaScript">
221+
98222
```ts
99223
interface PrivateChannelEvent extends ApiEvent {
100224
readonly type: PrivateChannelEventTypes;
101225
readonly details: any;
102226
}
103227
```
228+
</TabItem>
229+
<TabItem value="dotnet" label=".NET">
230+
231+
```csharp
232+
public interface IFdc3PrivateChannelEventDetails
233+
{
234+
string? ContextType { get; }
235+
}
236+
public class Fdc3PrivateChannelEventDetails : IFdc3PrivateChannelEventDetails
237+
{
238+
public string? ContextType { get; }
239+
240+
public Fdc3PrivateChannelEventDetails(string? contextType)
241+
{
242+
this.ContextType = contextType;
243+
}
244+
}
245+
```
246+
247+
</TabItem>
248+
</Tabs>
249+
104250

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

@@ -111,6 +257,9 @@ Type defining the format of event objects that may be received via a PrivateChan
111257

112258
### `PrivateChannelAddContextListenerEvent`
113259

260+
<Tabs groupId="lang">
261+
<TabItem value="ts" label="TypeScript/JavaScript">
262+
114263
```ts
115264
interface PrivateChannelAddContextListenerEvent extends PrivateChannelEvent {
116265
readonly type: "addContextListener";
@@ -119,13 +268,31 @@ interface PrivateChannelAddContextListenerEvent extends PrivateChannelEvent {
119268
};
120269
}
121270
```
271+
</TabItem>
272+
<TabItem value="dotnet" label=".NET">
273+
274+
```csharp
275+
public class Fdc3PrivateChannelAddContextListenerEvent : Fdc3Event
276+
{
277+
public Fdc3PrivateChannelAddContextListenerEvent(string? contextType)
278+
: base(Fdc3PrivateChannelEventType.AddContextListener, new Fdc3PrivateChannelEventDetails(contextType))
279+
{
280+
}
281+
}
282+
```
283+
284+
</TabItem>
285+
</Tabs>
122286

123287
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).
124288

125289
The context type of the listener added is provided as `details.contextType`, which will be `null` if all event types are being listened to.
126290

127291
### `PrivateChannelUnsubscribeEvent`
128292

293+
<Tabs groupId="lang">
294+
<TabItem value="ts" label="TypeScript/JavaScript">
295+
129296
```ts
130297
interface PrivateChannelUnsubscribeEvent extends PrivateChannelEvent {
131298
readonly type: "unsubscribe";
@@ -134,19 +301,52 @@ interface PrivateChannelUnsubscribeEvent extends PrivateChannelEvent {
134301
};
135302
}
136303
```
304+
</TabItem>
305+
<TabItem value="dotnet" label=".NET">
306+
307+
```csharp
308+
public class Fdc3PrivateChannelUnsubscribeListenerEvent : Fdc3Event
309+
{
310+
public Fdc3PrivateChannelUnsubscribeListenerEvent(string? contextType)
311+
: base(Fdc3PrivateChannelEventType.Unsubscribe, new Fdc3PrivateChannelEventDetails(contextType))
312+
{
313+
}
314+
}
315+
```
316+
317+
</TabItem>
318+
</Tabs>
137319

138320
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.
139321

140322
The context type of the listener removed is provided as `details.contextType`, which will be `null` if all event types were being listened to.
141323

142324
### `PrivateChannelDisconnectEvent`
143325

326+
<Tabs groupId="lang">
327+
<TabItem value="ts" label="TypeScript/JavaScript">
328+
144329
```ts
145330
export interface PrivateChannelDisconnectEvent extends PrivateChannelEvent {
146331
readonly type: "disconnect";
147332
readonly details: null | undefined;
148333
}
149334
```
335+
</TabItem>
336+
<TabItem value="dotnet" label=".NET">
337+
338+
```csharp
339+
public class Fdc3PrivateChanneDisconnectEvent : Fdc3Event
340+
{
341+
public Fdc3PrivateChanneDisconnectEvent()
342+
: base(Fdc3PrivateChannelEventType.Disconnect)
343+
{
344+
}
345+
}
346+
```
347+
348+
</TabItem>
349+
</Tabs>
150350

151351
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.
152352

0 commit comments

Comments
 (0)