@openfin/core 25.68.26
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/LICENSE +13 -0
- package/NOTICE +16 -0
- package/OpenFin.d.ts +1340 -0
- package/README.md +41 -0
- package/docs.README(OLD).md +82 -0
- package/fin.d.ts +4 -0
- package/package.json +33 -0
- package/resources/win/OpenFinRVM.exe +0 -0
- package/src/api/application/Factory.d.ts +145 -0
- package/src/api/application/Factory.js +229 -0
- package/src/api/application/Instance.d.ts +302 -0
- package/src/api/application/Instance.js +412 -0
- package/src/api/application/index.d.ts +3 -0
- package/src/api/application/index.js +15 -0
- package/src/api/base.d.ts +43 -0
- package/src/api/base.js +177 -0
- package/src/api/clipboard/index.d.ts +69 -0
- package/src/api/clipboard/index.js +88 -0
- package/src/api/events/application.d.ts +69 -0
- package/src/api/events/application.js +2 -0
- package/src/api/events/base.d.ts +17 -0
- package/src/api/events/base.js +2 -0
- package/src/api/events/channel.d.ts +10 -0
- package/src/api/events/channel.js +2 -0
- package/src/api/events/emitterMap.d.ts +11 -0
- package/src/api/events/emitterMap.js +35 -0
- package/src/api/events/eventAggregator.d.ts +5 -0
- package/src/api/events/eventAggregator.js +43 -0
- package/src/api/events/externalApplication.d.ts +5 -0
- package/src/api/events/externalApplication.js +2 -0
- package/src/api/events/frame.d.ts +9 -0
- package/src/api/events/frame.js +2 -0
- package/src/api/events/globalHotkey.d.ts +10 -0
- package/src/api/events/globalHotkey.js +2 -0
- package/src/api/events/platform.d.ts +18 -0
- package/src/api/events/platform.js +2 -0
- package/src/api/events/system.d.ts +22 -0
- package/src/api/events/system.js +2 -0
- package/src/api/events/view.d.ts +56 -0
- package/src/api/events/view.js +2 -0
- package/src/api/events/webcontents.d.ts +48 -0
- package/src/api/events/webcontents.js +2 -0
- package/src/api/events/window.d.ts +169 -0
- package/src/api/events/window.js +2 -0
- package/src/api/external-application/Factory.d.ts +26 -0
- package/src/api/external-application/Factory.js +40 -0
- package/src/api/external-application/Instance.d.ts +102 -0
- package/src/api/external-application/Instance.js +109 -0
- package/src/api/external-application/index.d.ts +3 -0
- package/src/api/external-application/index.js +15 -0
- package/src/api/fin.d.ts +49 -0
- package/src/api/fin.js +43 -0
- package/src/api/frame/Factory.d.ts +36 -0
- package/src/api/frame/Factory.js +69 -0
- package/src/api/frame/Instance.d.ts +121 -0
- package/src/api/frame/Instance.js +130 -0
- package/src/api/frame/index.d.ts +3 -0
- package/src/api/frame/index.js +15 -0
- package/src/api/global-hotkey/index.d.ts +38 -0
- package/src/api/global-hotkey/index.js +58 -0
- package/src/api/interappbus/channel/channel.d.ts +26 -0
- package/src/api/interappbus/channel/channel.js +77 -0
- package/src/api/interappbus/channel/channels-docs.d.ts +318 -0
- package/src/api/interappbus/channel/channels-docs.js +376 -0
- package/src/api/interappbus/channel/client.d.ts +22 -0
- package/src/api/interappbus/channel/client.js +84 -0
- package/src/api/interappbus/channel/connection-manager.d.ts +28 -0
- package/src/api/interappbus/channel/connection-manager.js +244 -0
- package/src/api/interappbus/channel/index.d.ts +22 -0
- package/src/api/interappbus/channel/index.js +121 -0
- package/src/api/interappbus/channel/protocols/classic/message-receiver.d.ts +13 -0
- package/src/api/interappbus/channel/protocols/classic/message-receiver.js +73 -0
- package/src/api/interappbus/channel/protocols/classic/strategy.d.ts +22 -0
- package/src/api/interappbus/channel/protocols/classic/strategy.js +84 -0
- package/src/api/interappbus/channel/protocols/combined/strategy.d.ts +20 -0
- package/src/api/interappbus/channel/protocols/combined/strategy.js +58 -0
- package/src/api/interappbus/channel/protocols/index.d.ts +44 -0
- package/src/api/interappbus/channel/protocols/index.js +2 -0
- package/src/api/interappbus/channel/protocols/protocol-manager.d.ts +10 -0
- package/src/api/interappbus/channel/protocols/protocol-manager.js +43 -0
- package/src/api/interappbus/channel/protocols/rtc/endpoint.d.ts +23 -0
- package/src/api/interappbus/channel/protocols/rtc/endpoint.js +135 -0
- package/src/api/interappbus/channel/protocols/rtc/ice-manager.d.ts +30 -0
- package/src/api/interappbus/channel/protocols/rtc/ice-manager.js +131 -0
- package/src/api/interappbus/channel/protocols/rtc/strategy.d.ts +22 -0
- package/src/api/interappbus/channel/protocols/rtc/strategy.js +87 -0
- package/src/api/interappbus/channel/protocols/strategy-types.d.ts +13 -0
- package/src/api/interappbus/channel/protocols/strategy-types.js +2 -0
- package/src/api/interappbus/channel/protocols/strategy.d.ts +15 -0
- package/src/api/interappbus/channel/protocols/strategy.js +2 -0
- package/src/api/interappbus/channel/provider.d.ts +31 -0
- package/src/api/interappbus/channel/provider.js +165 -0
- package/src/api/interappbus/index.d.ts +85 -0
- package/src/api/interappbus/index.js +175 -0
- package/src/api/interop/Factory.d.ts +37 -0
- package/src/api/interop/Factory.js +54 -0
- package/src/api/interop/InteropBroker.d.ts +363 -0
- package/src/api/interop/InteropBroker.js +914 -0
- package/src/api/interop/InteropClient.d.ts +268 -0
- package/src/api/interop/InteropClient.js +450 -0
- package/src/api/interop/SessionContextGroupBroker.d.ts +26 -0
- package/src/api/interop/SessionContextGroupBroker.js +107 -0
- package/src/api/interop/SessionContextGroupClient.d.ts +20 -0
- package/src/api/interop/SessionContextGroupClient.js +85 -0
- package/src/api/interop/fdc3/fdc3-1.2.d.ts +187 -0
- package/src/api/interop/fdc3/fdc3-1.2.js +385 -0
- package/src/api/interop/fdc3/fdc3.js +17 -0
- package/src/api/interop/fdc3/utils.d.ts +6 -0
- package/src/api/interop/fdc3/utils.js +17 -0
- package/src/api/interop/index.d.ts +4 -0
- package/src/api/interop/index.js +16 -0
- package/src/api/interop/utils.d.ts +11 -0
- package/src/api/interop/utils.js +36 -0
- package/src/api/me.d.ts +35 -0
- package/src/api/me.js +60 -0
- package/src/api/platform/Factory.d.ts +109 -0
- package/src/api/platform/Factory.js +188 -0
- package/src/api/platform/Instance.d.ts +122 -0
- package/src/api/platform/Instance.js +299 -0
- package/src/api/platform/common-utils.d.ts +6 -0
- package/src/api/platform/common-utils.js +16 -0
- package/src/api/platform/index.d.ts +3 -0
- package/src/api/platform/index.js +15 -0
- package/src/api/platform/layout/Factory.d.ts +108 -0
- package/src/api/platform/layout/Factory.js +189 -0
- package/src/api/platform/layout/Instance.d.ts +48 -0
- package/src/api/platform/layout/Instance.js +99 -0
- package/src/api/platform/layout/index.d.ts +3 -0
- package/src/api/platform/layout/index.js +15 -0
- package/src/api/platform/layout/shapes.d.ts +11 -0
- package/src/api/platform/layout/shapes.js +2 -0
- package/src/api/snapshot-source/Factory.d.ts +36 -0
- package/src/api/snapshot-source/Factory.js +65 -0
- package/src/api/snapshot-source/Instance.d.ts +30 -0
- package/src/api/snapshot-source/Instance.js +134 -0
- package/src/api/snapshot-source/index.d.ts +3 -0
- package/src/api/snapshot-source/index.js +15 -0
- package/src/api/snapshot-source/utils.d.ts +1 -0
- package/src/api/snapshot-source/utils.js +5 -0
- package/src/api/system/application.d.ts +6 -0
- package/src/api/system/application.js +2 -0
- package/src/api/system/entity.d.ts +11 -0
- package/src/api/system/entity.js +2 -0
- package/src/api/system/index.d.ts +957 -0
- package/src/api/system/index.js +1241 -0
- package/src/api/system/installedApps.d.ts +6 -0
- package/src/api/system/installedApps.js +2 -0
- package/src/api/system/log.d.ts +11 -0
- package/src/api/system/log.js +2 -0
- package/src/api/system/process.d.ts +15 -0
- package/src/api/system/process.js +2 -0
- package/src/api/system/proxy.d.ts +15 -0
- package/src/api/system/proxy.js +2 -0
- package/src/api/system/queryPermissionTypes.d.ts +1 -0
- package/src/api/system/queryPermissionTypes.js +2 -0
- package/src/api/system/registry-info.d.ts +7 -0
- package/src/api/system/registry-info.js +2 -0
- package/src/api/system/window.d.ts +16 -0
- package/src/api/system/window.js +2 -0
- package/src/api/view/Factory.d.ts +49 -0
- package/src/api/view/Factory.js +103 -0
- package/src/api/view/Instance.d.ts +379 -0
- package/src/api/view/Instance.js +415 -0
- package/src/api/view/index.d.ts +3 -0
- package/src/api/view/index.js +15 -0
- package/src/api/webcontents/main.d.ts +36 -0
- package/src/api/webcontents/main.js +82 -0
- package/src/api/window/Factory.d.ts +44 -0
- package/src/api/window/Factory.js +91 -0
- package/src/api/window/Instance.d.ts +966 -0
- package/src/api/window/Instance.js +1202 -0
- package/src/api/window/bounds-changed.d.ts +10 -0
- package/src/api/window/bounds-changed.js +6 -0
- package/src/api/window/index.d.ts +5 -0
- package/src/api/window/index.js +17 -0
- package/src/api/window/shapes.d.ts +13 -0
- package/src/api/window/shapes.js +2 -0
- package/src/environment/environment.d.ts +28 -0
- package/src/environment/environment.js +4 -0
- package/src/environment/node-env.d.ts +25 -0
- package/src/environment/node-env.js +64 -0
- package/src/environment/openfin-env.d.ts +29 -0
- package/src/environment/openfin-env.js +105 -0
- package/src/mock.d.ts +4 -0
- package/src/mock.js +91 -0
- package/src/shapes/ERROR_BOX_TYPES.d.ts +6 -0
- package/src/shapes/ERROR_BOX_TYPES.js +10 -0
- package/src/shapes/EntityType.d.ts +1 -0
- package/src/shapes/EntityType.js +2 -0
- package/src/shapes/LayoutPresetType.d.ts +1 -0
- package/src/shapes/LayoutPresetType.js +2 -0
- package/src/shapes/Platform.d.ts +112 -0
- package/src/shapes/Platform.js +16 -0
- package/src/shapes/WebOptions.d.ts +12 -0
- package/src/shapes/WebOptions.js +2 -0
- package/src/shapes/WindowOptions.d.ts +42 -0
- package/src/shapes/WindowOptions.js +2 -0
- package/src/shapes/protocol.d.ts +178 -0
- package/src/shapes/protocol.js +2 -0
- package/src/transport/fin_store.d.ts +4 -0
- package/src/transport/fin_store.js +16 -0
- package/src/transport/transport-errors.d.ts +17 -0
- package/src/transport/transport-errors.js +39 -0
- package/src/transport/transport.d.ts +57 -0
- package/src/transport/transport.js +195 -0
- package/src/transport/wire.d.ts +76 -0
- package/src/transport/wire.js +39 -0
- package/src/util/asyncFilter.d.ts +1 -0
- package/src/util/asyncFilter.js +7 -0
- package/src/util/errors.d.ts +9 -0
- package/src/util/errors.js +14 -0
- package/src/util/exhaustive.d.ts +1 -0
- package/src/util/exhaustive.js +7 -0
- package/src/util/http.d.ts +11 -0
- package/src/util/http.js +83 -0
- package/src/util/normalize-config.d.ts +3 -0
- package/src/util/normalize-config.js +47 -0
- package/src/util/promises.d.ts +5 -0
- package/src/util/promises.js +27 -0
- package/src/util/ref-counter.d.ts +7 -0
- package/src/util/ref-counter.js +51 -0
- package/src/util/runtimeVersioning.d.ts +3 -0
- package/src/util/runtimeVersioning.js +25 -0
- package/src/util/utilTypes.d.ts +8 -0
- package/src/util/utilTypes.js +2 -0
- package/src/util/validate.d.ts +3 -0
- package/src/util/validate.js +11 -0
|
@@ -0,0 +1,914 @@
|
|
|
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
|
+
let contextGroups = [
|
|
8
|
+
{
|
|
9
|
+
id: 'green',
|
|
10
|
+
displayMetadata: {
|
|
11
|
+
color: '#00CC88',
|
|
12
|
+
name: 'green'
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
id: 'purple',
|
|
17
|
+
displayMetadata: {
|
|
18
|
+
color: '#8C61FF',
|
|
19
|
+
name: 'purple'
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: 'orange',
|
|
24
|
+
displayMetadata: {
|
|
25
|
+
color: '#FF8C4C',
|
|
26
|
+
name: 'orange'
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
id: 'red',
|
|
31
|
+
displayMetadata: {
|
|
32
|
+
color: '#FF5E60',
|
|
33
|
+
name: 'red'
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
id: 'pink',
|
|
38
|
+
displayMetadata: {
|
|
39
|
+
color: '#FF8FB8',
|
|
40
|
+
name: 'pink'
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
id: 'yellow',
|
|
45
|
+
displayMetadata: {
|
|
46
|
+
color: '#E9FF8F',
|
|
47
|
+
name: 'yellow'
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
];
|
|
51
|
+
/**
|
|
52
|
+
* {@link https://developers.openfin.co/of-docs/docs/enable-color-linking **THE INTEROP API IS EXPERIMENTAL. IF YOU WOULD LIKE TO USE IT, PLEASE USE OUR DEFAULT IMPLEMENTATION IN BROWSER**}
|
|
53
|
+
*
|
|
54
|
+
* The Interop Broker is responsible for keeping track of the Interop state of the Platform, and for directing messages to the proper locations.
|
|
55
|
+
*
|
|
56
|
+
* ---
|
|
57
|
+
*
|
|
58
|
+
* There are 2 ways to inject custom functionality into the Interop Broker:
|
|
59
|
+
*
|
|
60
|
+
* **1. Configuration**
|
|
61
|
+
*
|
|
62
|
+
* 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.
|
|
63
|
+
* ```js
|
|
64
|
+
* {
|
|
65
|
+
* "runtime": {
|
|
66
|
+
* "arguments": "--v=1 --inspect",
|
|
67
|
+
* "version": "alpha-v19"
|
|
68
|
+
* },
|
|
69
|
+
* "platform": {
|
|
70
|
+
* "uuid": "platform_customization_local",
|
|
71
|
+
* "applicationIcon": "https://openfin.github.io/golden-prototype/favicon.ico",
|
|
72
|
+
* "autoShow": false,
|
|
73
|
+
* "providerUrl": "http://localhost:5555/provider.html",
|
|
74
|
+
* "interopBrokerConfiguration": {
|
|
75
|
+
* "contextGroups": [
|
|
76
|
+
* {
|
|
77
|
+
* "id": "green",
|
|
78
|
+
* "displayMetadata": {
|
|
79
|
+
* "color": "#00CC88",
|
|
80
|
+
* "name": "green"
|
|
81
|
+
* }
|
|
82
|
+
* },
|
|
83
|
+
* {
|
|
84
|
+
* "id": "purple",
|
|
85
|
+
* "displayMetadata": {
|
|
86
|
+
* "color": "#8C61FF",
|
|
87
|
+
* "name": "purple"
|
|
88
|
+
* }
|
|
89
|
+
* },
|
|
90
|
+
* ]
|
|
91
|
+
* }
|
|
92
|
+
* }
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* ---
|
|
97
|
+
* **2. Overriding**
|
|
98
|
+
*
|
|
99
|
+
* Similarly to how [Platform Overriding]{@link https://developers.openfin.co/docs/platform-customization#section-customizing-platform-behavior} 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.
|
|
100
|
+
*
|
|
101
|
+
* 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.
|
|
102
|
+
*
|
|
103
|
+
* ```js
|
|
104
|
+
* fin.Platform.init({
|
|
105
|
+
* overrideCallback: async (Provider) => {
|
|
106
|
+
* class Override extends Provider {
|
|
107
|
+
* async getSnapshot() {
|
|
108
|
+
* console.log('before getSnapshot')
|
|
109
|
+
* const snapshot = await super.getSnapshot();
|
|
110
|
+
* console.log('after getSnapshot')
|
|
111
|
+
* return snapshot;
|
|
112
|
+
* }
|
|
113
|
+
*
|
|
114
|
+
* async applySnapshot({ snapshot, options }) {
|
|
115
|
+
* console.log('before applySnapshot')
|
|
116
|
+
* const originalPromise = super.applySnapshot({ snapshot, options });
|
|
117
|
+
* console.log('after applySnapshot')
|
|
118
|
+
*
|
|
119
|
+
* return originalPromise;
|
|
120
|
+
* }
|
|
121
|
+
* };
|
|
122
|
+
* return new Override();
|
|
123
|
+
* },
|
|
124
|
+
* interopOverride: async (InteropBroker, provider, options, ...args) => {
|
|
125
|
+
* class Override extends InteropBroker {
|
|
126
|
+
* async joinContextGroup(channelName = 'default', target) {
|
|
127
|
+
* console.log('before super joinContextGroup')
|
|
128
|
+
* super.joinContextGroup(channelName, target);
|
|
129
|
+
* console.log('after super joinContextGroup')
|
|
130
|
+
* }
|
|
131
|
+
* }
|
|
132
|
+
*
|
|
133
|
+
* options.contextGroups = [
|
|
134
|
+
* {
|
|
135
|
+
* id: 'green',
|
|
136
|
+
* displayMetadata: {
|
|
137
|
+
* color: '#00CC88',
|
|
138
|
+
* name: 'green'
|
|
139
|
+
* }
|
|
140
|
+
* },
|
|
141
|
+
* {
|
|
142
|
+
* id: 'purple',
|
|
143
|
+
* displayMetadata: {
|
|
144
|
+
* color: '#8C61FF',
|
|
145
|
+
* name: 'purple'
|
|
146
|
+
* }
|
|
147
|
+
* },
|
|
148
|
+
* {
|
|
149
|
+
* id: 'orange',
|
|
150
|
+
* displayMetadata: {
|
|
151
|
+
* color: '#FF8C4C',
|
|
152
|
+
* name: 'orange'
|
|
153
|
+
* }
|
|
154
|
+
* },
|
|
155
|
+
* {
|
|
156
|
+
* id: 'red',
|
|
157
|
+
* displayMetadata: {
|
|
158
|
+
* color: '#FF5E60',
|
|
159
|
+
* name: 'red'
|
|
160
|
+
* }
|
|
161
|
+
* }
|
|
162
|
+
* ];
|
|
163
|
+
* return new Override(provider, options, ...args);
|
|
164
|
+
* }
|
|
165
|
+
* });
|
|
166
|
+
* ```
|
|
167
|
+
*
|
|
168
|
+
* ---
|
|
169
|
+
*
|
|
170
|
+
* @hideconstructor
|
|
171
|
+
* @class
|
|
172
|
+
*/
|
|
173
|
+
class InteropBroker extends base_1.Base {
|
|
174
|
+
constructor(wire, channel, options) {
|
|
175
|
+
super(wire);
|
|
176
|
+
this.channel = channel;
|
|
177
|
+
this.interopClients = new Map();
|
|
178
|
+
this.contextGroupsById = new Map();
|
|
179
|
+
if (options.contextGroups) {
|
|
180
|
+
contextGroups = options.contextGroups;
|
|
181
|
+
}
|
|
182
|
+
this.intentClientMap = new Map();
|
|
183
|
+
this.lastContextMap = new Map();
|
|
184
|
+
this.sessionContextGroupMap = new Map();
|
|
185
|
+
this.setContextGroupMap();
|
|
186
|
+
this.wireChannel(channel);
|
|
187
|
+
}
|
|
188
|
+
/*
|
|
189
|
+
Client API
|
|
190
|
+
*/
|
|
191
|
+
/**
|
|
192
|
+
* SetContextOptions interface
|
|
193
|
+
* @typedef { object } SetContextOptions
|
|
194
|
+
* @property { Context } {context} - New context to set.
|
|
195
|
+
*/
|
|
196
|
+
/**
|
|
197
|
+
* GetContextOptions interface
|
|
198
|
+
* @typedef { object } GetContextOptions
|
|
199
|
+
* @property { string } [contextType] - Context Type
|
|
200
|
+
*/
|
|
201
|
+
/**
|
|
202
|
+
* JoinContextGroupOptions interface
|
|
203
|
+
* @typedef { object } JoinContextGroupOptions
|
|
204
|
+
* @property { string } contextGroupId - Id of the context group.
|
|
205
|
+
* @property { Identity | ClientIdentity } [target] - Identity of the entity you wish to join to a context group.
|
|
206
|
+
*/
|
|
207
|
+
/**
|
|
208
|
+
* AddClientToContextGroupOptions interface
|
|
209
|
+
* @typedef { object } AddClientToContextGroupOptions
|
|
210
|
+
* @property { string } contextGroupId - Name of the context group.
|
|
211
|
+
*/
|
|
212
|
+
/**
|
|
213
|
+
* RemoveFromContextGroupOptions interface
|
|
214
|
+
* @typedef { object } RemoveFromContextGroupOptions
|
|
215
|
+
* @property { Identity | ClientIdentity } target - Identity of the entity you wish to join to a context group.
|
|
216
|
+
*/
|
|
217
|
+
/**
|
|
218
|
+
* GetInfoForContextGroupOptions interface
|
|
219
|
+
* @typedef { object } GetInfoForContextGroupOptions
|
|
220
|
+
* @property { string } contextGroupId - Name of the context group to get info for.
|
|
221
|
+
*/
|
|
222
|
+
/**
|
|
223
|
+
* GetAllClientsInContextGroupOptions interface
|
|
224
|
+
* @typedef { object } GetAllClientsInContextGroupOptions
|
|
225
|
+
* @property { string } contextGroupId - Name of the context group to get info for.
|
|
226
|
+
*/
|
|
227
|
+
/**
|
|
228
|
+
* InfoForIntentOptions interface
|
|
229
|
+
* @typedef { object } InfoForIntentOptions
|
|
230
|
+
* @property { string } name Name of the intent to get info for.
|
|
231
|
+
* @property { Context } [context] Optional context.
|
|
232
|
+
*/
|
|
233
|
+
/**
|
|
234
|
+
* Sets a context for the context group of the incoming current entity.
|
|
235
|
+
* @param { SetContextOptions } setContextOptions - New context to set.
|
|
236
|
+
* @param { ClientIdentity } clientIdentity - Identity of the client sender.
|
|
237
|
+
* @return { void }
|
|
238
|
+
* @experimental
|
|
239
|
+
*/
|
|
240
|
+
setContext({ context }, clientIdentity) {
|
|
241
|
+
this.wire.sendAction('interop-broker-set-context').catch((e) => {
|
|
242
|
+
// don't expose, analytics-only call
|
|
243
|
+
});
|
|
244
|
+
const clientState = this.getClientState(clientIdentity);
|
|
245
|
+
if (clientState && clientState.contextGroupId) {
|
|
246
|
+
const { contextGroupId } = clientState;
|
|
247
|
+
if (!this.contextGroupsById.has(contextGroupId)) {
|
|
248
|
+
// Theoretically not possible.
|
|
249
|
+
throw new Error(`Client has a context group that isn't in the context group mapping: ${contextGroupId}.`);
|
|
250
|
+
}
|
|
251
|
+
const contextIntegrityCheckResult = InteropBroker.checkContextIntegrity(context);
|
|
252
|
+
if (contextIntegrityCheckResult.isValid === false) {
|
|
253
|
+
throw new Error(`Failed to set Context - bad Context. Reason: ${contextIntegrityCheckResult.reason}. Context: ${JSON.stringify(context)}`);
|
|
254
|
+
}
|
|
255
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
256
|
+
const contextGroupState = this.contextGroupsById.get(contextGroupId);
|
|
257
|
+
const broadcastedContextType = context.type;
|
|
258
|
+
contextGroupState.set(broadcastedContextType, context);
|
|
259
|
+
this.lastContextMap.set(contextGroupId, broadcastedContextType);
|
|
260
|
+
const clientsInSameContextGroup = Array.from(this.interopClients.values()).filter((connectedClient) => connectedClient.contextGroupId === contextGroupId);
|
|
261
|
+
clientsInSameContextGroup.forEach((client) => {
|
|
262
|
+
for (const [, handlerInfo] of client.contextHandlers) {
|
|
263
|
+
if (InteropBroker.isContextTypeCompatible(broadcastedContextType, handlerInfo.contextType)) {
|
|
264
|
+
this.invokeContextHandler(client.clientIdentity, handlerInfo.handlerId, context);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
else if (clientState) {
|
|
270
|
+
// Client has not joined any context group behavior.
|
|
271
|
+
throw new Error('You must join a context group before you can set context.');
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
// This shouldn't get hit.
|
|
275
|
+
throw new Error(`Client with Identity: ${clientIdentity.uuid} ${clientIdentity.name} not in Client State Map`);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Get current context for a client subscribed to a Context Group.
|
|
280
|
+
* @param { GetContextOptions } getContextOptions - Options for getting context
|
|
281
|
+
* @param { ClientIdentity } clientIdentity - Identity of the client sender.
|
|
282
|
+
* @return { Context }
|
|
283
|
+
*/
|
|
284
|
+
getCurrentContext(getCurrentContextOptions, clientIdentity) {
|
|
285
|
+
var _a;
|
|
286
|
+
this.wire.sendAction('interop-broker-get-current-context').catch((e) => {
|
|
287
|
+
// don't expose, analytics-only call
|
|
288
|
+
});
|
|
289
|
+
const clientState = this.getClientState(clientIdentity);
|
|
290
|
+
if (!(clientState === null || clientState === void 0 ? void 0 : clientState.contextGroupId)) {
|
|
291
|
+
throw new Error('You must be a member of a context group to call getCurrentContext');
|
|
292
|
+
}
|
|
293
|
+
const { contextGroupId } = clientState;
|
|
294
|
+
const contextGroupState = this.contextGroupsById.get(contextGroupId);
|
|
295
|
+
const lastContextType = this.lastContextMap.get(contextGroupId);
|
|
296
|
+
const contextType = (_a = getCurrentContextOptions === null || getCurrentContextOptions === void 0 ? void 0 : getCurrentContextOptions.contextType) !== null && _a !== void 0 ? _a : lastContextType;
|
|
297
|
+
return contextGroupState && contextType ? contextGroupState.get(contextType) : undefined;
|
|
298
|
+
}
|
|
299
|
+
/*
|
|
300
|
+
Platform Window APIs
|
|
301
|
+
*/
|
|
302
|
+
// joinContextGroup and addClientToContextGroup are separate functions here, for easier overrides and separation of concerns.
|
|
303
|
+
// joinContextGroup checks all connections for matching identities, in case we have multiple connection from an entity.
|
|
304
|
+
/**
|
|
305
|
+
* Join all connections at the given identity (or just one if endpointId provided) to context group `contextGroupId`.
|
|
306
|
+
* If no target is specified, it adds the sender to the context group.
|
|
307
|
+
* joinContextGroup is responsible for checking connections at the incoming identity. It calls {@link InteropBroker#addClientToContextGroup InteropBroker.addClientToContextGroup} to actually group the client.
|
|
308
|
+
* Used by Platform Windows.
|
|
309
|
+
* @return { Promise<void> }
|
|
310
|
+
* @param { JoinContextGroupOptions } joinContextGroupOptions - Id of the Context Group and identity of the entity to join to the group.
|
|
311
|
+
* @param { ClientIdentity } senderIdentity - Identity of the client sender.
|
|
312
|
+
* @experimental
|
|
313
|
+
*/
|
|
314
|
+
async joinContextGroup({ contextGroupId, target }, senderIdentity) {
|
|
315
|
+
this.wire.sendAction('interop-broker-join-context-group').catch((e) => {
|
|
316
|
+
// don't expose, analytics-only call
|
|
317
|
+
});
|
|
318
|
+
if (target) {
|
|
319
|
+
// If an endpointId is provided, use that. This will likely be used by external adapters.
|
|
320
|
+
if (InteropBroker.hasEndpointId(target)) {
|
|
321
|
+
await this.addClientToContextGroup({ contextGroupId }, target);
|
|
322
|
+
}
|
|
323
|
+
// Sanity check here in case a single app has multiple connections
|
|
324
|
+
const allConnections = this.channel.connections.filter((x) => x.uuid === target.uuid && x.name === target.name);
|
|
325
|
+
if (!allConnections.length) {
|
|
326
|
+
throw new Error(`Given Identity ${target.uuid} ${target.name} is not connected to the Interop Broker.`);
|
|
327
|
+
}
|
|
328
|
+
if (allConnections.length > 1) {
|
|
329
|
+
// Should figure out how we want to handle this situation. In the meantime, just change context group for all connections.
|
|
330
|
+
console.warn(`More than one connection found for identity ${target.uuid} ${target.name}`);
|
|
331
|
+
}
|
|
332
|
+
const promises = [];
|
|
333
|
+
for (const connection of allConnections) {
|
|
334
|
+
promises.push(this.addClientToContextGroup({ contextGroupId }, connection));
|
|
335
|
+
}
|
|
336
|
+
await Promise.all(promises);
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
// No target provided, add the sender to the context group.
|
|
340
|
+
await this.addClientToContextGroup({ contextGroupId }, senderIdentity);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
// addClientToContextGroup does the actual addition of the client to the Context Group
|
|
344
|
+
/**
|
|
345
|
+
* Helper function for {@link InteropBroker#joinContextGroup InteropBroker.joinContextGroup}. Does the work of actually adding the client to the Context Group.
|
|
346
|
+
* Used by Platform Windows.
|
|
347
|
+
* @return { Promise<void> }
|
|
348
|
+
* @param { AddClientToContextGroupOptions } addClientToContextGroupOptions - Contains the contextGroupId
|
|
349
|
+
* @param { ClientIdentity } clientIdentity - Identity of the client sender.
|
|
350
|
+
* @experimental
|
|
351
|
+
*/
|
|
352
|
+
async addClientToContextGroup({ contextGroupId }, clientIdentity) {
|
|
353
|
+
this.wire.sendAction('interop-broker-add-client-to-context-group').catch((e) => {
|
|
354
|
+
// don't expose, analytics-only call
|
|
355
|
+
});
|
|
356
|
+
const clientSubscriptionState = this.getClientState(clientIdentity);
|
|
357
|
+
if (!clientSubscriptionState) {
|
|
358
|
+
throw new Error(`Client with Identity: ${clientIdentity.uuid} ${clientIdentity.name} not in Client State Map`);
|
|
359
|
+
}
|
|
360
|
+
if (!this.getContextGroups().find((contextGroupInfo) => contextGroupInfo.id === contextGroupId)) {
|
|
361
|
+
throw new Error(`Attempting to join a context group that does not exist: ${contextGroupId}. You may only join existing context groups.`);
|
|
362
|
+
}
|
|
363
|
+
const oldContextGroupId = clientSubscriptionState.contextGroupId;
|
|
364
|
+
if (oldContextGroupId !== contextGroupId) {
|
|
365
|
+
clientSubscriptionState.contextGroupId = contextGroupId;
|
|
366
|
+
await InteropBroker.setCurrentContextGroupInClientOptions(clientIdentity, contextGroupId);
|
|
367
|
+
const contextGroupMap = this.contextGroupsById.get(contextGroupId);
|
|
368
|
+
for (const [, handlerInfo] of clientSubscriptionState.contextHandlers) {
|
|
369
|
+
const { contextType, handlerId } = handlerInfo;
|
|
370
|
+
if (contextType === undefined) {
|
|
371
|
+
// Send this single handler all of the context, because it accepts all.
|
|
372
|
+
contextGroupMap.forEach((context, _) => {
|
|
373
|
+
this.invokeContextHandler(clientIdentity, handlerId, context);
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
else if (contextGroupMap.has(contextType)) {
|
|
377
|
+
const contextForType = contextGroupMap.get(contextType);
|
|
378
|
+
if (contextForType) {
|
|
379
|
+
this.invokeContextHandler(clientIdentity, handlerId, contextForType);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
// Removes the target from its context group. Similar structure to joinContextGroup.
|
|
386
|
+
/**
|
|
387
|
+
* Removes the specified target from a context group.
|
|
388
|
+
* If no target is specified, it removes the sender from their context group.
|
|
389
|
+
* removeFromContextGroup is responsible for checking connections at the incoming identity. It calls {@link InteropBroker#removeClientFromContextGroup InteropBroker.removeClientFromContextGroup} to actually ungroup the client.
|
|
390
|
+
* Used by Platform Windows.
|
|
391
|
+
* @return { Promise<void> }
|
|
392
|
+
* @param { RemoveFromContextGroupOptions } removeFromContextGroupOptions - Contains the target identity to remove.
|
|
393
|
+
* @param { ClientIdentity } senderIdentity - Identity of the client sender.
|
|
394
|
+
* @experimental
|
|
395
|
+
*/
|
|
396
|
+
async removeFromContextGroup({ target }, senderIdentity) {
|
|
397
|
+
this.wire.sendAction('interop-broker-remove-from-context-group').catch((e) => {
|
|
398
|
+
// don't expose, analytics-only call
|
|
399
|
+
});
|
|
400
|
+
if (target) {
|
|
401
|
+
// If an endpointId is provided, use that. This will likely be used by external adapters.
|
|
402
|
+
if (InteropBroker.hasEndpointId(target)) {
|
|
403
|
+
await this.removeClientFromContextGroup(target);
|
|
404
|
+
}
|
|
405
|
+
// Sanity check here in case a single app has multiple connections
|
|
406
|
+
const allConnections = this.channel.connections.filter((x) => x.uuid === target.uuid && x.name === target.name);
|
|
407
|
+
if (!allConnections.length) {
|
|
408
|
+
throw new Error(`No connection found for given Identity ${target.uuid} ${target.name}`);
|
|
409
|
+
}
|
|
410
|
+
if (allConnections.length > 1) {
|
|
411
|
+
console.warn(`More than one connection found for identity ${target.uuid} ${target.name}`);
|
|
412
|
+
}
|
|
413
|
+
const promises = [];
|
|
414
|
+
for (const connection of allConnections) {
|
|
415
|
+
promises.push(this.removeClientFromContextGroup(connection));
|
|
416
|
+
}
|
|
417
|
+
await Promise.all(promises);
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
// No target provided, remove the sender from the context group.
|
|
421
|
+
await this.removeClientFromContextGroup(senderIdentity);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
// removeClientFromContextGroup does the actual remove of the client from the Context Group
|
|
425
|
+
/**
|
|
426
|
+
* Helper function for {@link InteropBroker#removeFromContextGroup InteropBroker.removeFromContextGroup}. Does the work of actually removing the client from the Context Group.
|
|
427
|
+
* Used by Platform Windows.
|
|
428
|
+
* @return { Promise<void> }
|
|
429
|
+
* @property { ClientIdentity } clientIdentity - Identity of the client sender.
|
|
430
|
+
* @experimental
|
|
431
|
+
*/
|
|
432
|
+
async removeClientFromContextGroup(clientIdentity) {
|
|
433
|
+
this.wire.sendAction('interop-broker-remove-client-from-context-group').catch((e) => {
|
|
434
|
+
// don't expose, analytics-only call
|
|
435
|
+
});
|
|
436
|
+
const clientState = this.getClientState(clientIdentity);
|
|
437
|
+
if (clientState) {
|
|
438
|
+
clientState.contextGroupId = undefined;
|
|
439
|
+
}
|
|
440
|
+
await InteropBroker.setCurrentContextGroupInClientOptions(clientIdentity, null);
|
|
441
|
+
}
|
|
442
|
+
// 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.
|
|
443
|
+
/**
|
|
444
|
+
* 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.
|
|
445
|
+
* Used by Platform Windows.
|
|
446
|
+
* @return { Promise<ContextGroupInfo[]>}
|
|
447
|
+
* @experimental
|
|
448
|
+
*/
|
|
449
|
+
// eslint-disable-next-line class-methods-use-this
|
|
450
|
+
getContextGroups() {
|
|
451
|
+
this.wire.sendAction('interop-broker-get-context-groups').catch((e) => {
|
|
452
|
+
// don't expose, analytics-only call
|
|
453
|
+
});
|
|
454
|
+
// Create copy for immutability
|
|
455
|
+
return contextGroups.map((contextGroup) => {
|
|
456
|
+
return { ...contextGroup };
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
// Used to by platform windows to get display metadata for a context group.
|
|
460
|
+
/**
|
|
461
|
+
* Gets display info for a context group
|
|
462
|
+
* Used by Platform Windows.
|
|
463
|
+
* @param { GetInfoForContextGroupOptions } getInfoForContextGroupOptions - Contains contextGroupId, the context group you wish to get display info for.
|
|
464
|
+
* @return { Promise<ContextGroupInfo>}
|
|
465
|
+
* @experimental
|
|
466
|
+
*/
|
|
467
|
+
getInfoForContextGroup({ contextGroupId }) {
|
|
468
|
+
this.wire.sendAction('interop-broker-get-info-for-context-group').catch((e) => {
|
|
469
|
+
// don't expose, analytics-only call
|
|
470
|
+
});
|
|
471
|
+
return this.getContextGroups().find((contextGroup) => contextGroup.id === contextGroupId);
|
|
472
|
+
}
|
|
473
|
+
// Used by platform windows to get all clients for a context group.
|
|
474
|
+
/**
|
|
475
|
+
* Gets all clients for a context group.
|
|
476
|
+
* Used by Platform Windows.
|
|
477
|
+
* @param { GetAllClientsInContextGroupOptions } getAllClientsInContextGroupOptions - Contains contextGroupId, the context group you wish to get clients for.
|
|
478
|
+
* @return { Promise<ClientIdentity[]>}
|
|
479
|
+
* @experimental
|
|
480
|
+
*/
|
|
481
|
+
getAllClientsInContextGroup({ contextGroupId }) {
|
|
482
|
+
this.wire.sendAction('interop-broker-get-all-clients-in-context-group').catch((e) => {
|
|
483
|
+
// don't expose, analytics-only call
|
|
484
|
+
});
|
|
485
|
+
const clientsInContextGroup = Array.from(this.interopClients.values())
|
|
486
|
+
.filter((connectedClient) => connectedClient.contextGroupId === contextGroupId)
|
|
487
|
+
.map((subscriptionState) => {
|
|
488
|
+
return subscriptionState.clientIdentity;
|
|
489
|
+
});
|
|
490
|
+
return clientsInContextGroup;
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Responsible for launching of applications that can handle a given intent, and delegation of intents to those applications.
|
|
494
|
+
* Must be overridden.
|
|
495
|
+
* @param { Intent } intent The combination of an action and a context that is passed to an application for resolution.
|
|
496
|
+
* @param { ClientIdentity } clientIdentity Identity of the Client making the request.
|
|
497
|
+
* @return { Promise<unknown> }
|
|
498
|
+
* @tutorial interop.handleFiredIntent
|
|
499
|
+
* @experimental
|
|
500
|
+
*/
|
|
501
|
+
// eslint-disable-next-line class-methods-use-this
|
|
502
|
+
async handleFiredIntent(intent, clientIdentity) {
|
|
503
|
+
const warning = utils_1.generateOverrideWarning('interopClient.fireIntent', 'fdc3.raiseIntent', 'InteropBroker.handleFiredIntent', clientIdentity);
|
|
504
|
+
console.warn(warning);
|
|
505
|
+
throw new Error(utils_1.BROKER_ERRORS.fireIntent);
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Should be called in {@link InteropBroker#handleFiredIntent InteropBroker.handleFiredIntent}.
|
|
509
|
+
* While handleFiredIntent is responsible for launching applications, setIntentTarget is used to tell the InteropBroker which application should receive the intent when it is ready.
|
|
510
|
+
* @param { Intent } intent The combination of an action and a context that is passed to an application for resolution.
|
|
511
|
+
* @param { Identity } target - Identity of the target that will handle the intent.
|
|
512
|
+
* @return { Promise<void> }
|
|
513
|
+
* @experimental
|
|
514
|
+
*/
|
|
515
|
+
async setIntentTarget(intent, target) {
|
|
516
|
+
this.wire.sendAction('interop-broker-set-intent-target').catch((e) => {
|
|
517
|
+
// don't expose, this is only for api analytics purposes
|
|
518
|
+
});
|
|
519
|
+
const targetInfo = this.intentClientMap.get(target.name);
|
|
520
|
+
const handlerId = `intent-handler-${intent.name}`;
|
|
521
|
+
if (!targetInfo) {
|
|
522
|
+
this.intentClientMap.set(target.name, new Map());
|
|
523
|
+
const newHandlerInfoMap = this.intentClientMap.get(target.name);
|
|
524
|
+
if (newHandlerInfoMap) {
|
|
525
|
+
newHandlerInfoMap.set(handlerId, { isReady: false, pendingIntents: [intent] });
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
const handlerInfo = targetInfo.get(handlerId);
|
|
530
|
+
if (!handlerInfo) {
|
|
531
|
+
targetInfo.set(handlerId, { isReady: false, pendingIntents: [intent] });
|
|
532
|
+
}
|
|
533
|
+
else {
|
|
534
|
+
handlerInfo.pendingIntents.push(intent);
|
|
535
|
+
if (handlerInfo.clientIdentity && handlerInfo.isReady) {
|
|
536
|
+
const { clientIdentity, pendingIntents } = handlerInfo;
|
|
537
|
+
try {
|
|
538
|
+
const intentToSend = pendingIntents[pendingIntents.length - 1];
|
|
539
|
+
await this.channel.dispatch(clientIdentity, handlerId, intentToSend);
|
|
540
|
+
handlerInfo.pendingIntents = [];
|
|
541
|
+
}
|
|
542
|
+
catch (error) {
|
|
543
|
+
console.error(`Error invoking intent handler for client ${clientIdentity.uuid}/${clientIdentity.name}/${clientIdentity.endpointId}`);
|
|
544
|
+
handlerInfo.isReady = false;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Responsible for returning information on a particular Intent.
|
|
552
|
+
* Must be overridden.
|
|
553
|
+
* @param { InfoForIntentOptions } options
|
|
554
|
+
* @param { ClientIdentity } clientIdentity Identity of the Client making the request.
|
|
555
|
+
* @return { Promise<unknown> }
|
|
556
|
+
* @tutorial interop.handleInfoForIntent
|
|
557
|
+
* @experimental
|
|
558
|
+
*/
|
|
559
|
+
// eslint-disable-next-line class-methods-use-this
|
|
560
|
+
async handleInfoForIntent(options, clientIdentity) {
|
|
561
|
+
const warning = utils_1.generateOverrideWarning('interopClient.getInfoForIntent', 'fdc3.findIntent', 'InteropBroker.handleInfoForIntent', clientIdentity);
|
|
562
|
+
console.warn(warning);
|
|
563
|
+
throw new Error(utils_1.BROKER_ERRORS.getInfoForIntent);
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Responsible for returning information on which Intents are meant to handle a specific Context.
|
|
567
|
+
* Must be overridden.
|
|
568
|
+
* @param { Context } context Data passed between entities and applications.
|
|
569
|
+
* @param { ClientIdentity } clientIdentity Identity of the Client making the request.
|
|
570
|
+
* @return { Promise<unknown> }
|
|
571
|
+
* @tutorial interop.handleInfoForIntentsByContext
|
|
572
|
+
* @experimental
|
|
573
|
+
*/
|
|
574
|
+
// eslint-disable-next-line class-methods-use-this
|
|
575
|
+
async handleInfoForIntentsByContext(context, clientIdentity) {
|
|
576
|
+
const warning = utils_1.generateOverrideWarning('interopClient.getInfoForIntentsByContext', 'fdc3.findIntentsByContext', 'InteropBroker.handleInfoForIntentsByContext', clientIdentity);
|
|
577
|
+
console.warn(warning);
|
|
578
|
+
throw new Error(utils_1.BROKER_ERRORS.getInfoForIntentsByContext);
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Responsible for resolving an Intent based on a specific Context.
|
|
582
|
+
* Must be overridden.
|
|
583
|
+
* @param { ContextForIntent } contextForIntent Data passed between entities and applications.
|
|
584
|
+
* @param { ClientIdentity } clientIdentity Identity of the Client making the request.
|
|
585
|
+
* @return { Promise<unknown> }
|
|
586
|
+
* @tutorial interop.handleFiredIntentForContext
|
|
587
|
+
* @experimental
|
|
588
|
+
*/
|
|
589
|
+
// eslint-disable-next-line class-methods-use-this
|
|
590
|
+
async handleFiredIntentForContext(contextForIntent, clientIdentity) {
|
|
591
|
+
const warning = utils_1.generateOverrideWarning('interopClient.fireIntentForContext', 'fdc3.raiseIntentForContext', 'InteropBroker.handleFiredIntentForContext', clientIdentity);
|
|
592
|
+
console.warn(warning);
|
|
593
|
+
throw new Error(utils_1.BROKER_ERRORS.fireIntentForContext);
|
|
594
|
+
}
|
|
595
|
+
/*
|
|
596
|
+
Snapshot APIs
|
|
597
|
+
*/
|
|
598
|
+
// Used to save interop broker state in snapshots
|
|
599
|
+
decorateSnapshot(snapshot) {
|
|
600
|
+
return { ...snapshot, interopSnapshotDetails: { contextGroupStates: this.getContextGroupStates() } };
|
|
601
|
+
}
|
|
602
|
+
// Used to restore interop broker state in snapshots.
|
|
603
|
+
applySnapshot(snapshot, options) {
|
|
604
|
+
var _a;
|
|
605
|
+
const contextGroupStates = (_a = snapshot === null || snapshot === void 0 ? void 0 : snapshot.interopSnapshotDetails) === null || _a === void 0 ? void 0 : _a.contextGroupStates;
|
|
606
|
+
if (contextGroupStates) {
|
|
607
|
+
if (!(options === null || options === void 0 ? void 0 : options.closeExistingWindows)) {
|
|
608
|
+
this.updateExistingClients(contextGroupStates);
|
|
609
|
+
}
|
|
610
|
+
this.rehydrateContextGroupStates(contextGroupStates);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
updateExistingClients(contextGroupStates) {
|
|
614
|
+
const clients = this.interopClients;
|
|
615
|
+
clients.forEach((subState) => {
|
|
616
|
+
const { clientIdentity, contextGroupId, contextHandlers } = subState;
|
|
617
|
+
if (contextGroupId) {
|
|
618
|
+
const groupContexts = contextGroupStates[contextGroupId];
|
|
619
|
+
for (const [, context] of Object.entries(groupContexts)) {
|
|
620
|
+
contextHandlers.forEach((contextHandler) => {
|
|
621
|
+
const { handlerId, contextType } = contextHandler;
|
|
622
|
+
if (InteropBroker.isContextTypeCompatible(context.type, contextType)) {
|
|
623
|
+
this.invokeContextHandler(clientIdentity, handlerId, context);
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
// Used to store context group state in snapshots
|
|
631
|
+
getContextGroupStates() {
|
|
632
|
+
return InteropBroker.toObject(this.contextGroupsById);
|
|
633
|
+
}
|
|
634
|
+
// Used to rehydrate the context state from a snapshot
|
|
635
|
+
rehydrateContextGroupStates(incomingContextGroupStates) {
|
|
636
|
+
const contextGroupStates = Object.entries(incomingContextGroupStates);
|
|
637
|
+
for (const [contextGroupId, contexts] of contextGroupStates) {
|
|
638
|
+
const contextObjects = Object.entries(contexts);
|
|
639
|
+
for (const [contextType, context] of contextObjects) {
|
|
640
|
+
if (this.contextGroupsById.has(contextGroupId)) {
|
|
641
|
+
const currentContextGroupState = this.contextGroupsById.get(contextGroupId);
|
|
642
|
+
currentContextGroupState.set(contextType, context);
|
|
643
|
+
}
|
|
644
|
+
else {
|
|
645
|
+
// This logic will change when dynamic context group creation comes in.
|
|
646
|
+
console.warn(`Attempting to set a context group that isn't in the context group mapping. Skipping context group rehydration for: ${contextGroupId}`);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
/*
|
|
652
|
+
Internal Context Handler APIs
|
|
653
|
+
*/
|
|
654
|
+
// Used to give context to a client that has registered their context handler
|
|
655
|
+
contextHandlerRegistered({ contextType, handlerId }, clientIdentity) {
|
|
656
|
+
const handlerInfo = { contextType, handlerId };
|
|
657
|
+
const clientState = this.getClientState(clientIdentity);
|
|
658
|
+
clientState === null || clientState === void 0 ? void 0 : clientState.contextHandlers.set(handlerId, handlerInfo);
|
|
659
|
+
if (clientState && clientState.contextGroupId) {
|
|
660
|
+
const { contextGroupId } = clientState;
|
|
661
|
+
const contextGroupMap = this.contextGroupsById.get(contextGroupId);
|
|
662
|
+
if (contextType === undefined) {
|
|
663
|
+
// Send this single handler all of the context, because it accepts all.
|
|
664
|
+
contextGroupMap.forEach((context, _) => {
|
|
665
|
+
this.invokeContextHandler(clientIdentity, handlerId, context);
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
else if (contextGroupMap.has(contextType)) {
|
|
669
|
+
const contextForType = contextGroupMap.get(contextType);
|
|
670
|
+
if (contextForType) {
|
|
671
|
+
this.invokeContextHandler(clientIdentity, handlerId, contextForType);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
// eslint-disable-next-line class-methods-use-this
|
|
677
|
+
async intentHandlerRegistered(payload, clientIdentity) {
|
|
678
|
+
const { handlerId } = payload;
|
|
679
|
+
const clientIntentInfo = this.intentClientMap.get(clientIdentity.name);
|
|
680
|
+
const handlerInfo = clientIntentInfo === null || clientIntentInfo === void 0 ? void 0 : clientIntentInfo.get(handlerId);
|
|
681
|
+
if (!clientIntentInfo) {
|
|
682
|
+
this.intentClientMap.set(clientIdentity.name, new Map());
|
|
683
|
+
const newHandlerInfoMap = this.intentClientMap.get(clientIdentity.name);
|
|
684
|
+
if (newHandlerInfoMap) {
|
|
685
|
+
newHandlerInfoMap.set(handlerId, { isReady: true, pendingIntents: [], clientIdentity });
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
else if (!handlerInfo) {
|
|
689
|
+
clientIntentInfo.set(handlerId, { isReady: true, pendingIntents: [], clientIdentity });
|
|
690
|
+
}
|
|
691
|
+
else {
|
|
692
|
+
const { pendingIntents } = handlerInfo;
|
|
693
|
+
handlerInfo.clientIdentity = clientIdentity;
|
|
694
|
+
handlerInfo.isReady = true;
|
|
695
|
+
try {
|
|
696
|
+
if (pendingIntents.length > 0) {
|
|
697
|
+
const intentToSend = pendingIntents[pendingIntents.length - 1];
|
|
698
|
+
await this.channel.dispatch(clientIdentity, handlerId, intentToSend);
|
|
699
|
+
handlerInfo.pendingIntents = [];
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
catch (error) {
|
|
703
|
+
console.error(`Error invoking intent handler: ${handlerId} for client ${clientIdentity.uuid}/${clientIdentity.name}/${clientIdentity.endpointId}`);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
// Used to invoke a client's context handler
|
|
708
|
+
invokeContextHandler(clientIdentity, handlerId, context) {
|
|
709
|
+
this.channel.dispatch(clientIdentity, handlerId, context).catch((e) => {
|
|
710
|
+
console.error(`Error invoking context handler ${handlerId} for context type ${context.type} in client ${clientIdentity.uuid}/${clientIdentity.name}/${clientIdentity.endpointId}`, e);
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
// Used to remove a context handler for a client
|
|
714
|
+
removeContextHandler({ handlerId }, clientIdentity) {
|
|
715
|
+
const clientState = this.getClientState(clientIdentity);
|
|
716
|
+
if (clientState) {
|
|
717
|
+
clientState.contextHandlers.delete(handlerId);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
handleJoinSessionContextGroup({ sessionContextGroupId }, clientIdentity) {
|
|
721
|
+
try {
|
|
722
|
+
if (!sessionContextGroupId) {
|
|
723
|
+
throw new Error('Failed to join session context group: must specify group id.');
|
|
724
|
+
}
|
|
725
|
+
const sessionContextGroup = this.sessionContextGroupMap.get(sessionContextGroupId);
|
|
726
|
+
if (sessionContextGroup) {
|
|
727
|
+
sessionContextGroup.registerNewClient(clientIdentity);
|
|
728
|
+
}
|
|
729
|
+
else {
|
|
730
|
+
const newSessionContextGroupBroker = new SessionContextGroupBroker_1.default(this.channel, sessionContextGroupId);
|
|
731
|
+
newSessionContextGroupBroker.registerNewClient(clientIdentity);
|
|
732
|
+
this.sessionContextGroupMap.set(sessionContextGroupId, newSessionContextGroupBroker);
|
|
733
|
+
}
|
|
734
|
+
return { hasConflict: this.contextGroupsById.has(sessionContextGroupId) };
|
|
735
|
+
}
|
|
736
|
+
catch (error) {
|
|
737
|
+
throw new Error(error);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
/*
|
|
741
|
+
Internal Utilties
|
|
742
|
+
*/
|
|
743
|
+
// Getter for interop info for a client.
|
|
744
|
+
getClientState(id) {
|
|
745
|
+
return this.interopClients.get(id.endpointId);
|
|
746
|
+
}
|
|
747
|
+
// Util for getContextGroupStates. Serializes the contextGroupStates object so we can store it.
|
|
748
|
+
static toObject(map) {
|
|
749
|
+
const objectFromMap = Object.fromEntries(map);
|
|
750
|
+
const newObject = {};
|
|
751
|
+
Object.entries(objectFromMap).forEach(([contextGroupId, contextMap]) => {
|
|
752
|
+
const newContextObject = Object.fromEntries(contextMap);
|
|
753
|
+
newObject[contextGroupId] = newContextObject;
|
|
754
|
+
});
|
|
755
|
+
return newObject;
|
|
756
|
+
}
|
|
757
|
+
static checkContextIntegrity(context) {
|
|
758
|
+
if (!context) {
|
|
759
|
+
return { isValid: false, reason: 'No context supplied' };
|
|
760
|
+
}
|
|
761
|
+
if (typeof context !== 'object') {
|
|
762
|
+
return { isValid: false, reason: 'Context must be an Object' };
|
|
763
|
+
}
|
|
764
|
+
if (!context.type) {
|
|
765
|
+
return { isValid: false, reason: 'Context must have a type property' };
|
|
766
|
+
}
|
|
767
|
+
if (context.id && typeof context.id !== 'object') {
|
|
768
|
+
return {
|
|
769
|
+
isValid: false,
|
|
770
|
+
reason: 'Context id must be an Object populated with key-value identifiers (if set)'
|
|
771
|
+
};
|
|
772
|
+
}
|
|
773
|
+
if (context.id) {
|
|
774
|
+
const { id } = context;
|
|
775
|
+
const keys = Object.keys(id);
|
|
776
|
+
let foundBadIdentifier = false;
|
|
777
|
+
if (!keys.length) {
|
|
778
|
+
return { isValid: false, reason: 'Context id must have at least one key-value identifier' };
|
|
779
|
+
}
|
|
780
|
+
keys.forEach((key) => {
|
|
781
|
+
if (typeof key !== 'string' || typeof id[key] !== 'string') {
|
|
782
|
+
foundBadIdentifier = true;
|
|
783
|
+
}
|
|
784
|
+
});
|
|
785
|
+
if (foundBadIdentifier) {
|
|
786
|
+
return { isValid: false, reason: 'Context id key-value identifiers must be of type string' };
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
if (context.name && typeof context.name !== 'string') {
|
|
790
|
+
return { isValid: false, reason: 'Context name must be of string type (if set)' };
|
|
791
|
+
}
|
|
792
|
+
return { isValid: true };
|
|
793
|
+
}
|
|
794
|
+
// Util to check a client identity.
|
|
795
|
+
static hasEndpointId(target) {
|
|
796
|
+
return target.endpointId !== undefined;
|
|
797
|
+
}
|
|
798
|
+
// Util to check if we should send a context to a handler.
|
|
799
|
+
static isContextTypeCompatible(contextType, registeredContextType) {
|
|
800
|
+
return typeof registeredContextType === 'undefined' || contextType === registeredContextType;
|
|
801
|
+
}
|
|
802
|
+
// Setup function for state mapping
|
|
803
|
+
setContextGroupMap() {
|
|
804
|
+
// This way, if a user overrides this.getContextGroups, it's reflected in the contextGroupMapping.
|
|
805
|
+
for (const contextGroupInfo of this.getContextGroups()) {
|
|
806
|
+
this.contextGroupsById.set(contextGroupInfo.id, new Map());
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
static async setCurrentContextGroupInClientOptions(clientIdentity, contextGroupId) {
|
|
810
|
+
const entityInfo = await fin.System.getEntityInfo(clientIdentity.uuid, clientIdentity.name);
|
|
811
|
+
let entity;
|
|
812
|
+
if (entityInfo.entityType === 'view') {
|
|
813
|
+
entity = await fin.View.wrap(clientIdentity);
|
|
814
|
+
}
|
|
815
|
+
else if (entityInfo.entityType === 'window') {
|
|
816
|
+
entity = await fin.Window.wrap(clientIdentity);
|
|
817
|
+
}
|
|
818
|
+
if (entity) {
|
|
819
|
+
await entity.updateOptions({
|
|
820
|
+
interop: {
|
|
821
|
+
currentContextGroup: contextGroupId
|
|
822
|
+
}
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
else {
|
|
826
|
+
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.`);
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
// Setup Channel Connection Logic
|
|
830
|
+
wireChannel(channel) {
|
|
831
|
+
channel.onConnection((clientIdentity, payload) => {
|
|
832
|
+
if (!this.isConnectionAuthorized(clientIdentity, payload)) {
|
|
833
|
+
throw new Error(`Connection not authorized for ${clientIdentity.uuid}, ${clientIdentity.name}`);
|
|
834
|
+
}
|
|
835
|
+
if (!clientIdentity.endpointId) {
|
|
836
|
+
throw new Error('Version too old to be compatible with Interop. Please upgrade your runtime to a more recent version.');
|
|
837
|
+
}
|
|
838
|
+
const clientSubscriptionState = {
|
|
839
|
+
contextGroupId: undefined,
|
|
840
|
+
contextHandlers: new Map(),
|
|
841
|
+
clientIdentity
|
|
842
|
+
};
|
|
843
|
+
// Only allow the client to join a contextGroup that actually exists.
|
|
844
|
+
if ((payload === null || payload === void 0 ? void 0 : payload.currentContextGroup) && this.contextGroupsById.has(payload.currentContextGroup)) {
|
|
845
|
+
clientSubscriptionState.contextGroupId = payload === null || payload === void 0 ? void 0 : payload.currentContextGroup;
|
|
846
|
+
}
|
|
847
|
+
this.interopClients.set(clientIdentity.endpointId, clientSubscriptionState);
|
|
848
|
+
});
|
|
849
|
+
channel.onDisconnection((clientIdentity) => {
|
|
850
|
+
this.interopClients.delete(clientIdentity.endpointId);
|
|
851
|
+
const targetInfo = this.intentClientMap.get(clientIdentity.name);
|
|
852
|
+
if (targetInfo && clientIdentity.uuid === fin.me.identity.uuid) {
|
|
853
|
+
targetInfo.forEach((handler) => {
|
|
854
|
+
handler.isReady = false;
|
|
855
|
+
});
|
|
856
|
+
}
|
|
857
|
+
this.sessionContextGroupMap.forEach((sessionContextGroup) => {
|
|
858
|
+
sessionContextGroup.onDisconnection(clientIdentity);
|
|
859
|
+
});
|
|
860
|
+
});
|
|
861
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
862
|
+
// @ts-ignore
|
|
863
|
+
channel.beforeAction((action, payload, clientIdentity) => {
|
|
864
|
+
if (!this.isActionAuthorized(action, payload, clientIdentity)) {
|
|
865
|
+
throw new Error(`Action (${action}) not authorized for ${clientIdentity.uuid}, ${clientIdentity.name}`);
|
|
866
|
+
}
|
|
867
|
+
console.log(action, payload, clientIdentity);
|
|
868
|
+
});
|
|
869
|
+
channel.afterAction(console.log);
|
|
870
|
+
// Client functions
|
|
871
|
+
channel.register('setContext', this.setContext.bind(this));
|
|
872
|
+
channel.register('fireIntent', this.handleFiredIntent.bind(this));
|
|
873
|
+
channel.register('getCurrentContext', this.getCurrentContext.bind(this));
|
|
874
|
+
channel.register('getInfoForIntent', this.handleInfoForIntent.bind(this));
|
|
875
|
+
channel.register('getInfoForIntentsByContext', this.handleInfoForIntentsByContext.bind(this));
|
|
876
|
+
channel.register('fireIntentForContext', this.handleFiredIntentForContext.bind(this));
|
|
877
|
+
// Platform window functions
|
|
878
|
+
channel.register('getContextGroups', this.getContextGroups.bind(this));
|
|
879
|
+
channel.register('joinContextGroup', this.joinContextGroup.bind(this));
|
|
880
|
+
channel.register('removeFromContextGroup', this.removeFromContextGroup.bind(this));
|
|
881
|
+
channel.register('getAllClientsInContextGroup', this.getAllClientsInContextGroup.bind(this));
|
|
882
|
+
channel.register('getInfoForContextGroup', this.getInfoForContextGroup.bind(this));
|
|
883
|
+
// Internal methods
|
|
884
|
+
channel.register('contextHandlerRegistered', this.contextHandlerRegistered.bind(this));
|
|
885
|
+
channel.register('intentHandlerRegistered', this.intentHandlerRegistered.bind(this));
|
|
886
|
+
channel.register('removeContextHandler', this.removeContextHandler.bind(this));
|
|
887
|
+
channel.register('sessionContextGroup:createIfNeeded', this.handleJoinSessionContextGroup.bind(this));
|
|
888
|
+
}
|
|
889
|
+
/**
|
|
890
|
+
* Can be used to completely prevent a connection. Return false to prevent connections. Allows all connections by default.
|
|
891
|
+
* @param _id the identity tryinc to connect
|
|
892
|
+
* @param _connectionPayload optional payload to use in custom implementations, will be undefined by default
|
|
893
|
+
*/
|
|
894
|
+
async isConnectionAuthorized(_id, _connectionPayload) {
|
|
895
|
+
this.wire.sendAction('interop-broker-is-connection-authorized').catch((e) => {
|
|
896
|
+
// don't expose, analytics-only call
|
|
897
|
+
});
|
|
898
|
+
return true;
|
|
899
|
+
}
|
|
900
|
+
/**
|
|
901
|
+
* Called before every action to check if this entity should be allowed to take the action.
|
|
902
|
+
* Return false to prevent the action
|
|
903
|
+
* @param _action the string action to authorize in camel case
|
|
904
|
+
* @param _payload the data being sent for this action
|
|
905
|
+
* @param _identity the connection attempting to dispatch this action
|
|
906
|
+
*/
|
|
907
|
+
async isActionAuthorized(_action, _payload, _identity) {
|
|
908
|
+
this.wire.sendAction('interop-broker-is-action-authorized').catch((e) => {
|
|
909
|
+
// don't expose, analytics-only call
|
|
910
|
+
});
|
|
911
|
+
return true;
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
exports.InteropBroker = InteropBroker;
|