Skip to content

Commit 28c8dd6

Browse files
authored
Merge pull request #1695 from finos/1693-web-reference-impl-to-use-messageport
1693 web reference impl to use messageport
2 parents 3bbce2c + 7cfc762 commit 28c8dd6

5 files changed

Lines changed: 68 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
88
* Enhanced method binding for FDC3 API objects to support destructuring. All public methods of `Channel`, `PrivateChannel`, and `IntentResolution` objects are now properly bound to their instances using `.bind(this)` in their constructors. ([#1645](https://github.com/finos/FDC3/issues/1645))
99

1010
### Added
11-
* Add a notes field to Trade type ([#1563](https://github.com/finos/FDC3/pull/1563))
12-
* Add a notes field to Order and Product types ([#1597](https://github.com/finos/FDC3/pull/1597))
11+
12+
* Added a notes field to Trade type ([#1563](https://github.com/finos/FDC3/pull/1563))
13+
* Added a notes field to Order and Product types ([#1597](https://github.com/finos/FDC3/pull/1597))
1314
* Added Go language binding. ([#1483](https://github.com/finos/FDC3/pull/1483))
1415
* Added dynamic intent listener support to the reference Desktop Agent implementation ([#1613](https://github.com/finos/FDC3/pull/1613))
1516
* Added details of and procedures for resolving fully-qualified appIds and unqualified appIds in the API and Bridging Parts of the Standard. ([#1523](https://github.com/finos/FDC3/pull/1523))
@@ -24,14 +25,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
2425

2526
### Fixed
2627

27-
* Updated .NET API documentation for IListener.Unsubscribe to be async for 2.2 and current. ([#1690](https://github.com/finos/FDC3/pull/1690))
28+
* Corrected /toolbox/fdc3-for-web/demo to only use MessagePort communication when 'Parent Post-Message' selected in the demo. ([#1695](https://github.com/finos/FDC3/pull/1695))
2829
* Corrected the property set in WCP1Hello by getAgent that indicates whether an intent resolver is needed. ([#1684](https://github.com/finos/FDC3/issues/1684))
29-
* Add unit tests to the fdc3-context package for validating context examples are valid schema.
30-
* Revert schema of `fdc3.timeRange` context type back to use anyOf in place of oneOf for the `startTime` and `endTime` property combinations. This will allow existence of one of either, or both, and pass schema validation. When defined with oneOf, validation would fail due to multiple entries being valid and it could not identify which to apply. ([#1592](https://github.com/finos/FDC3/issues/1592))
31-
* Revert schema of `fdc3.interaction` context type back to use anyOf in place of oneOf for the `interactionType` property. Since it could be a string enum or a string, validation could not differentiate. ([#1598](https://github.com/finos/FDC3/issues/1598))
32-
* Fix `fdc3.timeRange` context example to use correctly formatted dateTime. ([#1599](https://github.com/finos/FDC3/issues/1599))
33-
* Removes broken sourcemaps from npm package output ([#1589](https://github.com/finos/FDC3/issues/1589))
30+
* Added unit tests to the fdc3-context package for validating context examples are valid schema.
31+
* Reverted schema of `fdc3.timeRange` context type back to use anyOf in place of oneOf for the `startTime` and `endTime` property combinations. This will allow existence of one of either, or both, and pass schema validation. When defined with oneOf, validation would fail due to multiple entries being valid and it could not identify which to apply. ([#1592](https://github.com/finos/FDC3/issues/1592))
32+
* Reverted schema of `fdc3.interaction` context type back to use anyOf in place of oneOf for the `interactionType` property. Since it could be a string enum or a string, validation could not differentiate. ([#1598](https://github.com/finos/FDC3/issues/1598))
33+
* Fixed `fdc3.timeRange` context example to use correctly formatted dateTime. ([#1599](https://github.com/finos/FDC3/issues/1599))
34+
* Removed broken sourcemaps from npm package output ([#1589](https://github.com/finos/FDC3/issues/1589))
3435
* Fixed the `fdc3-commonjs` build to include `d.ts` files and corrects the config for easier consumption in different environments. ([#1694](https://github.com/finos/FDC3/issues/1694))
36+
* Updated .NET API documentation for IListener.Unsubscribe to be async for 2.2 and current. ([#1690](https://github.com/finos/FDC3/pull/1690))
3537

3638
## [FDC3 Standard 2.2](https://github.com/finos/FDC3/compare/v2.1..v2.2) - 2025-03-12
3739

toolbox/fdc3-for-web/demo/eslint.config.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ import eslintConfigPrettier from 'eslint-config-prettier';
55

66
/** @type {import('eslint').Linter.Config[]} */
77
export default [
8+
{
9+
languageOptions: {
10+
parserOptions: {
11+
tsconfigRootDir: import.meta.dirname,
12+
},
13+
},
14+
},
815
{ files: ['**/*.{js,mjs,cjs,ts}'] },
916
{ languageOptions: { globals: globals.browser } },
1017
pluginJs.configs.recommended,

toolbox/fdc3-for-web/demo/src/client/da/DemoServerContext.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ enum Opener {
2020
type RunningAppRegistration = AppRegistration & {
2121
window: Window;
2222
url: string;
23+
messagePort?: MessagePort;
2324
};
2425

2526
type LaunchingAppRegistration = AppRegistration & {
@@ -165,7 +166,19 @@ export class DemoServerContext implements ServerContext<DemoAppRegistration> {
165166
* Post an outgoing message to a particular app
166167
*/
167168
async post(message: object, to: InstanceID): Promise<void> {
168-
this.socket.emit(FDC3_DA_EVENT, message, to);
169+
//figure out if we're using a MessagePort or the socket to communicate with the app
170+
const registration = this.getInstanceDetails(to);
171+
if (registration && isRunningAppRegistration(registration)) {
172+
if (registration.messagePort) {
173+
registration.messagePort.postMessage(message);
174+
} else {
175+
this.socket.emit(FDC3_DA_EVENT, message, to);
176+
}
177+
} else if (!registration) {
178+
console.error("Can't message unknown app instance: ", to);
179+
} else {
180+
console.error("Can't message app that is not yet connected: ", to);
181+
}
169182
}
170183

171184
openFrame(url: string): Promise<Window | null> {

toolbox/fdc3-for-web/demo/src/client/da/dummy-desktop-agent.ts

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { io } from 'socket.io-client';
22
import { v4 as uuid } from 'uuid';
3-
import { APP_GOODBYE, APP_HELLO, DA_HELLO, FDC3_APP_EVENT } from '../../message-types';
3+
import { APP_GOODBYE, DA_HELLO, FDC3_APP_EVENT } from '../../message-types';
44
import { DemoServerContext } from './DemoServerContext';
55
import { FDC3_2_1_JSONDirectory } from './FDC3_2_1_JSONDirectory';
66
import { AppRegistration, DefaultFDC3Server, DirectoryApp, ServerContext } from '@finos/fdc3-web-impl';
77
import { ChannelState, ChannelType } from '@finos/fdc3-web-impl/src/handlers/BroadcastHandler';
8-
import { link, UI, UI_URLS } from './util';
8+
import { UI, UI_URLS } from './util';
99
import { BrowserTypes } from '@finos/fdc3-schema';
1010
import { WebConnectionProtocol3Handshake } from '@finos/fdc3-schema/dist/generated/api/BrowserTypes';
1111

@@ -171,11 +171,14 @@ window.addEventListener('load', () => {
171171
const source = event.source as Window;
172172
const origin = event.origin;
173173

174-
console.log('Received: ' + JSON.stringify(event.data));
174+
console.log('Received window.postMessage: ' + JSON.stringify(event.data));
175175
if (data.type == 'WCP1Hello') {
176176
const instance = await sc.getInstanceForWindow(source);
177177
if (instance) {
178+
console.log('Identified instance for source window: ' + JSON.stringify(instance.instanceId));
179+
178180
if (getApproach() == Approach.IFRAME) {
181+
// Let getAgent/the app know to load an adaptor into an iframe via WCP2LoadUrl
179182
const message: WebConnectionProtocol2LoadURL = {
180183
type: 'WCP2LoadUrl',
181184
meta: {
@@ -189,14 +192,31 @@ window.addEventListener('load', () => {
189192
},
190193
};
191194

195+
console.log('Responding with message: ', JSON.stringify(message));
196+
197+
// no message port is included as communication will be setup with the iframe
192198
source.postMessage(message, origin);
193199
} else {
200+
//setup a MessageChannel and handling for incoming messages on it
194201
const channel = new MessageChannel();
195-
link(socket, channel, instance.instanceId);
196-
socket.emit(APP_HELLO, desktopAgentUUID, instance.instanceId);
202+
channel.port2.onmessage = message => {
203+
console.log(
204+
`message received on message port for app ${instance.instanceId}, message: ${JSON.stringify(message.data)}`
205+
);
206+
const msg = message.data as
207+
| BrowserTypes.AppRequestMessage
208+
| BrowserTypes.WebConnectionProtocol4ValidateAppIdentity
209+
| BrowserTypes.WebConnectionProtocol6Goodbye;
210+
fdc3Server.receive(msg, instance.instanceId);
211+
};
212+
213+
//update the server Context with the MessagePort
214+
await sc.setInstanceDetails(instance.instanceId, { ...instance, messagePort: channel.port2 });
215+
216+
//get details of channel selector and intent resolver
197217
const ui = UI_URLS[getUIKey()];
198218

199-
// send the other end of the channel to the app
219+
//prepare the handshake message
200220
const message: WebConnectionProtocol3Handshake = {
201221
type: 'WCP3Handshake',
202222
meta: {
@@ -208,9 +228,13 @@ window.addEventListener('load', () => {
208228
...ui,
209229
},
210230
};
231+
console.log('Responding with message: ', JSON.stringify(message));
232+
233+
//send the handshake message and include the message port for further comms
211234
source.postMessage(message, origin, [channel.port1]);
212235
}
213236
} else {
237+
// Log unknown windows but don't let them connect
214238
let sourceName;
215239
try {
216240
sourceName = source.name;

toolbox/fdc3-for-web/fdc3-web-impl/eslint.config.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ import eslintConfigPrettier from 'eslint-config-prettier';
55

66
/** @type {import('eslint').Linter.Config[]} */
77
export default [
8+
{
9+
languageOptions: {
10+
parserOptions: {
11+
tsconfigRootDir: import.meta.dirname,
12+
},
13+
},
14+
},
815
{ files: ['**/*.{js,mjs,cjs,ts}'] },
916
{ languageOptions: { globals: globals.browser } },
1017
pluginJs.configs.recommended,

0 commit comments

Comments
 (0)