Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
* Setup package publishing for mono-repo packages. ([#1520](https://github.com/finos/FDC3/pull/1520))
* Implementation PR for FDC3 for the Web ([#896](https://github.com/finos/FDC3/pull/896))
* 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))
* Added `addIntentWithContextListener` to `DesktopAgent` and implemented in `DesktopAgentProxy`

### Changed

Expand Down
5 changes: 5 additions & 0 deletions packages/fdc3-agent-proxy/src/DesktopAgentProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class DesktopAgentProxy implements DesktopAgent, Connectable {
this.findIntentsByContext = this.findIntentsByContext.bind(this);
this.raiseIntent = this.raiseIntent.bind(this);
this.addIntentListener = this.addIntentListener.bind(this);
this.addIntentListenerWithContext = this.addIntentListenerWithContext.bind(this);
this.raiseIntentForContext = this.raiseIntentForContext.bind(this);
this.open = this.open.bind(this);
this.findInstances = this.findInstances.bind(this);
Expand Down Expand Up @@ -183,6 +184,10 @@ export class DesktopAgentProxy implements DesktopAgent, Connectable {
return this.intents.addIntentListener(intent, handler);
}

addIntentListenerWithContext(intent: string, contextType: string | string[], handler: IntentHandler) {
return this.intents.addIntentListenerWithContext(intent, contextType, handler);
}

raiseIntentForContext(context: Context, app?: string | AppIdentifier): Promise<IntentResolution> {
return this.intents.raiseIntentForContext(context, this.ensureAppId(app));
}
Expand Down
18 changes: 17 additions & 1 deletion packages/fdc3-agent-proxy/src/intents/DefaultIntentSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,23 @@ export class DefaultIntentSupport implements IntentSupport {
}

async addIntentListener(intent: string, handler: IntentHandler): Promise<Listener> {
const out = new DefaultIntentListener(this.messaging, intent, handler, this.messageExchangeTimeout);
const out = new DefaultIntentListener(this.messaging, intent, null, handler, this.messageExchangeTimeout);
await out.register();
return out;
}

async addIntentListenerWithContext(
intent: string,
contextType: string | string[],
handler: IntentHandler
): Promise<Listener> {
const out = new DefaultIntentListener(
this.messaging,
intent,
Array.isArray(contextType) ? contextType : [contextType],
handler,
this.messageExchangeTimeout
);
await out.register();
return out;
}
Expand Down
5 changes: 5 additions & 0 deletions packages/fdc3-agent-proxy/src/intents/IntentSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ export interface IntentSupport {
raiseIntent(intent: string, context: Context, app?: AppIdentifier): Promise<IntentResolution>;
raiseIntentForContext(context: Context, app?: AppIdentifier): Promise<IntentResolution>;
addIntentListener(intent: string, handler: IntentHandler): Promise<Listener>;
addIntentListenerWithContext(
intent: string,
contextType: string | string[],
handler: IntentHandler
): Promise<Listener>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import {
IntentEvent,
IntentResultRequest,
IntentResultResponse,
//RaiseIntentResponse,
} from '@finos/fdc3-schema/dist/generated/api/BrowserTypes';

export class DefaultIntentListener extends AbstractListener<IntentHandler, AddIntentListenerRequest> {
readonly intent: string;

constructor(messaging: Messaging, intent: string, action: IntentHandler, messageExchangeTimeout: number) {
constructor(
messaging: Messaging,
private readonly intent: string,
private readonly context: string[] | null,
action: IntentHandler,
messageExchangeTimeout: number
) {
super(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theres more to think about here: how does the Desktop Agent know what contexts are being listened for (and hence how to filter intent resolution)?
The AbstractListener is what's notifying the Desktop Agent about the new listener and its only being passed the intent ({ intent }). To resolve, add the contexts array on line 23 if not null (I'd omit it otherwise) then update the addIntentListenerRequest schema to support the extra property in the payload. I'd make it optional (don't add to the required array) but don't allow null values (so type is just array).

messaging,
messageExchangeTimeout,
Expand All @@ -24,11 +27,14 @@ export class DefaultIntentListener extends AbstractListener<IntentHandler, AddIn
'intentListenerUnsubscribeRequest',
'intentListenerUnsubscribeResponse'
);
this.intent = intent;
}

filter(m: IntentEvent): boolean {
return m.type == 'intentEvent' && m.payload.intent == this.intent;
return (
m.type == 'intentEvent' &&
m.payload.intent == this.intent &&
(this.context == null || this.context.includes(m.payload.context.type))
);
}

action(m: IntentEvent): void {
Expand Down
10 changes: 10 additions & 0 deletions packages/fdc3-context/generated/context/ContextTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1980,6 +1980,10 @@ export interface Trade {
* A human-readable summary of the trade.
*/
name?: string;
/**
* Additional notes or comments about the trade.
*/
notes?: string;
/**
* A product that is the subject of the trade.
*/
Expand Down Expand Up @@ -2044,6 +2048,10 @@ export interface TradeElement {
* A human-readable summary of the trade.
*/
name?: string;
/**
* Additional notes or comments about the trade.
*/
notes?: string;
/**
* A product that is the subject of the trade.
*/
Expand Down Expand Up @@ -3067,6 +3075,7 @@ const typeMap: any = {
[
{ json: 'id', js: 'id', typ: m('') },
{ json: 'name', js: 'name', typ: u(undefined, '') },
{ json: 'notes', js: 'notes', typ: u(undefined, '') },
{ json: 'product', js: 'product', typ: r('ProductObject') },
{ json: 'type', js: 'type', typ: r('TradeType') },
],
Expand All @@ -3085,6 +3094,7 @@ const typeMap: any = {
[
{ json: 'id', js: 'id', typ: m('') },
{ json: 'name', js: 'name', typ: u(undefined, '') },
{ json: 'notes', js: 'notes', typ: u(undefined, '') },
{ json: 'product', js: 'product', typ: r('ProductObject') },
{ json: 'type', js: 'type', typ: r('TradeType') },
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ Given('A Dummy Desktop Agent in {string}', async function (this: CustomWorld, fi
raiseIntent: notImplemented,
raiseIntentForContext: notImplemented,
addIntentListener: notImplemented,
addIntentListenerWithContext: notImplemented,
addContextListener: notImplemented,
addEventListener: notImplemented,
getUserChannels: notImplemented,
Expand Down
Loading
Loading