Skip to content

Commit

Permalink
Support broadcast in FDC3 Action
Browse files Browse the repository at this point in the history
  • Loading branch information
symphony-jean-michael committed Sep 23, 2024
1 parent e7cefcf commit 311548b
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 2 deletions.
56 changes: 54 additions & 2 deletions docs/context/ref/Action.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ sidebar_label: Action

A representation of an FDC3 Action (specified via a Context or Context & Intent) that can be inserted inside another object, for example a chat message.

The action may be completed by calling `fdc3.raiseIntent()` with the specified Intent and Context, or, if only a context is specified, by calling `fdc3.raiseIntentForContext()` (which the Desktop Agent will resolve by presenting the user with a list of available Intents for the Context).
The action may be completed by calling:
- `fdc3.raiseIntent()` with the specified Intent and Context, or, if only a context is specified, by calling `fdc3.raiseIntentForContext()` (which the Desktop Agent will resolve by presenting the user with a list of available Intents for the Context).
- `channel.broadcast()` with the specified Context, if the `broadcast` action has been defined.

Accepts an optional `app` parameter in order to specify a specific app.

Expand All @@ -22,6 +24,17 @@ Accepts an optional `app` parameter in order to specify a specific app.

## Properties

<details>
<summary><code>action</code></summary>

**type**: `string`

The **action** field indicates the type of action:
- **raiseIntent** : If no action or **raiseIntent** is specified, then the current default behaviour will be used with `fdc3.raiseIntent` / `fdc3.raiseIntentForContext`
- **broadcast** : If **broadcast** action is specified, it will call `fdc3.getOrCreateChannel('Channel 1')`to retrieve the channel, then broadcast the context to that channel with `channel.broadcast(context)`. If no, channel has been specified, it will try to broadcast to the current channel (`fdc3.getCurrentChannel()`)

</details>

<details>
<summary><code>title</code> <strong>(required)</strong></summary>

Expand Down Expand Up @@ -50,17 +63,30 @@ A context object with which the action will be performed

</details>

<details>
<summary><code>channelId</code></summary>

**type**: `string`

Broadcasts a context on this channel, if the `broadcast` action has been defined.
The `channel` property is ignored unless the `action` is broadcast.

</details>

<details>
<summary><code>app</code></summary>

**type**: api/AppIdentifier

An optional target application identifier that should perform the action
An optional target application identifier that should perform the action.
This property is ignored if the `action` is broadcast.

</details>

## Example

RaiseIntent example:

```json
{
"type": "fdc3.action",
Expand Down Expand Up @@ -90,3 +116,29 @@ An optional target application identifier that should perform the action
}
```

Broadcast example:
```json
{
"type": "fdc3.action",
"title": "Click to view Chart",
"action": "broadcast",
"channelId": "Channel 1",
"context": {
"type": "fdc3.chart",
"instruments": [
{
"type": "fdc3.instrument",
"id": {
"ticker": "EURUSD"
}
}
],
"range": {
"type": "fdc3.dateRange",
"starttime": "2020-09-01T08:00:00.000Z",
"endtime": "2020-10-31T08:00:00.000Z"
},
"style": "candle"
}
}
```
38 changes: 38 additions & 0 deletions schemas/context/action.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
"type": "object",
"properties": {
"type": { "const": "fdc3.action" },
"action": {
"title": "Action Type",
"description": "Optional type of action to perform. If action is not set then `raiseIntent` should be used to perform the action.",
"type": "string",
"enum": [
"broadcast",
"raiseIntent"
]
},
"title": {
"title": "Action Title",
"description": "A human readable display name for the action",
Expand All @@ -22,6 +31,11 @@
"description": "A context object with which the action will be performed",
"$ref": "context.schema.json#"
},
"channelId": {
"title": "Channel ID",
"description": "Optional channel on which to broadcast the context",
"type": "string"
},
"app": {
"title": "Action Target App",
"description": "An optional target application identifier that should perform the action",
Expand All @@ -37,6 +51,7 @@
"examples": [
{
"type": "fdc3.action",
"action": "raiseIntent",
"title": "Click to view Chart",
"intent": "ViewChart",
"context": {
Expand All @@ -60,6 +75,29 @@
"appId": "MyChartViewingApp",
"instanceId": "instance1"
}
},
{
"type": "fdc3.action",
"action": "broadcast",
"channelId": "Channel 1",
"title": "Click to view Chart",
"context": {
"type": "fdc3.chart",
"instruments": [
{
"type": "fdc3.instrument",
"id": {
"ticker": "EURUSD"
}
}
],
"range": {
"type": "fdc3.dateRange",
"starttime": "2020-09-01T08:00:00.000Z",
"endtime": "2020-10-31T08:00:00.000Z"
},
"style": "candle"
}
}
]
}
15 changes: 15 additions & 0 deletions src/context/ContextTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,19 @@
* Accepts an optional `app` parameter in order to specify a specific app.
*/
export interface Action {
/**
* Optional type of action to perform. If action is not set then `raiseIntent` should be
* used to perform the action.
*/
action?: ActionType;
/**
* An optional target application identifier that should perform the action
*/
app?: AppIdentifier;
/**
* Optional channel on which to broadcast the context
*/
channelId?: string;
/**
* A context object with which the action will be performed
*/
Expand All @@ -71,6 +80,12 @@ export interface Action {
[property: string]: any;
}

/**
* Optional type of action to perform. If action is not set then `raiseIntent` should be
* used to perform the action.
*/
export type ActionType = "broadcast" | "raiseIntent";

/**
* An optional target application identifier that should perform the action
*
Expand Down

0 comments on commit 311548b

Please sign in to comment.