Skip to content

Commit

Permalink
Added support for configuring the interop broker to not send context …
Browse files Browse the repository at this point in the history
…to the sender

Something that has come up is use cases where you have a context listener that never wants any context that has been sent from the same webpage and instance.

There are ways of doing this so you ignore context messages sent from yourself (and we updated the doc for this) but now we also have a configuration option so you can specify that you do not want the originator of a context message to receive it.
  • Loading branch information
johnman committed Jul 12, 2024
1 parent 2012140 commit b237889
Show file tree
Hide file tree
Showing 14 changed files with 1,403 additions and 704 deletions.
1 change: 1 addition & 0 deletions how-to/workspace-platform-starter/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Updated manifests to disable app logging (where console log entries are written to disk). You can still see console log messages in dev tools or you can turn it back on by setting enableAppLogging to true.
- Added new v38 runtime setting appLogsTimezone and set it to utc for when you do capture logs to disk.
- Removed startup_app from manifests as the name setting in platform is sufficient for naming the app folder name when app logging is enabled.
- Added support to the interop broker for preventing context from being sent back to the originator (default behavior). See the [how to add context support to your app](./docs/how-to-add-context-support-to-your-app.md) document and scroll down to the section titled: Should the context object be sent back to the sender?

## v18.0.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ export interface PlatformInteropBrokerOptions extends ModuleList {
*/
openOptions?: OpenOptions;

/**
* Options for when fdc3.broadcast or fin.me.interop.setContext is called.
*/
contextOptions?: ContextOptions;

/**
* If an unregistered app is included here then it indicates you wish to support selecting views/windows that are
* not linked to an app from an intent picker that supports instances. The intents and contexts in this app specify
Expand Down Expand Up @@ -154,6 +159,16 @@ export interface IntentOptions {
intentTimeout?: number;
}

/**
* Option for the Context Handling.
*/
export interface ContextOptions {
/**
* Should the broker send context messages back to the sender? Default is true.
*/
includeOriginator?: boolean;
}

/**
* Intent resolver options.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import type {
IntentTargetMetaData,
ProcessedContext,
PlatformInteropOverrideOptions,
PlatformInteropBrokerHelpers
PlatformInteropBrokerHelpers,
ContextOptions
} from "workspace-platform-starter/shapes/interopbroker-shapes";
import type { Logger } from "workspace-platform-starter/shapes/logger-shapes";
import {
Expand Down Expand Up @@ -94,6 +95,8 @@ export async function getConstructorOverride(

private readonly _appIdHelper: AppIdHelper;

private readonly _contextOptions?: ContextOptions;

/**
* Create a new instance of InteropBroker.
*/
Expand All @@ -112,6 +115,8 @@ export async function getConstructorOverride(

this._openOptions = options?.openOptions;
this._unregisteredApp = options?.unregisteredApp;
this._contextOptions = options?.contextOptions;

if (!isEmpty(this._unregisteredApp)) {
this._unregisteredApp.manifestType = MANIFEST_TYPES.UnregisteredApp.id;
}
Expand Down Expand Up @@ -185,10 +190,16 @@ export async function getConstructorOverride(
context: OpenFin.Context
): Promise<void> {
const passedContext: { [key: string]: unknown } = { ...context };
const contextMetadata = passedContext[this._metadataKey];
const contextMetadata = passedContext[this._metadataKey] as ContextMetadata;
if (!isEmpty(contextMetadata)) {
delete passedContext[this._metadataKey];
}
if (
this._contextOptions?.includeOriginator === false &&
contextMetadata?.source.instanceId === clientIdentity.endpointId
) {
return;
}
return super.invokeContextHandler(clientIdentity, handlerId, {
...passedContext,
contextMetadata
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { OpenFin } from "@openfin/core";
import type { ModuleImplementation, ModuleList } from "./module-shapes";
/**
* InitOptions Provider Options. This is a list of modules that will be loaded and used to handle init params (similar
Expand Down Expand Up @@ -66,6 +67,6 @@ export type InitOptionsActionHandler<T = unknown> = (
* The handler for an init options listener.
*/
export type InitOptionsListener = (
initOptions: UserAppConfigArgs,
initOptions: OpenFin.UserAppConfigArgs,
context: ActionHandlerContext
) => Promise<void>;
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export interface PlatformInteropBrokerOptions extends ModuleList {
* When fdc3.open is used what settings should be applied?
*/
openOptions?: OpenOptions;
/**
* Options for when fdc3.broadcast or fin.me.interop.setContext is called.
*/
contextOptions?: ContextOptions;
/**
* If an unregistered app is included here then it indicates you wish to support selecting views/windows that are
* not linked to an app from an intent picker that supports instances. The intents and contexts in this app specify
Expand Down Expand Up @@ -139,6 +143,15 @@ export interface IntentOptions {
*/
intentTimeout?: number;
}
/**
* Option for the Context Handling.
*/
export interface ContextOptions {
/**
* Should the broker send context messages back to the sender? Default is true.
*/
includeOriginator?: boolean;
}
/**
* Intent resolver options.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,57 @@ If you are a platform owner with a variable number of apps from different conten

We have an example of what this could be like in workspace platform starter. You can define endpoints ([See how to define endpoints](./how-to-define-endpoints.md)) that support a requestResponse function where the context will be passed to the function, enriched and then returned. This could be a single JavaScript module for one or more context types or you might have teams that build and own their own JavaScript module for their specific context types. This will let your platform scale without requiring direct changes to your broker's setContext function.

## Should the context object be sent back to the sender?

By default if you have a user channel context listener (e.g. listening on green) and you also publish a context message via fdc3.broadcast or fin.me.interop.setContext then the listener will receive the message you sent.

### Checking to see if you are the originator of the context message

Workspace Platform Starter supports the fdc3 preference of including app metadata alongside the context. You can check to see if you are the sender through a snippet like this:

```javascript
// get the app Id and instance Id of the current webpage
const info = await fdc3.getInfo();
const appMetadata = info.appMetadata;
console.log(
`I am associated with appId: ${appMetadata.appId} and this specific instance of this app has the following instanceId: ${appMetadata.instanceId}`
);

// ... other logic followed by your contextListener
// --------------------------------
// Listening code
// --------------------------------
const userChannelHandler = (ctx, metadata) => {
if (
metadata !== undefined &&
metadata.source.appId === appMetadata.appId &&
metadata.source.instanceId === appMetadata.instanceId
) {
console.log('We are not going to do anything with this context object as it came from ourselves');
} else {
console.log('User Context Received: ', ctx);
}
};

const userChannelListener = fdc3.addContextListener(null, userChannelHandler);
```

### Configure your interop broker to not pass context messages to the originator

From workspace platform starter v19.0 we have added a new configuration option to the interop section of the platformProvider settings called contextOptions. ContextOptions has a setting called **includeOriginator**. By default this is true but if you set it to false it won't pass context to the source of the sent context.

```json
"platformProvider": {
...
"interop": {
...
"contextOptions": {
"includeOriginator": false
}
}
}
```

## Test Harnesses

It is useful to be able to test your app against something. When you reference the common apps feed in your instance of workspace platform starter you get a number of useful utilities. We provide two entries related to context sharing in FDC3:
Expand Down
1 change: 1 addition & 0 deletions how-to/workspace-platform-starter/public/manifest.fin.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
},
"intentOptions": {},
"openOptions": {},
"contextOptions": {},
"unregisteredApp": {
"appId": "unregistered",
"title": "Other",
Expand Down
Loading

0 comments on commit b237889

Please sign in to comment.