Skip to content

Commit 6803188

Browse files
committed
implement addIntentWithContextListener
1 parent 63eceaa commit 6803188

File tree

11 files changed

+2454
-2372
lines changed

11 files changed

+2454
-2372
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
4242
* Setup package publishing for mono-repo packages. ([#1520](https://github.com/finos/FDC3/pull/1520))
4343
* Implementation PR for FDC3 for the Web ([#896](https://github.com/finos/FDC3/pull/896))
4444
* Adjusted reference Desktop Agent implementation for FDC3 for Web to open a new app instance when raiseIntent is called with an appId but no instanceId ([#1556](https://github.com/finos/FDC3/pull/1556))
45+
* Added `addIntentWithContextListener` to `DesktopAgent` and implemented in `DesktopAgentProxy`
4546

4647
### Changed
4748

packages/fdc3-agent-proxy/src/DesktopAgentProxy.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export class DesktopAgentProxy implements DesktopAgent, Connectable {
6666
this.findIntentsByContext = this.findIntentsByContext.bind(this);
6767
this.raiseIntent = this.raiseIntent.bind(this);
6868
this.addIntentListener = this.addIntentListener.bind(this);
69+
this.addIntentListenerWithContext = this.addIntentListenerWithContext.bind(this);
6970
this.raiseIntentForContext = this.raiseIntentForContext.bind(this);
7071
this.open = this.open.bind(this);
7172
this.findInstances = this.findInstances.bind(this);
@@ -183,6 +184,10 @@ export class DesktopAgentProxy implements DesktopAgent, Connectable {
183184
return this.intents.addIntentListener(intent, handler);
184185
}
185186

187+
addIntentListenerWithContext(intent: string, contextType: string | string[], handler: IntentHandler) {
188+
return this.intents.addIntentListenerWithContext(intent, contextType, handler);
189+
}
190+
186191
raiseIntentForContext(context: Context, app?: string | AppIdentifier): Promise<IntentResolution> {
187192
return this.intents.raiseIntentForContext(context, this.ensureAppId(app));
188193
}

packages/fdc3-agent-proxy/src/intents/DefaultIntentSupport.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,23 @@ export class DefaultIntentSupport implements IntentSupport {
217217
}
218218

219219
async addIntentListener(intent: string, handler: IntentHandler): Promise<Listener> {
220-
const out = new DefaultIntentListener(this.messaging, intent, handler, this.messageExchangeTimeout);
220+
const out = new DefaultIntentListener(this.messaging, intent, undefined, handler, this.messageExchangeTimeout);
221+
await out.register();
222+
return out;
223+
}
224+
225+
async addIntentListenerWithContext(
226+
intent: string,
227+
contextType: string | string[],
228+
handler: IntentHandler
229+
): Promise<Listener> {
230+
const out = new DefaultIntentListener(
231+
this.messaging,
232+
intent,
233+
Array.isArray(contextType) ? contextType : [contextType],
234+
handler,
235+
this.messageExchangeTimeout
236+
);
221237
await out.register();
222238
return out;
223239
}

packages/fdc3-agent-proxy/src/intents/IntentSupport.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@ export interface IntentSupport {
77
raiseIntent(intent: string, context: Context, app?: AppIdentifier): Promise<IntentResolution>;
88
raiseIntentForContext(context: Context, app?: AppIdentifier): Promise<IntentResolution>;
99
addIntentListener(intent: string, handler: IntentHandler): Promise<Listener>;
10+
addIntentListenerWithContext(
11+
intent: string,
12+
contextType: string | string[],
13+
handler: IntentHandler
14+
): Promise<Listener>;
1015
}

packages/fdc3-agent-proxy/src/listeners/DefaultIntentListener.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,34 @@ import {
77
IntentEvent,
88
IntentResultRequest,
99
IntentResultResponse,
10-
//RaiseIntentResponse,
1110
} from '@finos/fdc3-schema/dist/generated/api/BrowserTypes';
1211

1312
export class DefaultIntentListener extends AbstractListener<IntentHandler, AddIntentListenerRequest> {
14-
readonly intent: string;
15-
16-
constructor(messaging: Messaging, intent: string, action: IntentHandler, messageExchangeTimeout: number) {
13+
constructor(
14+
messaging: Messaging,
15+
private readonly intent: string,
16+
private readonly contextTypes: string[] | undefined,
17+
action: IntentHandler,
18+
messageExchangeTimeout: number
19+
) {
1720
super(
1821
messaging,
1922
messageExchangeTimeout,
20-
{ intent },
23+
{ intent, contextTypes },
2124
action,
2225
'addIntentListenerRequest',
2326
'addIntentListenerResponse',
2427
'intentListenerUnsubscribeRequest',
2528
'intentListenerUnsubscribeResponse'
2629
);
27-
this.intent = intent;
2830
}
2931

3032
filter(m: IntentEvent): boolean {
31-
return m.type == 'intentEvent' && m.payload.intent == this.intent;
33+
return (
34+
m.type == 'intentEvent' &&
35+
m.payload.intent == this.intent &&
36+
(this.contextTypes == null || this.contextTypes.includes(m.payload.context.type))
37+
);
3238
}
3339

3440
action(m: IntentEvent): void {

packages/fdc3-context/generated/context/ContextTypes.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,6 +1980,10 @@ export interface Trade {
19801980
* A human-readable summary of the trade.
19811981
*/
19821982
name?: string;
1983+
/**
1984+
* Additional notes or comments about the trade.
1985+
*/
1986+
notes?: string;
19831987
/**
19841988
* A product that is the subject of the trade.
19851989
*/
@@ -2044,6 +2048,10 @@ export interface TradeElement {
20442048
* A human-readable summary of the trade.
20452049
*/
20462050
name?: string;
2051+
/**
2052+
* Additional notes or comments about the trade.
2053+
*/
2054+
notes?: string;
20472055
/**
20482056
* A product that is the subject of the trade.
20492057
*/
@@ -3067,6 +3075,7 @@ const typeMap: any = {
30673075
[
30683076
{ json: 'id', js: 'id', typ: m('') },
30693077
{ json: 'name', js: 'name', typ: u(undefined, '') },
3078+
{ json: 'notes', js: 'notes', typ: u(undefined, '') },
30703079
{ json: 'product', js: 'product', typ: r('ProductObject') },
30713080
{ json: 'type', js: 'type', typ: r('TradeType') },
30723081
],
@@ -3085,6 +3094,7 @@ const typeMap: any = {
30853094
[
30863095
{ json: 'id', js: 'id', typ: m('') },
30873096
{ json: 'name', js: 'name', typ: u(undefined, '') },
3097+
{ json: 'notes', js: 'notes', typ: u(undefined, '') },
30883098
{ json: 'product', js: 'product', typ: r('ProductObject') },
30893099
{ json: 'type', js: 'type', typ: r('TradeType') },
30903100
],

packages/fdc3-get-agent/test/step-definitions/desktop-agent.steps.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ Given('A Dummy Desktop Agent in {string}', async function (this: CustomWorld, fi
223223
raiseIntent: notImplemented,
224224
raiseIntentForContext: notImplemented,
225225
addIntentListener: notImplemented,
226+
addIntentListenerWithContext: notImplemented,
226227
addContextListener: notImplemented,
227228
addEventListener: notImplemented,
228229
getUserChannels: notImplemented,

0 commit comments

Comments
 (0)