@openfin/core 33.76.36 → 33.76.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/OpenFin.d.ts +1 -1
- package/README.md +29 -4
- package/fin.d.ts +2 -2
- package/{src → out}/GlobalOpenFin.d.ts +1 -1
- package/out/mock-alpha.d.ts +16112 -0
- package/out/mock-beta.d.ts +16112 -0
- package/out/mock-public.d.ts +16112 -0
- package/out/mock.d.ts +16797 -0
- package/out/mock.js +17104 -0
- package/package.json +30 -23
- package/LICENSE +0 -13
- package/NOTICE +0 -16
- package/openfin-core-33.76.36.tgz +0 -0
- package/src/OpenFin.d.ts +0 -3091
- package/src/OpenFin.js +0 -2
- package/src/api/api-exposer/api-consumer.d.ts +0 -28
- package/src/api/api-exposer/api-consumer.js +0 -28
- package/src/api/api-exposer/api-exposer.d.ts +0 -35
- package/src/api/api-exposer/api-exposer.js +0 -38
- package/src/api/api-exposer/decorators.d.ts +0 -10
- package/src/api/api-exposer/decorators.js +0 -18
- package/src/api/api-exposer/index.d.ts +0 -4
- package/src/api/api-exposer/index.js +0 -20
- package/src/api/api-exposer/strategies/index.d.ts +0 -1
- package/src/api/api-exposer/strategies/index.js +0 -17
- package/src/api/api-exposer/strategies/openfin-channels/channels-consumer.d.ts +0 -14
- package/src/api/api-exposer/strategies/openfin-channels/channels-consumer.js +0 -20
- package/src/api/api-exposer/strategies/openfin-channels/channels-exposer.d.ts +0 -20
- package/src/api/api-exposer/strategies/openfin-channels/channels-exposer.js +0 -23
- package/src/api/api-exposer/strategies/openfin-channels/index.d.ts +0 -2
- package/src/api/api-exposer/strategies/openfin-channels/index.js +0 -18
- package/src/api/application/Factory.d.ts +0 -196
- package/src/api/application/Factory.js +0 -278
- package/src/api/application/Instance.d.ts +0 -692
- package/src/api/application/Instance.js +0 -821
- package/src/api/application/index.d.ts +0 -12
- package/src/api/application/index.js +0 -28
- package/src/api/base.d.ts +0 -117
- package/src/api/base.js +0 -246
- package/src/api/clipboard/index.d.ts +0 -172
- package/src/api/clipboard/index.js +0 -200
- package/src/api/events/application.d.ts +0 -158
- package/src/api/events/application.js +0 -14
- package/src/api/events/base.d.ts +0 -42
- package/src/api/events/base.js +0 -2
- package/src/api/events/channel.d.ts +0 -35
- package/src/api/events/channel.js +0 -7
- package/src/api/events/emitterMap.d.ts +0 -11
- package/src/api/events/emitterMap.js +0 -35
- package/src/api/events/eventAggregator.d.ts +0 -5
- package/src/api/events/eventAggregator.js +0 -35
- package/src/api/events/externalApplication.d.ts +0 -24
- package/src/api/events/externalApplication.js +0 -7
- package/src/api/events/frame.d.ts +0 -35
- package/src/api/events/frame.js +0 -2
- package/src/api/events/globalHotkey.d.ts +0 -25
- package/src/api/events/globalHotkey.js +0 -2
- package/src/api/events/platform.d.ts +0 -34
- package/src/api/events/platform.js +0 -10
- package/src/api/events/system.d.ts +0 -126
- package/src/api/events/system.js +0 -15
- package/src/api/events/typedEventEmitter.d.ts +0 -20
- package/src/api/events/typedEventEmitter.js +0 -2
- package/src/api/events/view.d.ts +0 -92
- package/src/api/events/view.js +0 -12
- package/src/api/events/webcontents.d.ts +0 -277
- package/src/api/events/webcontents.js +0 -13
- package/src/api/events/window.d.ts +0 -421
- package/src/api/events/window.js +0 -12
- package/src/api/external-application/Factory.d.ts +0 -34
- package/src/api/external-application/Factory.js +0 -47
- package/src/api/external-application/Instance.d.ts +0 -110
- package/src/api/external-application/Instance.js +0 -117
- package/src/api/external-application/index.d.ts +0 -12
- package/src/api/external-application/index.js +0 -28
- package/src/api/fin.d.ts +0 -54
- package/src/api/fin.js +0 -45
- package/src/api/frame/Factory.d.ts +0 -54
- package/src/api/frame/Factory.js +0 -86
- package/src/api/frame/Instance.d.ts +0 -136
- package/src/api/frame/Instance.js +0 -143
- package/src/api/frame/index.d.ts +0 -14
- package/src/api/frame/index.js +0 -30
- package/src/api/global-hotkey/index.d.ts +0 -106
- package/src/api/global-hotkey/index.js +0 -132
- package/src/api/interappbus/channel/channel.d.ts +0 -285
- package/src/api/interappbus/channel/channel.js +0 -334
- package/src/api/interappbus/channel/channels-docs.d.ts +0 -342
- package/src/api/interappbus/channel/channels-docs.js +0 -401
- package/src/api/interappbus/channel/client.d.ts +0 -117
- package/src/api/interappbus/channel/client.js +0 -181
- package/src/api/interappbus/channel/connection-manager.d.ts +0 -29
- package/src/api/interappbus/channel/connection-manager.js +0 -246
- package/src/api/interappbus/channel/index.d.ts +0 -189
- package/src/api/interappbus/channel/index.js +0 -333
- package/src/api/interappbus/channel/protocols/classic/message-receiver.d.ts +0 -13
- package/src/api/interappbus/channel/protocols/classic/message-receiver.js +0 -73
- package/src/api/interappbus/channel/protocols/classic/strategy.d.ts +0 -24
- package/src/api/interappbus/channel/protocols/classic/strategy.js +0 -101
- package/src/api/interappbus/channel/protocols/combined/strategy.d.ts +0 -20
- package/src/api/interappbus/channel/protocols/combined/strategy.js +0 -58
- package/src/api/interappbus/channel/protocols/index.d.ts +0 -47
- package/src/api/interappbus/channel/protocols/index.js +0 -2
- package/src/api/interappbus/channel/protocols/protocol-manager.d.ts +0 -10
- package/src/api/interappbus/channel/protocols/protocol-manager.js +0 -43
- package/src/api/interappbus/channel/protocols/rtc/endpoint.d.ts +0 -25
- package/src/api/interappbus/channel/protocols/rtc/endpoint.js +0 -141
- package/src/api/interappbus/channel/protocols/rtc/ice-manager.d.ts +0 -30
- package/src/api/interappbus/channel/protocols/rtc/ice-manager.js +0 -130
- package/src/api/interappbus/channel/protocols/rtc/strategy.d.ts +0 -24
- package/src/api/interappbus/channel/protocols/rtc/strategy.js +0 -85
- package/src/api/interappbus/channel/protocols/strategy-types.d.ts +0 -13
- package/src/api/interappbus/channel/protocols/strategy-types.js +0 -2
- package/src/api/interappbus/channel/protocols/strategy.d.ts +0 -17
- package/src/api/interappbus/channel/protocols/strategy.js +0 -2
- package/src/api/interappbus/channel/provider.d.ts +0 -206
- package/src/api/interappbus/channel/provider.js +0 -338
- package/src/api/interappbus/index.d.ts +0 -120
- package/src/api/interappbus/index.js +0 -210
- package/src/api/interop/Factory.d.ts +0 -57
- package/src/api/interop/Factory.js +0 -96
- package/src/api/interop/InteropBroker.d.ts +0 -665
- package/src/api/interop/InteropBroker.js +0 -1313
- package/src/api/interop/InteropClient.d.ts +0 -502
- package/src/api/interop/InteropClient.js +0 -683
- package/src/api/interop/SessionContextGroupBroker.d.ts +0 -27
- package/src/api/interop/SessionContextGroupBroker.js +0 -108
- package/src/api/interop/SessionContextGroupClient.d.ts +0 -21
- package/src/api/interop/SessionContextGroupClient.js +0 -86
- package/src/api/interop/fdc3/PrivateChannelClient.d.ts +0 -20
- package/src/api/interop/fdc3/PrivateChannelClient.js +0 -90
- package/src/api/interop/fdc3/PrivateChannelProvider.d.ts +0 -55
- package/src/api/interop/fdc3/PrivateChannelProvider.js +0 -276
- package/src/api/interop/fdc3/documentationStub.d.ts +0 -14
- package/src/api/interop/fdc3/documentationStub.js +0 -17
- package/src/api/interop/fdc3/fdc3-1.2.d.ts +0 -205
- package/src/api/interop/fdc3/fdc3-1.2.js +0 -435
- package/src/api/interop/fdc3/fdc3-2.0.d.ts +0 -298
- package/src/api/interop/fdc3/fdc3-2.0.js +0 -479
- package/src/api/interop/fdc3/fdc3.d.ts +0 -12
- package/src/api/interop/fdc3/fdc3.js +0 -35
- package/src/api/interop/fdc3/overrideCheck.d.ts +0 -4
- package/src/api/interop/fdc3/overrideCheck.js +0 -32
- package/src/api/interop/fdc3/shapes/fdc3v1.d.ts +0 -53
- package/src/api/interop/fdc3/shapes/fdc3v1.js +0 -4
- package/src/api/interop/fdc3/shapes/fdc3v2.d.ts +0 -75
- package/src/api/interop/fdc3/shapes/fdc3v2.js +0 -2
- package/src/api/interop/fdc3/utils.d.ts +0 -45
- package/src/api/interop/fdc3/utils.js +0 -239
- package/src/api/interop/fdc3/versions.d.ts +0 -1
- package/src/api/interop/fdc3/versions.js +0 -2
- package/src/api/interop/index.d.ts +0 -12
- package/src/api/interop/index.js +0 -28
- package/src/api/interop/utils.d.ts +0 -18
- package/src/api/interop/utils.js +0 -61
- package/src/api/me.d.ts +0 -40
- package/src/api/me.js +0 -134
- package/src/api/platform/Factory.d.ts +0 -171
- package/src/api/platform/Factory.js +0 -240
- package/src/api/platform/Instance.d.ts +0 -653
- package/src/api/platform/Instance.js +0 -834
- package/src/api/platform/common-utils.d.ts +0 -7
- package/src/api/platform/common-utils.js +0 -16
- package/src/api/platform/index.d.ts +0 -12
- package/src/api/platform/index.js +0 -28
- package/src/api/platform/layout/Factory.d.ts +0 -91
- package/src/api/platform/layout/Factory.js +0 -151
- package/src/api/platform/layout/Instance.d.ts +0 -192
- package/src/api/platform/layout/Instance.js +0 -224
- package/src/api/platform/layout/controllers/layout-content-cache.d.ts +0 -9
- package/src/api/platform/layout/controllers/layout-content-cache.js +0 -54
- package/src/api/platform/layout/controllers/layout-entities-controller.d.ts +0 -119
- package/src/api/platform/layout/controllers/layout-entities-controller.js +0 -287
- package/src/api/platform/layout/entities/layout-entities.d.ts +0 -427
- package/src/api/platform/layout/entities/layout-entities.js +0 -504
- package/src/api/platform/layout/entities/shapes.d.ts +0 -6
- package/src/api/platform/layout/entities/shapes.js +0 -2
- package/src/api/platform/layout/index.d.ts +0 -11
- package/src/api/platform/layout/index.js +0 -27
- package/src/api/platform/layout/layout.constants.d.ts +0 -1
- package/src/api/platform/layout/layout.constants.js +0 -4
- package/src/api/platform/layout/shapes.d.ts +0 -16
- package/src/api/platform/layout/shapes.js +0 -2
- package/src/api/platform/layout/utils/layout-traversal.d.ts +0 -4
- package/src/api/platform/layout/utils/layout-traversal.js +0 -65
- package/src/api/platform/provider.d.ts +0 -510
- package/src/api/platform/provider.js +0 -2
- package/src/api/snapshot-source/Factory.d.ts +0 -53
- package/src/api/snapshot-source/Factory.js +0 -81
- package/src/api/snapshot-source/Instance.d.ts +0 -53
- package/src/api/snapshot-source/Instance.js +0 -154
- package/src/api/snapshot-source/index.d.ts +0 -12
- package/src/api/snapshot-source/index.js +0 -28
- package/src/api/snapshot-source/utils.d.ts +0 -2
- package/src/api/snapshot-source/utils.js +0 -6
- package/src/api/system/index.d.ts +0 -1468
- package/src/api/system/index.js +0 -1851
- package/src/api/view/Factory.d.ts +0 -88
- package/src/api/view/Factory.js +0 -141
- package/src/api/view/Instance.d.ts +0 -601
- package/src/api/view/Instance.js +0 -671
- package/src/api/view/index.d.ts +0 -12
- package/src/api/view/index.js +0 -28
- package/src/api/webcontents/main.d.ts +0 -922
- package/src/api/webcontents/main.js +0 -1046
- package/src/api/window/Factory.d.ts +0 -96
- package/src/api/window/Factory.js +0 -142
- package/src/api/window/Instance.d.ts +0 -1598
- package/src/api/window/Instance.js +0 -1851
- package/src/api/window/index.d.ts +0 -14
- package/src/api/window/index.js +0 -30
- package/src/browser.d.ts +0 -10
- package/src/browser.js +0 -36
- package/src/environment/browser.d.ts +0 -29
- package/src/environment/browser.js +0 -60
- package/src/environment/environment.d.ts +0 -33
- package/src/environment/environment.js +0 -4
- package/src/environment/mockEnvironment.d.ts +0 -27
- package/src/environment/mockEnvironment.js +0 -61
- package/src/environment/node-env.d.ts +0 -29
- package/src/environment/node-env.js +0 -72
- package/src/fdc3.d.ts +0 -3
- package/src/fdc3.js +0 -9
- package/src/mock.d.ts +0 -3
- package/src/mock.js +0 -18
- package/src/namespaces.d.ts +0 -22
- package/src/namespaces.js +0 -26
- package/src/shapes/ERROR_BOX_TYPES.d.ts +0 -1
- package/src/shapes/ERROR_BOX_TYPES.js +0 -2
- package/src/shapes/WebOptions.d.ts +0 -13
- package/src/shapes/WebOptions.js +0 -2
- package/src/shapes/WindowOptions.d.ts +0 -43
- package/src/shapes/WindowOptions.js +0 -2
- package/src/shapes/protocol.d.ts +0 -204
- package/src/shapes/protocol.js +0 -2
- package/src/transport/mockWire.d.ts +0 -11
- package/src/transport/mockWire.js +0 -26
- package/src/transport/transport-errors.d.ts +0 -31
- package/src/transport/transport-errors.js +0 -79
- package/src/transport/transport.d.ts +0 -73
- package/src/transport/transport.js +0 -219
- package/src/transport/wire.d.ts +0 -77
- package/src/transport/wire.js +0 -36
- package/src/util/asyncFilter.d.ts +0 -1
- package/src/util/asyncFilter.js +0 -7
- package/src/util/channel-api-relay.d.ts +0 -13
- package/src/util/channel-api-relay.js +0 -47
- package/src/util/errors.d.ts +0 -10
- package/src/util/errors.js +0 -12
- package/src/util/exhaustive.d.ts +0 -1
- package/src/util/exhaustive.js +0 -7
- package/src/util/http.d.ts +0 -11
- package/src/util/http.js +0 -90
- package/src/util/inaccessibleObject.d.ts +0 -2
- package/src/util/inaccessibleObject.js +0 -49
- package/src/util/lazy.d.ts +0 -34
- package/src/util/lazy.js +0 -54
- package/src/util/normalize-config.d.ts +0 -3
- package/src/util/normalize-config.js +0 -52
- package/src/util/promises.d.ts +0 -5
- package/src/util/promises.js +0 -27
- package/src/util/ref-counter.d.ts +0 -7
- package/src/util/ref-counter.js +0 -52
- package/src/util/reversible-map.d.ts +0 -11
- package/src/util/reversible-map.js +0 -49
- package/src/util/runtimeVersioning.d.ts +0 -3
- package/src/util/runtimeVersioning.js +0 -25
- package/src/util/utilTypes.d.ts +0 -8
- package/src/util/utilTypes.js +0 -2
- package/src/util/validate.d.ts +0 -3
- package/src/util/validate.js +0 -11
|
@@ -1,1313 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InteropBroker = void 0;
|
|
4
|
-
const base_1 = require("../base");
|
|
5
|
-
const SessionContextGroupBroker_1 = require("./SessionContextGroupBroker");
|
|
6
|
-
const utils_1 = require("./utils");
|
|
7
|
-
const lodash_1 = require("lodash");
|
|
8
|
-
const PrivateChannelProvider_1 = require("./fdc3/PrivateChannelProvider");
|
|
9
|
-
let contextGroups = [
|
|
10
|
-
{
|
|
11
|
-
id: 'green',
|
|
12
|
-
displayMetadata: {
|
|
13
|
-
color: '#00CC88',
|
|
14
|
-
name: 'green'
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
id: 'purple',
|
|
19
|
-
displayMetadata: {
|
|
20
|
-
color: '#8C61FF',
|
|
21
|
-
name: 'purple'
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
id: 'orange',
|
|
26
|
-
displayMetadata: {
|
|
27
|
-
color: '#FF8C4C',
|
|
28
|
-
name: 'orange'
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
id: 'red',
|
|
33
|
-
displayMetadata: {
|
|
34
|
-
color: '#FF5E60',
|
|
35
|
-
name: 'red'
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
id: 'pink',
|
|
40
|
-
displayMetadata: {
|
|
41
|
-
color: '#FF8FB8',
|
|
42
|
-
name: 'pink'
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
id: 'yellow',
|
|
47
|
-
displayMetadata: {
|
|
48
|
-
color: '#E9FF8F',
|
|
49
|
-
name: 'yellow'
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
];
|
|
53
|
-
/**
|
|
54
|
-
* {@link https://developers.openfin.co/of-docs/docs/enable-color-linking}
|
|
55
|
-
*
|
|
56
|
-
* The Interop Broker is responsible for keeping track of the Interop state of the Platform, and for directing messages to the proper locations.
|
|
57
|
-
*
|
|
58
|
-
* @remarks This class contains some types related to FDC3 that are specific to OpenFin. {@link https://developers.openfin.co/of-docs/docs/fdc3-support-in-openfin OpenFin's FDC3 support} is forward- and backward-compatible.
|
|
59
|
-
* Standard types for {@link https://fdc3.finos.org/ FDC3} do not appear in OpenFin’s API documentation, to avoid duplication.
|
|
60
|
-
*
|
|
61
|
-
* ---
|
|
62
|
-
*
|
|
63
|
-
* There are 2 ways to inject custom functionality into the Interop Broker:
|
|
64
|
-
*
|
|
65
|
-
* **1. Configuration**
|
|
66
|
-
*
|
|
67
|
-
* At the moment, you can configure the default context groups for the Interop Broker without having to override it. To do so, include the `interopBrokerConfiguration` `contextGroups` option in your `platform` options in your manifest. This is the preferred method.
|
|
68
|
-
* ```js
|
|
69
|
-
* {
|
|
70
|
-
* "runtime": {
|
|
71
|
-
* "arguments": "--v=1 --inspect",
|
|
72
|
-
* "version": "alpha-v19"
|
|
73
|
-
* },
|
|
74
|
-
* "platform": {
|
|
75
|
-
* "uuid": "platform_customization_local",
|
|
76
|
-
* "applicationIcon": "https://openfin.github.io/golden-prototype/favicon.ico",
|
|
77
|
-
* "autoShow": false,
|
|
78
|
-
* "providerUrl": "http://localhost:5555/provider.html",
|
|
79
|
-
* "interopBrokerConfiguration": {
|
|
80
|
-
* "contextGroups": [
|
|
81
|
-
* {
|
|
82
|
-
* "id": "green",
|
|
83
|
-
* "displayMetadata": {
|
|
84
|
-
* "color": "#00CC88",
|
|
85
|
-
* "name": "green"
|
|
86
|
-
* }
|
|
87
|
-
* },
|
|
88
|
-
* {
|
|
89
|
-
* "id": "purple",
|
|
90
|
-
* "displayMetadata": {
|
|
91
|
-
* "color": "#8C61FF",
|
|
92
|
-
* "name": "purple"
|
|
93
|
-
* }
|
|
94
|
-
* },
|
|
95
|
-
* ]
|
|
96
|
-
* }
|
|
97
|
-
* }
|
|
98
|
-
* }
|
|
99
|
-
* ```
|
|
100
|
-
*
|
|
101
|
-
* By default the Interop Broker logs all actions to the console. You can disable this by using the logging option in `interopBrokerConfiguration`:
|
|
102
|
-
* ```js
|
|
103
|
-
* {
|
|
104
|
-
* "runtime": {
|
|
105
|
-
* "arguments": "--v=1 --inspect",
|
|
106
|
-
* "version": "alpha-v19"
|
|
107
|
-
* },
|
|
108
|
-
* "platform": {
|
|
109
|
-
* "uuid": "platform_customization_local",
|
|
110
|
-
* "applicationIcon": "https://openfin.github.io/golden-prototype/favicon.ico",
|
|
111
|
-
* "autoShow": false,
|
|
112
|
-
* "providerUrl": "http://localhost:5555/provider.html",
|
|
113
|
-
* "interopBrokerConfiguration": {
|
|
114
|
-
* "logging": {
|
|
115
|
-
* "beforeAction": {
|
|
116
|
-
* "enabled": false
|
|
117
|
-
* },
|
|
118
|
-
* "afterAction": {
|
|
119
|
-
* "enabled": false
|
|
120
|
-
* }
|
|
121
|
-
* }
|
|
122
|
-
* }
|
|
123
|
-
* }
|
|
124
|
-
* }
|
|
125
|
-
* ```
|
|
126
|
-
*
|
|
127
|
-
* ---
|
|
128
|
-
* **2. Overriding**
|
|
129
|
-
*
|
|
130
|
-
* Similarly to how {@link https://developers.openfin.co/docs/platform-customization#section-customizing-platform-behavior Platform Overriding} works, you can override functions in the Interop Broker in `fin.Platform.init`. An example of that is shown below. Overriding `isConnectionAuthorized` and `isActionAuthorized` will allow you to control allowed connections and allowed actions.
|
|
131
|
-
*
|
|
132
|
-
* However, if there is custom functionality you wish to include in the Interop Broker, please let us know. We would like to provide better configuration options so that you don't have to continually maintain your own override code.
|
|
133
|
-
*
|
|
134
|
-
* ```js
|
|
135
|
-
* fin.Platform.init({
|
|
136
|
-
* overrideCallback: async (Provider) => {
|
|
137
|
-
* class Override extends Provider {
|
|
138
|
-
* async getSnapshot() {
|
|
139
|
-
* console.log('before getSnapshot')
|
|
140
|
-
* const snapshot = await super.getSnapshot();
|
|
141
|
-
* console.log('after getSnapshot')
|
|
142
|
-
* return snapshot;
|
|
143
|
-
* }
|
|
144
|
-
*
|
|
145
|
-
* async applySnapshot({ snapshot, options }) {
|
|
146
|
-
* console.log('before applySnapshot')
|
|
147
|
-
* const originalPromise = super.applySnapshot({ snapshot, options });
|
|
148
|
-
* console.log('after applySnapshot')
|
|
149
|
-
*
|
|
150
|
-
* return originalPromise;
|
|
151
|
-
* }
|
|
152
|
-
* };
|
|
153
|
-
* return new Override();
|
|
154
|
-
* },
|
|
155
|
-
* interopOverride: async (InteropBroker) => {
|
|
156
|
-
* class Override extends InteropBroker {
|
|
157
|
-
* async joinContextGroup(channelName = 'default', target) {
|
|
158
|
-
* console.log('before super joinContextGroup')
|
|
159
|
-
* super.joinContextGroup(channelName, target);
|
|
160
|
-
* console.log('after super joinContextGroup')
|
|
161
|
-
* }
|
|
162
|
-
* }
|
|
163
|
-
*
|
|
164
|
-
* return new Override();
|
|
165
|
-
* }
|
|
166
|
-
* });
|
|
167
|
-
* ```
|
|
168
|
-
*
|
|
169
|
-
* ---
|
|
170
|
-
*
|
|
171
|
-
*/
|
|
172
|
-
class InteropBroker extends base_1.Base {
|
|
173
|
-
/**
|
|
174
|
-
* @internal
|
|
175
|
-
*/
|
|
176
|
-
constructor(wire, getProvider, options) {
|
|
177
|
-
// Tip from Pierre and Michael from the overrideCheck work: Don't use bound methods for overrideable InteropBroker functions.
|
|
178
|
-
super(wire);
|
|
179
|
-
this.getProvider = getProvider;
|
|
180
|
-
this.interopClients = new Map();
|
|
181
|
-
this.contextGroupsById = new Map();
|
|
182
|
-
if (options === null || options === void 0 ? void 0 : options.contextGroups) {
|
|
183
|
-
contextGroups = options.contextGroups;
|
|
184
|
-
}
|
|
185
|
-
if (options === null || options === void 0 ? void 0 : options.logging) {
|
|
186
|
-
this.logging = options.logging;
|
|
187
|
-
}
|
|
188
|
-
this.intentClientMap = new Map();
|
|
189
|
-
this.lastContextMap = new Map();
|
|
190
|
-
this.sessionContextGroupMap = new Map();
|
|
191
|
-
this.setContextGroupMap();
|
|
192
|
-
this.setupChannelProvider();
|
|
193
|
-
}
|
|
194
|
-
static createClosedConstructor(...args) {
|
|
195
|
-
return class OverrideableBroker extends InteropBroker {
|
|
196
|
-
constructor(...unused) {
|
|
197
|
-
if (unused.length) {
|
|
198
|
-
const [_ignore1, ignore2, opts] = unused;
|
|
199
|
-
if (opts && typeof opts === 'object' && !(0, lodash_1.isEqual)(opts, args[2])) {
|
|
200
|
-
// eslint-disable-next-line no-console
|
|
201
|
-
console.warn('You have modified the parameters of the InteropOverride constructor. This behavior is deprecated and will be removed in a future version. You can modify these options in your manifest. Please consult our Interop docs for guidance on migrating to the new override scheme.');
|
|
202
|
-
super(args[0], args[1], opts);
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
// eslint-disable-next-line no-console
|
|
206
|
-
console.warn('You are attempting to pass arguments to the InteropOverride constructor. This is not necessary, and these passed arguments will be ignored. You are likely using an older InteropBroker override scheme. Please consult our Interop docs for guidance on migrating to the new override scheme.');
|
|
207
|
-
}
|
|
208
|
-
super(...args);
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
/*
|
|
213
|
-
Client API
|
|
214
|
-
*/
|
|
215
|
-
/**
|
|
216
|
-
* @REMOVED
|
|
217
|
-
* SetContextOptions interface
|
|
218
|
-
* @typedef { object } SetContextOptions
|
|
219
|
-
* @property { Context } {context} - New context to set.
|
|
220
|
-
*/
|
|
221
|
-
/**
|
|
222
|
-
* @REMOVED
|
|
223
|
-
* GetContextOptions interface
|
|
224
|
-
* @typedef { object } GetContextOptions
|
|
225
|
-
* @property { string } [contextType] - Context Type
|
|
226
|
-
*/
|
|
227
|
-
// TODO: extract inline type and do proper comments
|
|
228
|
-
/**
|
|
229
|
-
* @REMOVED
|
|
230
|
-
* JoinContextGroupOptions interface
|
|
231
|
-
* @typedef { object } JoinContextGroupOptions
|
|
232
|
-
* @property { string } contextGroupId - Id of the context group.
|
|
233
|
-
* @property { Identity | ClientIdentity } [target] - Identity of the entity you wish to join to a context group.
|
|
234
|
-
*/
|
|
235
|
-
/**
|
|
236
|
-
* @REMOVED
|
|
237
|
-
* AddClientToContextGroupOptions interface
|
|
238
|
-
* @typedef { object } AddClientToContextGroupOptions
|
|
239
|
-
* @property { string } contextGroupId - Name of the context group.
|
|
240
|
-
*/
|
|
241
|
-
/**
|
|
242
|
-
* @REMOVED
|
|
243
|
-
* RemoveFromContextGroupOptions interface
|
|
244
|
-
* @typedef { object } RemoveFromContextGroupOptions
|
|
245
|
-
* @property { Identity | ClientIdentity } target - Identity of the entity you wish to join to a context group.
|
|
246
|
-
*/
|
|
247
|
-
/**
|
|
248
|
-
* @REMOVED
|
|
249
|
-
* GetInfoForContextGroupOptions interface
|
|
250
|
-
* @typedef { object } GetInfoForContextGroupOptions
|
|
251
|
-
* @property { string } contextGroupId - Name of the context group to get info for.
|
|
252
|
-
*/
|
|
253
|
-
/**
|
|
254
|
-
* @REMOVED
|
|
255
|
-
* GetAllClientsInContextGroupOptions interface
|
|
256
|
-
* @typedef { object } GetAllClientsInContextGroupOptions
|
|
257
|
-
* @property { string } contextGroupId - Name of the context group to get info for.
|
|
258
|
-
*/
|
|
259
|
-
/**
|
|
260
|
-
* @PORTED
|
|
261
|
-
* InfoForIntentOptions interface
|
|
262
|
-
* @typedef { object } InfoForIntentOptions
|
|
263
|
-
* @property { string } name Name of the intent to get info for.
|
|
264
|
-
* @property { Context } [context] Optional context.
|
|
265
|
-
*/
|
|
266
|
-
/**
|
|
267
|
-
* Sets a context for the context group of the incoming current entity.
|
|
268
|
-
* @param setContextOptions - New context to set.
|
|
269
|
-
* @param clientIdentity - Identity of the client sender.
|
|
270
|
-
*
|
|
271
|
-
*/
|
|
272
|
-
setContext({ context }, clientIdentity) {
|
|
273
|
-
this.wire.sendAction('interop-broker-set-context').catch((e) => {
|
|
274
|
-
// don't expose, analytics-only call
|
|
275
|
-
});
|
|
276
|
-
const clientState = this.getClientState(clientIdentity);
|
|
277
|
-
if (clientState && clientState.contextGroupId) {
|
|
278
|
-
const { contextGroupId } = clientState;
|
|
279
|
-
if (!this.contextGroupsById.has(contextGroupId)) {
|
|
280
|
-
// Theoretically not possible.
|
|
281
|
-
throw new Error(`Client has a context group that isn't in the context group mapping: ${contextGroupId}.`);
|
|
282
|
-
}
|
|
283
|
-
const contextIntegrityCheckResult = InteropBroker.checkContextIntegrity(context);
|
|
284
|
-
if (contextIntegrityCheckResult.isValid === false) {
|
|
285
|
-
throw new Error(`Failed to set Context - bad Context. Reason: ${contextIntegrityCheckResult.reason}. Context: ${JSON.stringify(context)}`);
|
|
286
|
-
}
|
|
287
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
288
|
-
const contextGroupState = this.contextGroupsById.get(contextGroupId);
|
|
289
|
-
const broadcastedContextType = context.type;
|
|
290
|
-
contextGroupState.set(broadcastedContextType, context);
|
|
291
|
-
this.lastContextMap.set(contextGroupId, broadcastedContextType);
|
|
292
|
-
const clientsInSameContextGroup = Array.from(this.interopClients.values()).filter((connectedClient) => connectedClient.contextGroupId === contextGroupId);
|
|
293
|
-
clientsInSameContextGroup.forEach((client) => {
|
|
294
|
-
for (const [, handlerInfo] of client.contextHandlers) {
|
|
295
|
-
if (InteropBroker.isContextTypeCompatible(broadcastedContextType, handlerInfo.contextType)) {
|
|
296
|
-
this.invokeContextHandler(client.clientIdentity, handlerInfo.handlerId, context);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
else if (clientState) {
|
|
302
|
-
// Client has not joined any context group behavior.
|
|
303
|
-
throw new Error('You must join a context group before you can set context.');
|
|
304
|
-
}
|
|
305
|
-
else {
|
|
306
|
-
// This shouldn't get hit.
|
|
307
|
-
throw new Error(`Client with Identity: ${clientIdentity.uuid} ${clientIdentity.name} not in Client State Map`);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
/**
|
|
311
|
-
* Get current context for a client subscribed to a Context Group.
|
|
312
|
-
*
|
|
313
|
-
* @remarks It takes an optional Context Type argument and returns the last context of that type.
|
|
314
|
-
*
|
|
315
|
-
* @param getContextOptions - Options for getting context
|
|
316
|
-
* @param clientIdentity - Identity of the client sender.
|
|
317
|
-
*
|
|
318
|
-
*/
|
|
319
|
-
getCurrentContext(getCurrentContextOptions, clientIdentity) {
|
|
320
|
-
var _a;
|
|
321
|
-
this.wire.sendAction('interop-broker-get-current-context').catch((e) => {
|
|
322
|
-
// don't expose, analytics-only call
|
|
323
|
-
});
|
|
324
|
-
const clientState = this.getClientState(clientIdentity);
|
|
325
|
-
if (!(clientState === null || clientState === void 0 ? void 0 : clientState.contextGroupId)) {
|
|
326
|
-
throw new Error('You must be a member of a context group to call getCurrentContext');
|
|
327
|
-
}
|
|
328
|
-
const { contextGroupId } = clientState;
|
|
329
|
-
const contextGroupState = this.contextGroupsById.get(contextGroupId);
|
|
330
|
-
const lastContextType = this.lastContextMap.get(contextGroupId);
|
|
331
|
-
const contextType = (_a = getCurrentContextOptions === null || getCurrentContextOptions === void 0 ? void 0 : getCurrentContextOptions.contextType) !== null && _a !== void 0 ? _a : lastContextType;
|
|
332
|
-
return contextGroupState && contextType ? contextGroupState.get(contextType) : undefined;
|
|
333
|
-
}
|
|
334
|
-
/*
|
|
335
|
-
Platform Window APIs
|
|
336
|
-
*/
|
|
337
|
-
// joinContextGroup and addClientToContextGroup are separate functions here, for easier overrides and separation of concerns.
|
|
338
|
-
// joinContextGroup checks all connections for matching identities, in case we have multiple connection from an entity.
|
|
339
|
-
/**
|
|
340
|
-
* Join all connections at the given identity (or just one if endpointId provided) to context group `contextGroupId`.
|
|
341
|
-
* If no target is specified, it adds the sender to the context group.
|
|
342
|
-
* joinContextGroup is responsible for checking connections at the incoming identity. It calls {@link InteropBroker#addClientToContextGroup InteropBroker.addClientToContextGroup} to actually group the client.
|
|
343
|
-
* Used by Platform Windows.
|
|
344
|
-
*
|
|
345
|
-
* @param joinContextGroupOptions - Id of the Context Group and identity of the entity to join to the group.
|
|
346
|
-
* @param senderIdentity - Identity of the client sender.
|
|
347
|
-
*/
|
|
348
|
-
async joinContextGroup({ contextGroupId, target }, senderIdentity) {
|
|
349
|
-
this.wire.sendAction('interop-broker-join-context-group').catch((e) => {
|
|
350
|
-
// don't expose, analytics-only call
|
|
351
|
-
});
|
|
352
|
-
if (this.sessionContextGroupMap.has(contextGroupId)) {
|
|
353
|
-
throw new Error(utils_1.BROKER_ERRORS.joinSessionContextGroupWithJoinContextGroup);
|
|
354
|
-
}
|
|
355
|
-
if (target) {
|
|
356
|
-
// If an endpointId is provided, use that. This will likely be used by external adapters.
|
|
357
|
-
if (InteropBroker.hasEndpointId(target)) {
|
|
358
|
-
await this.addClientToContextGroup({ contextGroupId }, target);
|
|
359
|
-
}
|
|
360
|
-
// Sanity check here in case a single app has multiple connections
|
|
361
|
-
try {
|
|
362
|
-
const allConnections = this.channel.connections.filter((x) => x.uuid === target.uuid && x.name === target.name);
|
|
363
|
-
if (!allConnections.length) {
|
|
364
|
-
throw new Error(`Given Identity ${target.uuid} ${target.name} is not connected to the Interop Broker.`);
|
|
365
|
-
}
|
|
366
|
-
if (allConnections.length > 1) {
|
|
367
|
-
// Should figure out how we want to handle this situation. In the meantime, just change context group for all connections.
|
|
368
|
-
console.warn(`More than one connection found for identity ${target.uuid} ${target.name}`);
|
|
369
|
-
}
|
|
370
|
-
const promises = [];
|
|
371
|
-
for (const connection of allConnections) {
|
|
372
|
-
promises.push(this.addClientToContextGroup({ contextGroupId }, connection));
|
|
373
|
-
}
|
|
374
|
-
await Promise.all(promises);
|
|
375
|
-
}
|
|
376
|
-
catch (error) {
|
|
377
|
-
throw new Error(error);
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
else {
|
|
381
|
-
// No target provided, add the sender to the context group.
|
|
382
|
-
await this.addClientToContextGroup({ contextGroupId }, senderIdentity);
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
// addClientToContextGroup does the actual addition of the client to the Context Group
|
|
386
|
-
/**
|
|
387
|
-
* Helper function for {@link InteropBroker#joinContextGroup InteropBroker.joinContextGroup}. Does the work of actually adding the client to the Context Group.
|
|
388
|
-
* Used by Platform Windows.
|
|
389
|
-
*
|
|
390
|
-
* @param addClientToContextGroupOptions - Contains the contextGroupId
|
|
391
|
-
* @param clientIdentity - Identity of the client sender.
|
|
392
|
-
*/
|
|
393
|
-
async addClientToContextGroup({ contextGroupId }, clientIdentity) {
|
|
394
|
-
this.wire.sendAction('interop-broker-add-client-to-context-group').catch((e) => {
|
|
395
|
-
// don't expose, analytics-only call
|
|
396
|
-
});
|
|
397
|
-
const clientSubscriptionState = this.getClientState(clientIdentity);
|
|
398
|
-
if (!clientSubscriptionState) {
|
|
399
|
-
throw new Error(`Client with Identity: ${clientIdentity.uuid} ${clientIdentity.name} not in Client State Map`);
|
|
400
|
-
}
|
|
401
|
-
if (!this.getContextGroups().find((contextGroupInfo) => contextGroupInfo.id === contextGroupId)) {
|
|
402
|
-
throw new Error(`Attempting to join a context group that does not exist: ${contextGroupId}. You may only join existing context groups.`);
|
|
403
|
-
}
|
|
404
|
-
const oldContextGroupId = clientSubscriptionState.contextGroupId;
|
|
405
|
-
if (oldContextGroupId !== contextGroupId) {
|
|
406
|
-
clientSubscriptionState.contextGroupId = contextGroupId;
|
|
407
|
-
await this.setCurrentContextGroupInClientOptions(clientIdentity, contextGroupId);
|
|
408
|
-
const contextGroupMap = this.contextGroupsById.get(contextGroupId);
|
|
409
|
-
for (const [, handlerInfo] of clientSubscriptionState.contextHandlers) {
|
|
410
|
-
const { contextType, handlerId } = handlerInfo;
|
|
411
|
-
if (contextType === undefined) {
|
|
412
|
-
// Send this single handler all of the context, because it accepts all.
|
|
413
|
-
contextGroupMap.forEach((context, _) => {
|
|
414
|
-
this.invokeContextHandler(clientIdentity, handlerId, context);
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
else if (contextGroupMap.has(contextType)) {
|
|
418
|
-
const contextForType = contextGroupMap.get(contextType);
|
|
419
|
-
if (contextForType) {
|
|
420
|
-
this.invokeContextHandler(clientIdentity, handlerId, contextForType);
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
// Removes the target from its context group. Similar structure to joinContextGroup.
|
|
427
|
-
/**
|
|
428
|
-
* Removes the specified target from a context group.
|
|
429
|
-
* If no target is specified, it removes the sender from their context group.
|
|
430
|
-
* removeFromContextGroup is responsible for checking connections at the incoming identity.
|
|
431
|
-
*
|
|
432
|
-
* @remarks It calls {@link InteropBroker#removeClientFromContextGroup InteropBroker.removeClientFromContextGroup} to actually ungroup
|
|
433
|
-
* the client. Used by Platform Windows.
|
|
434
|
-
*
|
|
435
|
-
* @param removeFromContextGroupOptions - Contains the target identity to remove.
|
|
436
|
-
* @param senderIdentity - Identity of the client sender.
|
|
437
|
-
*/
|
|
438
|
-
async removeFromContextGroup({ target }, senderIdentity) {
|
|
439
|
-
this.wire.sendAction('interop-broker-remove-from-context-group').catch((e) => {
|
|
440
|
-
// don't expose, analytics-only call
|
|
441
|
-
});
|
|
442
|
-
if (target) {
|
|
443
|
-
// If an endpointId is provided, use that. This will likely be used by external adapters.
|
|
444
|
-
if (InteropBroker.hasEndpointId(target)) {
|
|
445
|
-
await this.removeClientFromContextGroup(target);
|
|
446
|
-
}
|
|
447
|
-
try {
|
|
448
|
-
// Sanity check here in case a single app has multiple connections
|
|
449
|
-
const allConnections = this.channel.connections.filter((x) => x.uuid === target.uuid && x.name === target.name);
|
|
450
|
-
if (!allConnections.length) {
|
|
451
|
-
throw new Error(`No connection found for given Identity ${target.uuid} ${target.name}`);
|
|
452
|
-
}
|
|
453
|
-
if (allConnections.length > 1) {
|
|
454
|
-
console.warn(`More than one connection found for identity ${target.uuid} ${target.name}`);
|
|
455
|
-
}
|
|
456
|
-
const promises = [];
|
|
457
|
-
for (const connection of allConnections) {
|
|
458
|
-
promises.push(this.removeClientFromContextGroup(connection));
|
|
459
|
-
}
|
|
460
|
-
await Promise.all(promises);
|
|
461
|
-
}
|
|
462
|
-
catch (error) {
|
|
463
|
-
throw new Error(error);
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
else {
|
|
467
|
-
// No target provided, remove the sender from the context group.
|
|
468
|
-
await this.removeClientFromContextGroup(senderIdentity);
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
// removeClientFromContextGroup does the actual remove of the client from the Context Group
|
|
472
|
-
/**
|
|
473
|
-
* Helper function for {@link InteropBroker#removeFromContextGroup InteropBroker.removeFromContextGroup}. Does the work of actually removing the client from the Context Group.
|
|
474
|
-
* Used by Platform Windows.
|
|
475
|
-
*
|
|
476
|
-
* @property { ClientIdentity } clientIdentity - Identity of the client sender.
|
|
477
|
-
*/
|
|
478
|
-
async removeClientFromContextGroup(clientIdentity) {
|
|
479
|
-
this.wire.sendAction('interop-broker-remove-client-from-context-group').catch((e) => {
|
|
480
|
-
// don't expose, analytics-only call
|
|
481
|
-
});
|
|
482
|
-
const clientState = this.getClientState(clientIdentity);
|
|
483
|
-
if (clientState) {
|
|
484
|
-
clientState.contextGroupId = undefined;
|
|
485
|
-
}
|
|
486
|
-
await this.setCurrentContextGroupInClientOptions(clientIdentity, null);
|
|
487
|
-
}
|
|
488
|
-
// Used by platform windows to know what client groups the provider has declared. Also used internally to access context groups. Overrideable so that the platform developer can modify it.
|
|
489
|
-
/**
|
|
490
|
-
* Returns the Interop-Broker-defined context groups available for an entity to join. Because this function is used in the rest of the Interop Broker to fetch the Context Groups, overriding this allows you to customize the Context Groups for the Interop Broker. However, we recommend customizing the context groups through configuration instead.
|
|
491
|
-
* Used by Platform Windows.
|
|
492
|
-
*
|
|
493
|
-
*/
|
|
494
|
-
// eslint-disable-next-line class-methods-use-this
|
|
495
|
-
getContextGroups() {
|
|
496
|
-
this.wire.sendAction('interop-broker-get-context-groups').catch((e) => {
|
|
497
|
-
// don't expose, analytics-only call
|
|
498
|
-
});
|
|
499
|
-
// Create copy for immutability
|
|
500
|
-
return contextGroups.map((contextGroup) => {
|
|
501
|
-
return { ...contextGroup };
|
|
502
|
-
});
|
|
503
|
-
}
|
|
504
|
-
// Used to by platform windows to get display metadata for a context group.
|
|
505
|
-
/**
|
|
506
|
-
* Gets display info for a context group
|
|
507
|
-
*
|
|
508
|
-
* @remarks Used by Platform Windows.
|
|
509
|
-
*
|
|
510
|
-
* @param getInfoForContextGroupOptions - Contains contextGroupId, the context group you wish to get display info for.
|
|
511
|
-
*
|
|
512
|
-
*/
|
|
513
|
-
getInfoForContextGroup({ contextGroupId }) {
|
|
514
|
-
this.wire.sendAction('interop-broker-get-info-for-context-group').catch((e) => {
|
|
515
|
-
// don't expose, analytics-only call
|
|
516
|
-
});
|
|
517
|
-
return this.getContextGroups().find((contextGroup) => contextGroup.id === contextGroupId);
|
|
518
|
-
}
|
|
519
|
-
// Used by platform windows to get all clients for a context group.
|
|
520
|
-
/**
|
|
521
|
-
* Gets all clients for a context group.
|
|
522
|
-
*
|
|
523
|
-
* @remarks **This is primarily used for platform windows. Views within a platform should not have to use this API.**
|
|
524
|
-
* Returns the Interop-Broker-defined context groups available for an entity to join.
|
|
525
|
-
*
|
|
526
|
-
* @param getAllClientsInContextGroupOptions - Contains contextGroupId, the context group you wish to get clients for.
|
|
527
|
-
*
|
|
528
|
-
*/
|
|
529
|
-
getAllClientsInContextGroup({ contextGroupId }) {
|
|
530
|
-
this.wire.sendAction('interop-broker-get-all-clients-in-context-group').catch((e) => {
|
|
531
|
-
// don't expose, analytics-only call
|
|
532
|
-
});
|
|
533
|
-
const clientsInContextGroup = Array.from(this.interopClients.values())
|
|
534
|
-
.filter((connectedClient) => connectedClient.contextGroupId === contextGroupId)
|
|
535
|
-
.map((subscriptionState) => {
|
|
536
|
-
return subscriptionState.clientIdentity;
|
|
537
|
-
});
|
|
538
|
-
return clientsInContextGroup;
|
|
539
|
-
}
|
|
540
|
-
/**
|
|
541
|
-
* Responsible for launching of applications that can handle a given intent, and delegation of intents to those applications.
|
|
542
|
-
* Must be overridden.
|
|
543
|
-
*
|
|
544
|
-
* @remarks To make this call FDC3-Compliant it would need to return an IntentResolution.
|
|
545
|
-
*
|
|
546
|
-
* ```js
|
|
547
|
-
* interface IntentResolution {
|
|
548
|
-
* source: TargetApp;
|
|
549
|
-
* // deprecated, not assignable from intent listeners
|
|
550
|
-
* data?: object;
|
|
551
|
-
* version: string;
|
|
552
|
-
* }
|
|
553
|
-
* ```
|
|
554
|
-
*
|
|
555
|
-
* More information on the IntentResolution type can be found in the [FDC3 documentation](https://fdc3.finos.org/docs/api/ref/IntentResolution).
|
|
556
|
-
*
|
|
557
|
-
* @param intent The combination of an action and a context that is passed to an application for resolution.
|
|
558
|
-
* @param clientIdentity Identity of the Client making the request.
|
|
559
|
-
*
|
|
560
|
-
* @example
|
|
561
|
-
* ```js
|
|
562
|
-
* // override call so we set intent target and create view that will handle it
|
|
563
|
-
* fin.Platform.init({
|
|
564
|
-
* interopOverride: async (InteropBroker) => {
|
|
565
|
-
* class Override extends InteropBroker {
|
|
566
|
-
* async handleFiredIntent(intent) {
|
|
567
|
-
* super.setIntentTarget(intent, { uuid: 'platform-uuid', name: 'intent-view' });
|
|
568
|
-
* const platform = fin.Platform.getCurrentSync();
|
|
569
|
-
* const win = fin.Window.wrapSync({ name: 'foo', uuid: 'platform-uuid' });
|
|
570
|
-
* const createdView = await platform.createView({ url: 'http://openfin.co', name: 'intent-view' }, win.identity);
|
|
571
|
-
* }
|
|
572
|
-
* }
|
|
573
|
-
* return new Override();
|
|
574
|
-
* }
|
|
575
|
-
* });
|
|
576
|
-
* ```
|
|
577
|
-
*/
|
|
578
|
-
// eslint-disable-next-line class-methods-use-this
|
|
579
|
-
async handleFiredIntent(intent, clientIdentity) {
|
|
580
|
-
const warning = (0, utils_1.generateOverrideWarning)('fdc3.raiseIntent', 'InteropBroker.handleFiredIntent', clientIdentity, 'interopClient.fireIntent');
|
|
581
|
-
console.warn(warning);
|
|
582
|
-
throw new Error(utils_1.BROKER_ERRORS.fireIntent);
|
|
583
|
-
}
|
|
584
|
-
/**
|
|
585
|
-
* Should be called in {@link InteropBroker#handleFiredIntent InteropBroker.handleFiredIntent}.
|
|
586
|
-
* While handleFiredIntent is responsible for launching applications, setIntentTarget is used to tell the InteropBroker which application should receive the intent when it is ready.
|
|
587
|
-
* @param intent The combination of an action and a context that is passed to an application for resolution.
|
|
588
|
-
* @param target - Identity of the target that will handle the intent.
|
|
589
|
-
*
|
|
590
|
-
*/
|
|
591
|
-
async setIntentTarget(intent, target) {
|
|
592
|
-
this.wire.sendAction('interop-broker-set-intent-target').catch((e) => {
|
|
593
|
-
// don't expose, this is only for api analytics purposes
|
|
594
|
-
});
|
|
595
|
-
const targetInfo = this.intentClientMap.get(target.name);
|
|
596
|
-
const handlerId = `intent-handler-${intent.name}`;
|
|
597
|
-
if (!targetInfo) {
|
|
598
|
-
this.intentClientMap.set(target.name, new Map());
|
|
599
|
-
const newHandlerInfoMap = this.intentClientMap.get(target.name);
|
|
600
|
-
if (newHandlerInfoMap) {
|
|
601
|
-
newHandlerInfoMap.set(handlerId, { isReady: false, pendingIntents: [intent] });
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
else {
|
|
605
|
-
const handlerInfo = targetInfo.get(handlerId);
|
|
606
|
-
if (!handlerInfo) {
|
|
607
|
-
targetInfo.set(handlerId, { isReady: false, pendingIntents: [intent] });
|
|
608
|
-
}
|
|
609
|
-
else {
|
|
610
|
-
handlerInfo.pendingIntents.push(intent);
|
|
611
|
-
if (handlerInfo.clientIdentity && handlerInfo.isReady) {
|
|
612
|
-
const { clientIdentity, pendingIntents } = handlerInfo;
|
|
613
|
-
try {
|
|
614
|
-
const intentToSend = pendingIntents[pendingIntents.length - 1];
|
|
615
|
-
await this.invokeIntentHandler(clientIdentity, handlerId, intentToSend);
|
|
616
|
-
handlerInfo.pendingIntents = [];
|
|
617
|
-
}
|
|
618
|
-
catch (error) {
|
|
619
|
-
console.error(`Error invoking intent handler for client ${clientIdentity.uuid}/${clientIdentity.name}/${clientIdentity.endpointId}`);
|
|
620
|
-
handlerInfo.isReady = false;
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
/**
|
|
627
|
-
* Responsible for returning information on a particular Intent.
|
|
628
|
-
*
|
|
629
|
-
* @remarks Whenever InteropClient.getInfoForIntent is called this function will fire. The options argument gives you
|
|
630
|
-
* access to the intent name and any optional context that was passed and clientIdentity is the identity of the client
|
|
631
|
-
* that made the call. Ideally here you would fetch the info for the intent and return it with the shape that the
|
|
632
|
-
* InteropClient.getInfoForIntent call is expecting.
|
|
633
|
-
*
|
|
634
|
-
* To make this call FDC3-Compliant it would need to return an App Intent:
|
|
635
|
-
*
|
|
636
|
-
* ```js
|
|
637
|
-
* // {
|
|
638
|
-
* // intent: { name: "StartChat", displayName: "Chat" },
|
|
639
|
-
* // apps: [{ name: "Skype" }, { name: "Symphony" }, { name: "Slack" }]
|
|
640
|
-
* // }
|
|
641
|
-
* ```
|
|
642
|
-
*
|
|
643
|
-
* More information on the AppIntent type can be found in the [FDC3 documentation](https://fdc3.finos.org/docs/api/ref/AppIntent).
|
|
644
|
-
*
|
|
645
|
-
* @param options
|
|
646
|
-
* @param clientIdentity Identity of the Client making the request.
|
|
647
|
-
*
|
|
648
|
-
* @example
|
|
649
|
-
* ```js
|
|
650
|
-
* fin.Platform.init({
|
|
651
|
-
* interopOverride: async (InteropBroker) => {
|
|
652
|
-
* class Override extends InteropBroker {
|
|
653
|
-
* async handleInfoForIntent(options, clientIdentity) {
|
|
654
|
-
* // Your code goes here.
|
|
655
|
-
* }
|
|
656
|
-
* }
|
|
657
|
-
* return new Override();
|
|
658
|
-
* }
|
|
659
|
-
* });
|
|
660
|
-
* ```
|
|
661
|
-
*/
|
|
662
|
-
// eslint-disable-next-line class-methods-use-this
|
|
663
|
-
async handleInfoForIntent(options, clientIdentity) {
|
|
664
|
-
const warning = (0, utils_1.generateOverrideWarning)('fdc3.findIntent', 'InteropBroker.handleInfoForIntent', clientIdentity, 'interopClient.getInfoForIntent');
|
|
665
|
-
console.warn(warning);
|
|
666
|
-
throw new Error(utils_1.BROKER_ERRORS.getInfoForIntent);
|
|
667
|
-
}
|
|
668
|
-
/**
|
|
669
|
-
* Responsible for returning information on which Intents are meant to handle a specific Context.
|
|
670
|
-
* Must be overridden.
|
|
671
|
-
*
|
|
672
|
-
* @remarks Responsible for returning information on which Intents are meant to handle a specific Context. Must be overridden.
|
|
673
|
-
*
|
|
674
|
-
* Whenever InteropClient.getInfoForIntentsByContext is called this function will fire. The context argument gives you access to the context that the client wants information on and clientIdentity is the identity of the client that made the call. Ideally here you would fetch the info for any intent that can handle and return it with the shape that the InteropClient.getInfoForIntentsByContext call is expecting.
|
|
675
|
-
*
|
|
676
|
-
* To make this call FDC3-Compliant it would need to return an array of AppIntents:
|
|
677
|
-
*
|
|
678
|
-
* ```js
|
|
679
|
-
* // [{
|
|
680
|
-
* // intent: { name: "StartCall", displayName: "Call" },
|
|
681
|
-
* // apps: [{ name: "Skype" }]
|
|
682
|
-
* // },
|
|
683
|
-
* // {
|
|
684
|
-
* // intent: { name: "StartChat", displayName: "Chat" },
|
|
685
|
-
* // apps: [{ name: "Skype" }, { name: "Symphony" }, { name: "Slack" }]
|
|
686
|
-
* // }];
|
|
687
|
-
* ```
|
|
688
|
-
*
|
|
689
|
-
* More information on the AppIntent type can be found in the [FDC3 documentation](https://fdc3.finos.org/docs/api/ref/AppIntent).
|
|
690
|
-
*
|
|
691
|
-
* @param context Data passed between entities and applications.
|
|
692
|
-
* @param clientIdentity Identity of the Client making the request.
|
|
693
|
-
*
|
|
694
|
-
* @example
|
|
695
|
-
* ```js
|
|
696
|
-
* fin.Platform.init({
|
|
697
|
-
* interopOverride: async (InteropBroker) => {
|
|
698
|
-
* class Override extends InteropBroker {
|
|
699
|
-
* async handleInfoForIntentsByContext(context, clientIdentity) {
|
|
700
|
-
* // Your code goes here.
|
|
701
|
-
* }
|
|
702
|
-
* }
|
|
703
|
-
* return new Override();
|
|
704
|
-
* }
|
|
705
|
-
* });
|
|
706
|
-
* ```
|
|
707
|
-
*/
|
|
708
|
-
// eslint-disable-next-line class-methods-use-this
|
|
709
|
-
async handleInfoForIntentsByContext(context, clientIdentity) {
|
|
710
|
-
const warning = (0, utils_1.generateOverrideWarning)('fdc3.findIntentsByContext', 'InteropBroker.handleInfoForIntentsByContext', clientIdentity, 'interopClient.getInfoForIntentsByContext');
|
|
711
|
-
console.warn(warning);
|
|
712
|
-
throw new Error(utils_1.BROKER_ERRORS.getInfoForIntentsByContext);
|
|
713
|
-
}
|
|
714
|
-
/**
|
|
715
|
-
* Responsible for resolving an Intent based on a specific Context.
|
|
716
|
-
* Must be overridden.
|
|
717
|
-
*
|
|
718
|
-
* @remarks Whenever InteropClient.fireIntentForContext is called this function will fire. The contextForIntent argument
|
|
719
|
-
* gives you access to the context that will be resolved to an intent. It also can optionally contain any metadata relevant
|
|
720
|
-
* to resolving it, like a specific app the client wants the context to be handled by. The clientIdentity is the identity
|
|
721
|
-
* of the client that made the call.
|
|
722
|
-
*
|
|
723
|
-
* To make this call FDC3-Compliant it would need to return an IntentResolution:
|
|
724
|
-
*
|
|
725
|
-
* ```js
|
|
726
|
-
* // {
|
|
727
|
-
* // intent: { name: "StartChat", displayName: "Chat" },
|
|
728
|
-
* // apps: [{ name: "Skype" }, { name: "Symphony" }, { name: "Slack" }]
|
|
729
|
-
* // }
|
|
730
|
-
* ```
|
|
731
|
-
*
|
|
732
|
-
* More information on the IntentResolution type can be found in the [FDC3 documentation](https://fdc3.finos.org/docs/api/ref/IntentResolution).
|
|
733
|
-
*
|
|
734
|
-
* @param contextForIntent Data passed between entities and applications.
|
|
735
|
-
* @param clientIdentity Identity of the Client making the request.
|
|
736
|
-
*
|
|
737
|
-
* @example
|
|
738
|
-
* ```js
|
|
739
|
-
* fin.Platform.init({
|
|
740
|
-
* interopOverride: async (InteropBroker) => {
|
|
741
|
-
* class Override extends InteropBroker {
|
|
742
|
-
* async handleFiredIntentForContext(contextForIntent, clientIdentity) {
|
|
743
|
-
* // Your code goes here.
|
|
744
|
-
* }
|
|
745
|
-
* }
|
|
746
|
-
* return new Override();
|
|
747
|
-
* }
|
|
748
|
-
* });
|
|
749
|
-
* ```
|
|
750
|
-
*/
|
|
751
|
-
// eslint-disable-next-line class-methods-use-this
|
|
752
|
-
async handleFiredIntentForContext(contextForIntent, clientIdentity) {
|
|
753
|
-
const warning = (0, utils_1.generateOverrideWarning)('fdc3.raiseIntentForContext', 'InteropBroker.handleFiredIntentForContext', clientIdentity, 'interopClient.fireIntentForContext');
|
|
754
|
-
console.warn(warning);
|
|
755
|
-
throw new Error(utils_1.BROKER_ERRORS.fireIntentForContext);
|
|
756
|
-
}
|
|
757
|
-
/**
|
|
758
|
-
* Provides the identity of any Interop Client that disconnects from the Interop Broker. It is meant to be overriden.
|
|
759
|
-
* @param clientIdentity
|
|
760
|
-
*
|
|
761
|
-
* @example
|
|
762
|
-
* ```js
|
|
763
|
-
* fin.Platform.init({
|
|
764
|
-
* interopOverride: async (InteropBroker) => {
|
|
765
|
-
* class Override extends InteropBroker {
|
|
766
|
-
* async clientDisconnected(clientIdentity) {
|
|
767
|
-
* const { uuid, name } = clientIdentity;
|
|
768
|
-
* console.log(`Client with identity ${uuid}/${name} has been disconnected`);
|
|
769
|
-
* }
|
|
770
|
-
* }
|
|
771
|
-
* return new Override();
|
|
772
|
-
* }
|
|
773
|
-
* });
|
|
774
|
-
* ```
|
|
775
|
-
*/
|
|
776
|
-
// eslint-disable-next-line class-methods-use-this
|
|
777
|
-
async clientDisconnected(clientIdentity) {
|
|
778
|
-
// This function is called in channel.onDisconnection.
|
|
779
|
-
// It is meant to be overridden to inform when an Interop Client has been disconnected.
|
|
780
|
-
}
|
|
781
|
-
/**
|
|
782
|
-
* Responsible for resolving an fdc3.open call.
|
|
783
|
-
* Must be overridden.
|
|
784
|
-
* @param fdc3OpenOptions fdc3.open options
|
|
785
|
-
* @param clientIdentity Identity of the Client making the request.
|
|
786
|
-
*/
|
|
787
|
-
// eslint-disable-next-line class-methods-use-this
|
|
788
|
-
async fdc3HandleOpen({ app, context }, clientIdentity) {
|
|
789
|
-
const warning = (0, utils_1.generateOverrideWarning)('fdc3.open', 'InteropBroker.fdc3HandleOpen', clientIdentity);
|
|
790
|
-
console.warn(warning);
|
|
791
|
-
throw new Error(utils_1.BROKER_ERRORS.fdc3Open);
|
|
792
|
-
}
|
|
793
|
-
/**
|
|
794
|
-
* Responsible for resolving the fdc3.findInstances call.
|
|
795
|
-
* Must be overridden
|
|
796
|
-
* @param app AppIdentifier that was passed to fdc3.findInstances
|
|
797
|
-
* @param clientIdentity Identity of the Client making the request.
|
|
798
|
-
*/
|
|
799
|
-
// eslint-disable-next-line class-methods-use-this
|
|
800
|
-
async fdc3HandleFindInstances(app, clientIdentity) {
|
|
801
|
-
const warning = (0, utils_1.generateOverrideWarning)('fdc3.open', 'InteropBroker.fdc3HandleFindInstances', clientIdentity);
|
|
802
|
-
console.warn(warning);
|
|
803
|
-
throw new Error(utils_1.BROKER_ERRORS.fdc3FindInstances);
|
|
804
|
-
}
|
|
805
|
-
/**
|
|
806
|
-
* Responsible for resolving the fdc3.getAppMetadata call.
|
|
807
|
-
* Must be overridden
|
|
808
|
-
* @param app AppIdentifier that was passed to fdc3.getAppMetadata
|
|
809
|
-
* @param clientIdentity Identity of the Client making the request.
|
|
810
|
-
*/
|
|
811
|
-
// eslint-disable-next-line class-methods-use-this
|
|
812
|
-
async fdc3HandleGetAppMetadata(app, clientIdentity) {
|
|
813
|
-
const warning = (0, utils_1.generateOverrideWarning)('fdc3.getAppMetadata', 'InteropBroker.fdc3HandleGetAppMetadata', clientIdentity);
|
|
814
|
-
console.warn(warning);
|
|
815
|
-
throw new Error(utils_1.BROKER_ERRORS.fdc3GetAppMetadata);
|
|
816
|
-
}
|
|
817
|
-
/**
|
|
818
|
-
* This function is called by the Interop Broker whenever a Context handler would fire.
|
|
819
|
-
* For FDC3 2.0 you would need to override this function and add the contextMetadata as
|
|
820
|
-
* part of the Context object. Then would you need to call
|
|
821
|
-
* super.invokeContextHandler passing it this new Context object along with the clientIdentity and handlerId
|
|
822
|
-
* @param clientIdentity
|
|
823
|
-
* @param handlerId
|
|
824
|
-
* @param context
|
|
825
|
-
*
|
|
826
|
-
* @example
|
|
827
|
-
* ```js
|
|
828
|
-
* fin.Platform.init({
|
|
829
|
-
* interopOverride: async (InteropBroker) => {
|
|
830
|
-
* class Override extends InteropBroker {
|
|
831
|
-
* async invokeContextHandler(options, clientIdentity) {
|
|
832
|
-
* return super.invokeContextHandler(clientIdentity, handlerId, {
|
|
833
|
-
* ...context,
|
|
834
|
-
* contextMetadata: {
|
|
835
|
-
* source: {
|
|
836
|
-
* appId: 'openfin-app',
|
|
837
|
-
* instanceId: '3D54D456D9HT0'
|
|
838
|
-
* }
|
|
839
|
-
* }
|
|
840
|
-
* });
|
|
841
|
-
* }
|
|
842
|
-
* }
|
|
843
|
-
* return new Override();
|
|
844
|
-
* }
|
|
845
|
-
* });
|
|
846
|
-
* ```
|
|
847
|
-
*/
|
|
848
|
-
async invokeContextHandler(clientIdentity, handlerId, context) {
|
|
849
|
-
const provider = await this.getProvider();
|
|
850
|
-
try {
|
|
851
|
-
await provider.dispatch(clientIdentity, handlerId, context);
|
|
852
|
-
}
|
|
853
|
-
catch (error) {
|
|
854
|
-
console.error(`Error invoking context handler ${handlerId} for context type ${context.type} in client ${clientIdentity.uuid}/${clientIdentity.name}/${clientIdentity.endpointId}`, error);
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
/**
|
|
858
|
-
* This function is called by the Interop Broker whenever an Intent handler would fire.
|
|
859
|
-
* For FDC3 2.0 you would need to override this function and add the contextMetadata as
|
|
860
|
-
* part of the Context object inside the Intent object. Then would you need to call
|
|
861
|
-
* super.invokeIntentHandler passing it this new Intent object along with the clientIdentity and handlerId
|
|
862
|
-
* @param ClientIdentity
|
|
863
|
-
* @param handlerId
|
|
864
|
-
* @param context
|
|
865
|
-
*
|
|
866
|
-
* @example
|
|
867
|
-
* ```js
|
|
868
|
-
* fin.Platform.init({
|
|
869
|
-
* interopOverride: async (InteropBroker) => {
|
|
870
|
-
* class Override extends InteropBroker {
|
|
871
|
-
* async invokeIntentHandler(options, clientIdentity) {
|
|
872
|
-
* const { context } = intent;
|
|
873
|
-
* return super.invokeIntentHandler(clientIdentity, handlerId, {
|
|
874
|
-
* ...intent,
|
|
875
|
-
* context: {
|
|
876
|
-
* ...context,
|
|
877
|
-
* contextMetadata: {
|
|
878
|
-
* source: {
|
|
879
|
-
* appId: 'openfin-app',
|
|
880
|
-
* instanceId: '3D54D456D9HT0'
|
|
881
|
-
* }
|
|
882
|
-
* }
|
|
883
|
-
* }
|
|
884
|
-
* });
|
|
885
|
-
* }
|
|
886
|
-
* }
|
|
887
|
-
* return new Override();
|
|
888
|
-
* }
|
|
889
|
-
* });
|
|
890
|
-
* ```
|
|
891
|
-
*/
|
|
892
|
-
async invokeIntentHandler(clientIdentity, handlerId, intent) {
|
|
893
|
-
const provider = await this.getProvider();
|
|
894
|
-
await provider.dispatch(clientIdentity, handlerId, intent);
|
|
895
|
-
}
|
|
896
|
-
/**
|
|
897
|
-
* Responsible for resolving fdc3.getInfo for FDC3 2.0
|
|
898
|
-
* Would need to return the optionalFeatures and appMetadata for the {@link https://fdc3.finos.org/docs/api/ref/Metadata#implementationmetadata ImplementationMetadata}.
|
|
899
|
-
* Must be overridden.
|
|
900
|
-
* @param clientIdentity
|
|
901
|
-
*
|
|
902
|
-
*/
|
|
903
|
-
// eslint-disable-next-line class-methods-use-this
|
|
904
|
-
async fdc3HandleGetInfo(payload, clientIdentity) {
|
|
905
|
-
const { fdc3Version } = payload;
|
|
906
|
-
return {
|
|
907
|
-
fdc3Version,
|
|
908
|
-
provider: 'OpenFin',
|
|
909
|
-
providerVersion: await this.fin.System.getVersion(),
|
|
910
|
-
optionalFeatures: {
|
|
911
|
-
OriginatingAppMetadata: false,
|
|
912
|
-
UserChannelMembershipAPIs: true
|
|
913
|
-
},
|
|
914
|
-
appMetadata: {
|
|
915
|
-
appId: '',
|
|
916
|
-
instanceId: ''
|
|
917
|
-
}
|
|
918
|
-
};
|
|
919
|
-
}
|
|
920
|
-
/**
|
|
921
|
-
* Returns an array of info for each Interop Client connected to the Interop Broker.
|
|
922
|
-
*
|
|
923
|
-
* FDC3 2.0: Use the endpointId in the ClientInfo as the instanceId when generating
|
|
924
|
-
* an AppIdentifier.
|
|
925
|
-
*
|
|
926
|
-
* @remarks FDC3 2.0 Note: When needing an instanceId to generate an AppIdentifier use this call to
|
|
927
|
-
* get the endpointId and use it as the instanceId. In the Example below we override handleFiredIntent
|
|
928
|
-
* and then call super.getAllClientInfo to generate the AppIdentifier for the IntentResolution.
|
|
929
|
-
*
|
|
930
|
-
*
|
|
931
|
-
* @example
|
|
932
|
-
* ```js
|
|
933
|
-
* // FDC3 2.0 Example:
|
|
934
|
-
* fin.Platform.init({
|
|
935
|
-
* interopOverride: async (InteropBroker, ...args) => {
|
|
936
|
-
* class Override extends InteropBroker {
|
|
937
|
-
* async handleFiredIntent(intent) {
|
|
938
|
-
* super.setIntentTarget(intent, { uuid: 'platform-uuid', name: 'intent-view' });
|
|
939
|
-
* const platform = fin.Platform.getCurrentSync();
|
|
940
|
-
* const win = fin.Window.wrapSync({ name: 'foo', uuid: 'platform-uuid' });
|
|
941
|
-
* const createdView = await platform.createView({ url: 'http://openfin.co', name: 'intent-view' }, win.identity);
|
|
942
|
-
*
|
|
943
|
-
* const allClientInfo = await super.getAllClientInfo();
|
|
944
|
-
*
|
|
945
|
-
* const infoForTarget = allClientInfo.find((clientInfo) => {
|
|
946
|
-
* return clientInfo.uuid === 'platform-uuid' && clientInfo.name === 'intent-view';
|
|
947
|
-
* });
|
|
948
|
-
*
|
|
949
|
-
* const source = {
|
|
950
|
-
* appId: 'intent-view',
|
|
951
|
-
* instanceId: infoForTarget.endpointId
|
|
952
|
-
* }
|
|
953
|
-
*
|
|
954
|
-
* return {
|
|
955
|
-
* source,
|
|
956
|
-
* intent: intent.name
|
|
957
|
-
* }
|
|
958
|
-
*
|
|
959
|
-
* }
|
|
960
|
-
* }
|
|
961
|
-
* return new Override(...args);
|
|
962
|
-
* }
|
|
963
|
-
* });
|
|
964
|
-
* ```
|
|
965
|
-
*/
|
|
966
|
-
async getAllClientInfo() {
|
|
967
|
-
const provider = await this.getProvider();
|
|
968
|
-
return provider.getAllClientInfo();
|
|
969
|
-
}
|
|
970
|
-
/*
|
|
971
|
-
Snapshot APIs
|
|
972
|
-
*/
|
|
973
|
-
// Used to save interop broker state in snapshots
|
|
974
|
-
decorateSnapshot(snapshot) {
|
|
975
|
-
return { ...snapshot, interopSnapshotDetails: { contextGroupStates: this.getContextGroupStates() } };
|
|
976
|
-
}
|
|
977
|
-
// Used to restore interop broker state in snapshots.
|
|
978
|
-
applySnapshot(snapshot, options) {
|
|
979
|
-
var _a;
|
|
980
|
-
const contextGroupStates = (_a = snapshot === null || snapshot === void 0 ? void 0 : snapshot.interopSnapshotDetails) === null || _a === void 0 ? void 0 : _a.contextGroupStates;
|
|
981
|
-
if (contextGroupStates) {
|
|
982
|
-
if (!(options === null || options === void 0 ? void 0 : options.closeExistingWindows)) {
|
|
983
|
-
this.updateExistingClients(contextGroupStates);
|
|
984
|
-
}
|
|
985
|
-
this.rehydrateContextGroupStates(contextGroupStates);
|
|
986
|
-
}
|
|
987
|
-
}
|
|
988
|
-
updateExistingClients(contextGroupStates) {
|
|
989
|
-
const clients = this.interopClients;
|
|
990
|
-
clients.forEach((subState) => {
|
|
991
|
-
const { clientIdentity, contextGroupId, contextHandlers } = subState;
|
|
992
|
-
if (contextGroupId) {
|
|
993
|
-
const groupContexts = contextGroupStates[contextGroupId];
|
|
994
|
-
for (const [, context] of Object.entries(groupContexts)) {
|
|
995
|
-
contextHandlers.forEach((contextHandler) => {
|
|
996
|
-
const { handlerId, contextType } = contextHandler;
|
|
997
|
-
if (InteropBroker.isContextTypeCompatible(context.type, contextType)) {
|
|
998
|
-
this.invokeContextHandler(clientIdentity, handlerId, context);
|
|
999
|
-
}
|
|
1000
|
-
});
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
});
|
|
1004
|
-
}
|
|
1005
|
-
// Used to store context group state in snapshots
|
|
1006
|
-
getContextGroupStates() {
|
|
1007
|
-
return InteropBroker.toObject(this.contextGroupsById);
|
|
1008
|
-
}
|
|
1009
|
-
// Used to rehydrate the context state from a snapshot
|
|
1010
|
-
rehydrateContextGroupStates(incomingContextGroupStates) {
|
|
1011
|
-
const contextGroupStates = Object.entries(incomingContextGroupStates);
|
|
1012
|
-
for (const [contextGroupId, contexts] of contextGroupStates) {
|
|
1013
|
-
const contextObjects = Object.entries(contexts);
|
|
1014
|
-
for (const [contextType, context] of contextObjects) {
|
|
1015
|
-
if (this.contextGroupsById.has(contextGroupId)) {
|
|
1016
|
-
const currentContextGroupState = this.contextGroupsById.get(contextGroupId);
|
|
1017
|
-
currentContextGroupState.set(contextType, context);
|
|
1018
|
-
}
|
|
1019
|
-
else {
|
|
1020
|
-
// This logic will change when dynamic context group creation comes in.
|
|
1021
|
-
console.warn(`Attempting to set a context group that isn't in the context group mapping. Skipping context group rehydration for: ${contextGroupId}`);
|
|
1022
|
-
}
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
|
-
}
|
|
1026
|
-
/*
|
|
1027
|
-
Internal Context Handler APIs
|
|
1028
|
-
*/
|
|
1029
|
-
// Used to give context to a client that has registered their context handler
|
|
1030
|
-
contextHandlerRegistered({ contextType, handlerId }, clientIdentity) {
|
|
1031
|
-
const handlerInfo = { contextType, handlerId };
|
|
1032
|
-
const clientState = this.getClientState(clientIdentity);
|
|
1033
|
-
clientState === null || clientState === void 0 ? void 0 : clientState.contextHandlers.set(handlerId, handlerInfo);
|
|
1034
|
-
if (clientState && clientState.contextGroupId) {
|
|
1035
|
-
const { contextGroupId } = clientState;
|
|
1036
|
-
const contextGroupMap = this.contextGroupsById.get(contextGroupId);
|
|
1037
|
-
if (contextType === undefined) {
|
|
1038
|
-
// Send this single handler all of the context, because it accepts all.
|
|
1039
|
-
contextGroupMap.forEach((context, _) => {
|
|
1040
|
-
this.invokeContextHandler(clientIdentity, handlerId, context);
|
|
1041
|
-
});
|
|
1042
|
-
}
|
|
1043
|
-
else if (contextGroupMap.has(contextType)) {
|
|
1044
|
-
const contextForType = contextGroupMap.get(contextType);
|
|
1045
|
-
if (contextForType) {
|
|
1046
|
-
this.invokeContextHandler(clientIdentity, handlerId, contextForType);
|
|
1047
|
-
}
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
}
|
|
1051
|
-
// eslint-disable-next-line class-methods-use-this
|
|
1052
|
-
async intentHandlerRegistered(payload, clientIdentity) {
|
|
1053
|
-
const { handlerId } = payload;
|
|
1054
|
-
const clientIntentInfo = this.intentClientMap.get(clientIdentity.name);
|
|
1055
|
-
const handlerInfo = clientIntentInfo === null || clientIntentInfo === void 0 ? void 0 : clientIntentInfo.get(handlerId);
|
|
1056
|
-
if (!clientIntentInfo) {
|
|
1057
|
-
this.intentClientMap.set(clientIdentity.name, new Map());
|
|
1058
|
-
const newHandlerInfoMap = this.intentClientMap.get(clientIdentity.name);
|
|
1059
|
-
if (newHandlerInfoMap) {
|
|
1060
|
-
newHandlerInfoMap.set(handlerId, { isReady: true, pendingIntents: [], clientIdentity });
|
|
1061
|
-
}
|
|
1062
|
-
}
|
|
1063
|
-
else if (!handlerInfo) {
|
|
1064
|
-
clientIntentInfo.set(handlerId, { isReady: true, pendingIntents: [], clientIdentity });
|
|
1065
|
-
}
|
|
1066
|
-
else {
|
|
1067
|
-
const { pendingIntents } = handlerInfo;
|
|
1068
|
-
handlerInfo.clientIdentity = clientIdentity;
|
|
1069
|
-
handlerInfo.isReady = true;
|
|
1070
|
-
try {
|
|
1071
|
-
if (pendingIntents.length > 0) {
|
|
1072
|
-
const intentToSend = pendingIntents[pendingIntents.length - 1];
|
|
1073
|
-
await this.invokeIntentHandler(clientIdentity, handlerId, intentToSend);
|
|
1074
|
-
handlerInfo.pendingIntents = [];
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
catch (error) {
|
|
1078
|
-
console.error(`Error invoking intent handler: ${handlerId} for client ${clientIdentity.uuid}/${clientIdentity.name}/${clientIdentity.endpointId}`);
|
|
1079
|
-
}
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
|
-
// Used to remove a context handler for a client
|
|
1083
|
-
removeContextHandler({ handlerId }, clientIdentity) {
|
|
1084
|
-
const clientState = this.getClientState(clientIdentity);
|
|
1085
|
-
if (clientState) {
|
|
1086
|
-
clientState.contextHandlers.delete(handlerId);
|
|
1087
|
-
}
|
|
1088
|
-
}
|
|
1089
|
-
handleJoinSessionContextGroup({ sessionContextGroupId }, clientIdentity) {
|
|
1090
|
-
try {
|
|
1091
|
-
if (!sessionContextGroupId) {
|
|
1092
|
-
throw new Error('Failed to join session context group: must specify group id.');
|
|
1093
|
-
}
|
|
1094
|
-
const sessionContextGroup = this.sessionContextGroupMap.get(sessionContextGroupId);
|
|
1095
|
-
if (sessionContextGroup) {
|
|
1096
|
-
sessionContextGroup.registerNewClient(clientIdentity);
|
|
1097
|
-
}
|
|
1098
|
-
else {
|
|
1099
|
-
const newSessionContextGroupBroker = new SessionContextGroupBroker_1.default(this.channel, sessionContextGroupId);
|
|
1100
|
-
newSessionContextGroupBroker.registerNewClient(clientIdentity);
|
|
1101
|
-
this.sessionContextGroupMap.set(sessionContextGroupId, newSessionContextGroupBroker);
|
|
1102
|
-
}
|
|
1103
|
-
return { hasConflict: this.contextGroupsById.has(sessionContextGroupId) };
|
|
1104
|
-
}
|
|
1105
|
-
catch (error) {
|
|
1106
|
-
throw new Error(error);
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
/*
|
|
1110
|
-
Internal Utilties
|
|
1111
|
-
*/
|
|
1112
|
-
// Getter for interop info for a client.
|
|
1113
|
-
getClientState(id) {
|
|
1114
|
-
return this.interopClients.get(id.endpointId);
|
|
1115
|
-
}
|
|
1116
|
-
// Util for getContextGroupStates. Serializes the contextGroupStates object so we can store it.
|
|
1117
|
-
static toObject(map) {
|
|
1118
|
-
const objectFromMap = Object.fromEntries(map);
|
|
1119
|
-
const newObject = {};
|
|
1120
|
-
Object.entries(objectFromMap).forEach(([contextGroupId, contextMap]) => {
|
|
1121
|
-
const newContextObject = Object.fromEntries(contextMap);
|
|
1122
|
-
newObject[contextGroupId] = newContextObject;
|
|
1123
|
-
});
|
|
1124
|
-
return newObject;
|
|
1125
|
-
}
|
|
1126
|
-
static checkContextIntegrity(context) {
|
|
1127
|
-
if (!context) {
|
|
1128
|
-
return { isValid: false, reason: 'No context supplied' };
|
|
1129
|
-
}
|
|
1130
|
-
if (typeof context !== 'object') {
|
|
1131
|
-
return { isValid: false, reason: 'Context must be an Object' };
|
|
1132
|
-
}
|
|
1133
|
-
if (!context.type) {
|
|
1134
|
-
return { isValid: false, reason: 'Context must have a type property' };
|
|
1135
|
-
}
|
|
1136
|
-
if (context.id && typeof context.id !== 'object') {
|
|
1137
|
-
return {
|
|
1138
|
-
isValid: false,
|
|
1139
|
-
reason: 'Context id must be an Object populated with key-value identifiers (if set)'
|
|
1140
|
-
};
|
|
1141
|
-
}
|
|
1142
|
-
if (context.id) {
|
|
1143
|
-
const { id } = context;
|
|
1144
|
-
const keys = Object.keys(id);
|
|
1145
|
-
let foundBadIdentifier = false;
|
|
1146
|
-
if (!keys.length) {
|
|
1147
|
-
return { isValid: false, reason: 'Context id must have at least one key-value identifier' };
|
|
1148
|
-
}
|
|
1149
|
-
keys.forEach((key) => {
|
|
1150
|
-
if (typeof key !== 'string' || typeof id[key] !== 'string') {
|
|
1151
|
-
foundBadIdentifier = true;
|
|
1152
|
-
}
|
|
1153
|
-
});
|
|
1154
|
-
if (foundBadIdentifier) {
|
|
1155
|
-
return { isValid: false, reason: 'Context id key-value identifiers must be of type string' };
|
|
1156
|
-
}
|
|
1157
|
-
}
|
|
1158
|
-
if (context.name && typeof context.name !== 'string') {
|
|
1159
|
-
return { isValid: false, reason: 'Context name must be of string type (if set)' };
|
|
1160
|
-
}
|
|
1161
|
-
return { isValid: true };
|
|
1162
|
-
}
|
|
1163
|
-
// Util to check a client identity.
|
|
1164
|
-
static hasEndpointId(target) {
|
|
1165
|
-
return target.endpointId !== undefined;
|
|
1166
|
-
}
|
|
1167
|
-
// Util to check if we should send a context to a handler.
|
|
1168
|
-
static isContextTypeCompatible(contextType, registeredContextType) {
|
|
1169
|
-
return typeof registeredContextType === 'undefined' || contextType === registeredContextType;
|
|
1170
|
-
}
|
|
1171
|
-
// Setup function for state mapping
|
|
1172
|
-
setContextGroupMap() {
|
|
1173
|
-
// This way, if a user overrides this.getContextGroups, it's reflected in the contextGroupMapping.
|
|
1174
|
-
for (const contextGroupInfo of this.getContextGroups()) {
|
|
1175
|
-
this.contextGroupsById.set(contextGroupInfo.id, new Map());
|
|
1176
|
-
}
|
|
1177
|
-
}
|
|
1178
|
-
async setCurrentContextGroupInClientOptions(clientIdentity, contextGroupId) {
|
|
1179
|
-
const entityInfo = await this.fin.System.getEntityInfo(clientIdentity.uuid, clientIdentity.name);
|
|
1180
|
-
let entity;
|
|
1181
|
-
if (entityInfo.entityType === 'view') {
|
|
1182
|
-
entity = await this.fin.View.wrap(clientIdentity);
|
|
1183
|
-
}
|
|
1184
|
-
else if (entityInfo.entityType === 'window') {
|
|
1185
|
-
entity = await this.fin.Window.wrap(clientIdentity);
|
|
1186
|
-
}
|
|
1187
|
-
if (entity) {
|
|
1188
|
-
await entity.updateOptions({
|
|
1189
|
-
interop: {
|
|
1190
|
-
currentContextGroup: contextGroupId
|
|
1191
|
-
}
|
|
1192
|
-
});
|
|
1193
|
-
}
|
|
1194
|
-
else {
|
|
1195
|
-
console.warn(`Setting Current Context Group: Entity with identity ${clientIdentity.uuid}, ${clientIdentity.name} is not a window or view. It is a ${entityInfo.entityType} instead.`);
|
|
1196
|
-
}
|
|
1197
|
-
}
|
|
1198
|
-
async setupChannelProvider() {
|
|
1199
|
-
try {
|
|
1200
|
-
const channel = await this.getProvider();
|
|
1201
|
-
this.channel = channel;
|
|
1202
|
-
this.wireChannel(channel);
|
|
1203
|
-
}
|
|
1204
|
-
catch (error) {
|
|
1205
|
-
throw new Error(`Error setting up Interop Broker Channel Provider: ${error}`);
|
|
1206
|
-
}
|
|
1207
|
-
}
|
|
1208
|
-
// Setup Channel Connection Logic
|
|
1209
|
-
wireChannel(channel) {
|
|
1210
|
-
channel.onConnection(async (clientIdentity, payload) => {
|
|
1211
|
-
if (!(await this.isConnectionAuthorized(clientIdentity, payload))) {
|
|
1212
|
-
throw new Error(`Connection not authorized for ${clientIdentity.uuid}, ${clientIdentity.name}`);
|
|
1213
|
-
}
|
|
1214
|
-
if (!clientIdentity.endpointId) {
|
|
1215
|
-
throw new Error('Version too old to be compatible with Interop. Please upgrade your runtime to a more recent version.');
|
|
1216
|
-
}
|
|
1217
|
-
const clientSubscriptionState = {
|
|
1218
|
-
contextGroupId: undefined,
|
|
1219
|
-
contextHandlers: new Map(),
|
|
1220
|
-
clientIdentity
|
|
1221
|
-
};
|
|
1222
|
-
// Only allow the client to join a contextGroup that actually exists.
|
|
1223
|
-
if ((payload === null || payload === void 0 ? void 0 : payload.currentContextGroup) && this.contextGroupsById.has(payload.currentContextGroup)) {
|
|
1224
|
-
clientSubscriptionState.contextGroupId = payload === null || payload === void 0 ? void 0 : payload.currentContextGroup;
|
|
1225
|
-
}
|
|
1226
|
-
this.interopClients.set(clientIdentity.endpointId, clientSubscriptionState);
|
|
1227
|
-
});
|
|
1228
|
-
channel.onDisconnection((clientIdentity) => {
|
|
1229
|
-
this.interopClients.delete(clientIdentity.endpointId);
|
|
1230
|
-
const targetInfo = this.intentClientMap.get(clientIdentity.name);
|
|
1231
|
-
if (targetInfo && clientIdentity.uuid === this.fin.me.uuid) {
|
|
1232
|
-
targetInfo.forEach((handler) => {
|
|
1233
|
-
handler.isReady = false;
|
|
1234
|
-
});
|
|
1235
|
-
}
|
|
1236
|
-
this.sessionContextGroupMap.forEach((sessionContextGroup) => {
|
|
1237
|
-
sessionContextGroup.onDisconnection(clientIdentity);
|
|
1238
|
-
});
|
|
1239
|
-
this.clientDisconnected(clientIdentity);
|
|
1240
|
-
});
|
|
1241
|
-
channel.beforeAction(async (action, payload, clientIdentity) => {
|
|
1242
|
-
var _a, _b;
|
|
1243
|
-
if (!(await this.isActionAuthorized(action, payload, clientIdentity))) {
|
|
1244
|
-
throw new Error(`Action (${action}) not authorized for ${clientIdentity.uuid}, ${clientIdentity.name}`);
|
|
1245
|
-
}
|
|
1246
|
-
if ((_b = (_a = this.logging) === null || _a === void 0 ? void 0 : _a.beforeAction) === null || _b === void 0 ? void 0 : _b.enabled) {
|
|
1247
|
-
console.log(action, payload, clientIdentity);
|
|
1248
|
-
}
|
|
1249
|
-
});
|
|
1250
|
-
channel.afterAction((action, payload, clientIdentity) => {
|
|
1251
|
-
var _a, _b;
|
|
1252
|
-
if ((_b = (_a = this.logging) === null || _a === void 0 ? void 0 : _a.afterAction) === null || _b === void 0 ? void 0 : _b.enabled) {
|
|
1253
|
-
console.log(action, payload, clientIdentity);
|
|
1254
|
-
}
|
|
1255
|
-
});
|
|
1256
|
-
// Client functions
|
|
1257
|
-
channel.register('setContext', this.setContext.bind(this));
|
|
1258
|
-
channel.register('fireIntent', this.handleFiredIntent.bind(this));
|
|
1259
|
-
channel.register('getCurrentContext', this.getCurrentContext.bind(this));
|
|
1260
|
-
channel.register('getInfoForIntent', this.handleInfoForIntent.bind(this));
|
|
1261
|
-
channel.register('getInfoForIntentsByContext', this.handleInfoForIntentsByContext.bind(this));
|
|
1262
|
-
channel.register('fireIntentForContext', this.handleFiredIntentForContext.bind(this));
|
|
1263
|
-
// Platform window functions
|
|
1264
|
-
channel.register('getContextGroups', this.getContextGroups.bind(this));
|
|
1265
|
-
channel.register('joinContextGroup', this.joinContextGroup.bind(this));
|
|
1266
|
-
channel.register('removeFromContextGroup', this.removeFromContextGroup.bind(this));
|
|
1267
|
-
channel.register('getAllClientsInContextGroup', this.getAllClientsInContextGroup.bind(this));
|
|
1268
|
-
channel.register('getInfoForContextGroup', this.getInfoForContextGroup.bind(this));
|
|
1269
|
-
// Internal methods
|
|
1270
|
-
channel.register('contextHandlerRegistered', this.contextHandlerRegistered.bind(this));
|
|
1271
|
-
channel.register('intentHandlerRegistered', this.intentHandlerRegistered.bind(this));
|
|
1272
|
-
channel.register('removeContextHandler', this.removeContextHandler.bind(this));
|
|
1273
|
-
channel.register('sessionContextGroup:createIfNeeded', this.handleJoinSessionContextGroup.bind(this));
|
|
1274
|
-
// fdc3 only methods
|
|
1275
|
-
channel.register('fdc3Open', this.fdc3HandleOpen.bind(this));
|
|
1276
|
-
channel.register('fdc3v2FindIntentsByContext', this.handleInfoForIntentsByContext.bind(this));
|
|
1277
|
-
channel.register('fdc3FindInstances', this.fdc3HandleFindInstances.bind(this));
|
|
1278
|
-
channel.register('fdc3GetAppMetadata', this.fdc3HandleGetAppMetadata.bind(this));
|
|
1279
|
-
channel.register('fdc3v2GetInfo', async (payload, clientIdentity) => {
|
|
1280
|
-
return this.fdc3HandleGetInfo.bind(this)(payload, clientIdentity);
|
|
1281
|
-
});
|
|
1282
|
-
channel.register('createPrivateChannelProvider', async (payload) => {
|
|
1283
|
-
const { channelId } = payload;
|
|
1284
|
-
const channelProvider = await this.fin.InterApplicationBus.Channel.create(channelId);
|
|
1285
|
-
PrivateChannelProvider_1.PrivateChannelProvider.init(channelProvider, channelId);
|
|
1286
|
-
});
|
|
1287
|
-
}
|
|
1288
|
-
/**
|
|
1289
|
-
* Can be used to completely prevent a connection. Return false to prevent connections. Allows all connections by default.
|
|
1290
|
-
* @param _id the identity tryinc to connect
|
|
1291
|
-
* @param _connectionPayload optional payload to use in custom implementations, will be undefined by default
|
|
1292
|
-
*/
|
|
1293
|
-
isConnectionAuthorized(_id, _connectionPayload) {
|
|
1294
|
-
this.wire.sendAction('interop-broker-is-connection-authorized').catch((e) => {
|
|
1295
|
-
// don't expose, analytics-only call
|
|
1296
|
-
});
|
|
1297
|
-
return Promise.resolve(true);
|
|
1298
|
-
}
|
|
1299
|
-
/**
|
|
1300
|
-
* Called before every action to check if this entity should be allowed to take the action.
|
|
1301
|
-
* Return false to prevent the action
|
|
1302
|
-
* @param _action the string action to authorize in camel case
|
|
1303
|
-
* @param _payload the data being sent for this action
|
|
1304
|
-
* @param _identity the connection attempting to dispatch this action
|
|
1305
|
-
*/
|
|
1306
|
-
isActionAuthorized(_action, _payload, _identity) {
|
|
1307
|
-
this.wire.sendAction('interop-broker-is-action-authorized').catch((e) => {
|
|
1308
|
-
// don't expose, analytics-only call
|
|
1309
|
-
});
|
|
1310
|
-
return Promise.resolve(true);
|
|
1311
|
-
}
|
|
1312
|
-
}
|
|
1313
|
-
exports.InteropBroker = InteropBroker;
|