@openfin/core 25.68.30 → 25.70.2
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 +30 -826
- package/README.md +12 -2
- package/package.json +1 -1
- package/src/api/application/Factory.d.ts +145 -145
- package/src/api/application/Factory.js +229 -229
- package/src/api/application/Instance.d.ts +301 -302
- package/src/api/application/Instance.js +412 -412
- package/src/api/application/index.d.ts +3 -3
- package/src/api/application/index.js +15 -15
- package/src/api/base.d.ts +43 -43
- package/src/api/base.js +177 -177
- package/src/api/clipboard/index.d.ts +69 -69
- package/src/api/clipboard/index.js +88 -88
- 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 -11
- package/src/api/events/channel.js +2 -2
- package/src/api/events/emitterMap.d.ts +11 -11
- package/src/api/events/emitterMap.js +35 -35
- package/src/api/events/eventAggregator.d.ts +5 -5
- package/src/api/events/eventAggregator.js +43 -43
- 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 +176 -0
- package/src/api/events/window.js +2 -0
- package/src/api/external-application/Factory.d.ts +26 -26
- package/src/api/external-application/Factory.js +40 -40
- package/src/api/external-application/Instance.d.ts +101 -102
- package/src/api/external-application/Instance.js +109 -109
- package/src/api/external-application/index.d.ts +3 -3
- package/src/api/external-application/index.js +15 -15
- package/src/api/fin.d.ts +49 -49
- package/src/api/fin.js +43 -43
- package/src/api/frame/Factory.d.ts +36 -36
- package/src/api/frame/Factory.js +69 -69
- package/src/api/frame/Instance.d.ts +121 -121
- package/src/api/frame/Instance.js +130 -130
- package/src/api/frame/index.d.ts +3 -3
- package/src/api/frame/index.js +15 -15
- package/src/api/global-hotkey/index.d.ts +38 -38
- package/src/api/global-hotkey/index.js +58 -58
- package/src/api/interappbus/channel/channel.d.ts +26 -26
- package/src/api/interappbus/channel/channel.js +77 -77
- package/src/api/interappbus/channel/channels-docs.d.ts +318 -318
- package/src/api/interappbus/channel/channels-docs.js +376 -376
- package/src/api/interappbus/channel/client.d.ts +22 -22
- package/src/api/interappbus/channel/client.js +84 -84
- package/src/api/interappbus/channel/connection-manager.d.ts +28 -28
- package/src/api/interappbus/channel/connection-manager.js +244 -244
- package/src/api/interappbus/channel/index.d.ts +22 -23
- package/src/api/interappbus/channel/index.js +121 -121
- package/src/api/interappbus/channel/protocols/classic/message-receiver.d.ts +13 -13
- package/src/api/interappbus/channel/protocols/classic/message-receiver.js +73 -73
- package/src/api/interappbus/channel/protocols/classic/strategy.d.ts +22 -22
- package/src/api/interappbus/channel/protocols/classic/strategy.js +84 -84
- package/src/api/interappbus/channel/protocols/combined/strategy.d.ts +20 -20
- package/src/api/interappbus/channel/protocols/combined/strategy.js +58 -58
- package/src/api/interappbus/channel/protocols/index.d.ts +44 -44
- package/src/api/interappbus/channel/protocols/index.js +2 -2
- package/src/api/interappbus/channel/protocols/protocol-manager.d.ts +10 -10
- package/src/api/interappbus/channel/protocols/protocol-manager.js +43 -43
- package/src/api/interappbus/channel/protocols/rtc/endpoint.d.ts +23 -23
- package/src/api/interappbus/channel/protocols/rtc/endpoint.js +135 -135
- package/src/api/interappbus/channel/protocols/rtc/ice-manager.d.ts +30 -30
- package/src/api/interappbus/channel/protocols/rtc/ice-manager.js +131 -131
- package/src/api/interappbus/channel/protocols/rtc/strategy.d.ts +22 -22
- package/src/api/interappbus/channel/protocols/rtc/strategy.js +87 -87
- package/src/api/interappbus/channel/protocols/strategy-types.d.ts +13 -13
- package/src/api/interappbus/channel/protocols/strategy-types.js +2 -2
- package/src/api/interappbus/channel/protocols/strategy.d.ts +15 -15
- package/src/api/interappbus/channel/protocols/strategy.js +2 -2
- package/src/api/interappbus/channel/provider.d.ts +31 -31
- package/src/api/interappbus/channel/provider.js +160 -160
- package/src/api/interappbus/index.d.ts +85 -86
- package/src/api/interappbus/index.js +175 -175
- package/src/api/interop/Factory.d.ts +37 -37
- package/src/api/interop/Factory.js +54 -54
- package/src/api/interop/InteropBroker.d.ts +363 -363
- package/src/api/interop/InteropBroker.js +914 -914
- package/src/api/interop/InteropClient.d.ts +268 -268
- package/src/api/interop/InteropClient.js +450 -450
- package/src/api/interop/SessionContextGroupBroker.d.ts +26 -26
- package/src/api/interop/SessionContextGroupBroker.js +107 -107
- package/src/api/interop/SessionContextGroupClient.d.ts +20 -20
- package/src/api/interop/SessionContextGroupClient.js +85 -85
- package/src/api/interop/fdc3/fdc3-1.2.d.ts +187 -187
- package/src/api/interop/fdc3/fdc3-1.2.js +385 -385
- package/src/api/interop/fdc3/fdc3.js +17 -17
- package/src/api/interop/fdc3/utils.d.ts +6 -6
- package/src/api/interop/fdc3/utils.js +17 -17
- package/src/api/interop/index.d.ts +4 -4
- package/src/api/interop/index.js +16 -16
- package/src/api/interop/utils.d.ts +11 -11
- package/src/api/interop/utils.js +36 -36
- package/src/api/me.d.ts +38 -35
- package/src/api/me.js +128 -60
- package/src/api/platform/Factory.d.ts +109 -109
- package/src/api/platform/Factory.js +188 -188
- package/src/api/platform/Instance.d.ts +122 -122
- package/src/api/platform/Instance.js +298 -298
- package/src/api/platform/common-utils.d.ts +6 -6
- package/src/api/platform/common-utils.js +16 -16
- package/src/api/platform/index.d.ts +3 -3
- package/src/api/platform/index.js +15 -15
- package/src/api/platform/layout/Factory.d.ts +108 -108
- package/src/api/platform/layout/Factory.js +189 -189
- package/src/api/platform/layout/Instance.d.ts +49 -49
- package/src/api/platform/layout/Instance.js +99 -99
- package/src/api/platform/layout/index.d.ts +2 -2
- package/src/api/platform/layout/index.js +14 -14
- package/src/api/platform/layout/shapes.d.ts +11 -0
- package/src/api/{window → platform/layout}/shapes.js +2 -2
- package/src/api/snapshot-source/Factory.d.ts +36 -36
- package/src/api/snapshot-source/Factory.js +65 -65
- package/src/api/snapshot-source/Instance.d.ts +30 -30
- package/src/api/snapshot-source/Instance.js +134 -134
- package/src/api/snapshot-source/index.d.ts +3 -3
- package/src/api/snapshot-source/index.js +15 -15
- package/src/api/snapshot-source/utils.d.ts +1 -1
- package/src/api/snapshot-source/utils.js +5 -5
- package/src/api/system/index.d.ts +960 -961
- package/src/api/system/index.js +1241 -1241
- package/src/api/view/Factory.d.ts +49 -49
- package/src/api/view/Factory.js +103 -103
- package/src/api/view/Instance.d.ts +387 -380
- package/src/api/view/Instance.js +422 -415
- package/src/api/view/index.d.ts +3 -3
- package/src/api/view/index.js +15 -15
- package/src/api/webcontents/main.d.ts +36 -36
- package/src/api/webcontents/main.js +82 -82
- package/src/api/window/Factory.d.ts +44 -44
- package/src/api/window/Factory.js +91 -91
- package/src/api/window/Instance.d.ts +972 -966
- package/src/api/window/Instance.js +1209 -1202
- package/src/api/window/index.d.ts +3 -5
- package/src/api/window/index.js +15 -17
- package/src/environment/environment.d.ts +28 -25
- package/src/environment/environment.js +4 -4
- package/src/environment/node-env.d.ts +25 -26
- package/src/environment/node-env.js +64 -64
- package/src/environment/openfin-env.d.ts +29 -30
- package/src/environment/openfin-env.js +107 -107
- package/src/mock.d.ts +3 -3
- package/src/mock.js +91 -90
- package/src/shapes/ERROR_BOX_TYPES.d.ts +1 -0
- package/src/shapes/ERROR_BOX_TYPES.js +2 -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 -4
- package/src/transport/fin_store.js +16 -16
- package/src/transport/transport-errors.d.ts +18 -18
- package/src/transport/transport-errors.js +37 -37
- package/src/transport/transport.d.ts +56 -43
- package/src/transport/transport.js +181 -181
- package/src/transport/wire.d.ts +71 -11
- package/src/transport/wire.js +32 -32
- package/src/util/asyncFilter.d.ts +1 -1
- package/src/util/asyncFilter.js +7 -7
- package/src/util/errors.d.ts +9 -5
- package/src/util/errors.js +11 -11
- package/src/util/exhaustive.d.ts +1 -1
- package/src/util/exhaustive.js +7 -7
- package/src/util/http.d.ts +11 -11
- package/src/util/http.js +83 -83
- package/src/util/normalize-config.d.ts +3 -5
- package/src/util/normalize-config.js +47 -47
- package/src/util/promises.d.ts +5 -5
- package/src/util/promises.js +27 -27
- package/src/util/ref-counter.d.ts +7 -7
- package/src/util/ref-counter.js +51 -51
- package/src/util/runtimeVersioning.d.ts +3 -3
- package/src/util/runtimeVersioning.js +25 -25
- package/src/util/utilTypes.d.ts +8 -8
- package/src/util/utilTypes.js +2 -2
- package/src/util/validate.d.ts +3 -3
- package/src/util/validate.js +11 -11
- package/docs.README(OLD).md +0 -82
- package/resources/win/OpenFinRVM.exe +0 -0
- package/src/api/window/bounds-changed.d.ts +0 -10
- package/src/api/window/bounds-changed.js +0 -6
- package/src/api/window/shapes.d.ts +0 -13
|
@@ -1,244 +1,244 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) {
|
|
3
|
-
if (!privateMap.has(receiver)) {
|
|
4
|
-
throw new TypeError("attempted to set private field on non-instance");
|
|
5
|
-
}
|
|
6
|
-
privateMap.set(receiver, value);
|
|
7
|
-
return value;
|
|
8
|
-
};
|
|
9
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) {
|
|
10
|
-
if (!privateMap.has(receiver)) {
|
|
11
|
-
throw new TypeError("attempted to get private field on non-instance");
|
|
12
|
-
}
|
|
13
|
-
return privateMap.get(receiver);
|
|
14
|
-
};
|
|
15
|
-
var _messageReceiver, _rtcConnectionManager;
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.ConnectionManager = void 0;
|
|
18
|
-
const exhaustive_1 = require("../../../util/exhaustive");
|
|
19
|
-
const base_1 = require("../../base");
|
|
20
|
-
const strategy_1 = require("./protocols/classic/strategy");
|
|
21
|
-
const strategy_2 = require("./protocols/rtc/strategy");
|
|
22
|
-
const ice_manager_1 = require("./protocols/rtc/ice-manager");
|
|
23
|
-
const provider_1 = require("./provider");
|
|
24
|
-
const message_receiver_1 = require("./protocols/classic/message-receiver");
|
|
25
|
-
const protocol_manager_1 = require("./protocols/protocol-manager");
|
|
26
|
-
const strategy_3 = require("./protocols/combined/strategy");
|
|
27
|
-
class ConnectionManager extends base_1.Base {
|
|
28
|
-
constructor(wire) {
|
|
29
|
-
super(wire);
|
|
30
|
-
_messageReceiver.set(this, void 0);
|
|
31
|
-
_rtcConnectionManager.set(this, void 0);
|
|
32
|
-
this.removeChannelFromProviderMap = (channelId) => {
|
|
33
|
-
this.providerMap.delete(channelId);
|
|
34
|
-
};
|
|
35
|
-
this.onmessage = (msg) => {
|
|
36
|
-
if (msg.action === 'process-channel-connection') {
|
|
37
|
-
this.processChannelConnection(msg);
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
return false;
|
|
41
|
-
};
|
|
42
|
-
this.providerMap = new Map();
|
|
43
|
-
this.protocolManager = new protocol_manager_1.ProtocolManager(this.isNodeEnvironment() ? ['classic'] : ['rtc', 'classic']);
|
|
44
|
-
__classPrivateFieldSet(this, _messageReceiver, new message_receiver_1.MessageReceiver(wire));
|
|
45
|
-
__classPrivateFieldSet(this, _rtcConnectionManager, new ice_manager_1.RTCICEManager(wire));
|
|
46
|
-
wire.registerMessageHandler(this.onmessage.bind(this));
|
|
47
|
-
}
|
|
48
|
-
static getProtocolOptionsFromStrings(protocols) {
|
|
49
|
-
return protocols.map(protocol => {
|
|
50
|
-
switch (protocol) {
|
|
51
|
-
case 'rtc':
|
|
52
|
-
return strategy_2.RTCInfo;
|
|
53
|
-
case 'classic':
|
|
54
|
-
return strategy_1.ClassicInfo;
|
|
55
|
-
default:
|
|
56
|
-
return exhaustive_1.exhaustiveCheck(protocol, ['rtc', 'classic']);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
createProvider(options, providerIdentity) {
|
|
61
|
-
const opts = Object.assign(this.wire.environment.getDefaultChannelOptions().create, options || {});
|
|
62
|
-
const protocols = this.protocolManager.getProviderProtocols(opts === null || opts === void 0 ? void 0 : opts.protocols);
|
|
63
|
-
const createSingleStrategy = (stratType) => {
|
|
64
|
-
switch (stratType) {
|
|
65
|
-
case 'rtc':
|
|
66
|
-
return new strategy_2.RTCStrategy();
|
|
67
|
-
case 'classic':
|
|
68
|
-
return new strategy_1.ClassicStrategy(this.wire, __classPrivateFieldGet(this, _messageReceiver),
|
|
69
|
-
// Providers do not have an endpointId, use channelId as endpointId in the strategy.
|
|
70
|
-
providerIdentity.channelId, providerIdentity);
|
|
71
|
-
default:
|
|
72
|
-
return exhaustive_1.exhaustiveCheck(stratType, ['rtc', 'classic']);
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
const strategies = protocols.map(createSingleStrategy);
|
|
76
|
-
let strategy;
|
|
77
|
-
if (strategies.length === 2) {
|
|
78
|
-
const [a, b] = strategies;
|
|
79
|
-
strategy = strategy_3.default.combine(a, b);
|
|
80
|
-
}
|
|
81
|
-
else if (strategies.length === 1) {
|
|
82
|
-
[strategy] = strategies;
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
// Should be impossible.
|
|
86
|
-
throw new Error('failed to combine strategies');
|
|
87
|
-
}
|
|
88
|
-
const channel = new provider_1.ChannelProvider(providerIdentity, this.wire, strategy);
|
|
89
|
-
const key = providerIdentity.channelId;
|
|
90
|
-
this.providerMap.set(key, { provider: channel, strategy, supportedProtocols: ConnectionManager.getProtocolOptionsFromStrings(protocols) });
|
|
91
|
-
provider_1.ChannelProvider.setProviderRemoval(channel, this.removeChannelFromProviderMap.bind(this));
|
|
92
|
-
return channel;
|
|
93
|
-
}
|
|
94
|
-
async createClientOffer(options) {
|
|
95
|
-
const protocols = this.protocolManager.getClientProtocols(options === null || options === void 0 ? void 0 : options.protocols);
|
|
96
|
-
let rtcPacket;
|
|
97
|
-
const supportedProtocols = await Promise.all(protocols.map(async (type) => {
|
|
98
|
-
switch (type) {
|
|
99
|
-
case 'rtc': {
|
|
100
|
-
const { rtcClient, channels, offer, rtcConnectionId, channelsOpened } = await __classPrivateFieldGet(this, _rtcConnectionManager).startClientOffer();
|
|
101
|
-
rtcPacket = { rtcClient, channels, channelsOpened };
|
|
102
|
-
return {
|
|
103
|
-
type: 'rtc',
|
|
104
|
-
version: strategy_2.RTCInfo.version,
|
|
105
|
-
payload: { offer, rtcConnectionId }
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
case 'classic':
|
|
109
|
-
return { type: 'classic', version: strategy_1.ClassicInfo.version };
|
|
110
|
-
default:
|
|
111
|
-
return exhaustive_1.exhaustiveCheck(type, ['rtc', 'classic']);
|
|
112
|
-
}
|
|
113
|
-
}));
|
|
114
|
-
return {
|
|
115
|
-
offer: {
|
|
116
|
-
supportedProtocols,
|
|
117
|
-
maxProtocols: 2
|
|
118
|
-
},
|
|
119
|
-
rtc: rtcPacket
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
async createClientStrategy(rtcPacket, routingInfo) {
|
|
123
|
-
var _a;
|
|
124
|
-
if (!routingInfo.endpointId) {
|
|
125
|
-
routingInfo.endpointId = this.wire.environment.getNextMessageId();
|
|
126
|
-
// For New Clients connecting to Old Providers. To prevent multi-dispatching and publishing, we delete previously-connected
|
|
127
|
-
// clients that are in the same context as the newly-connected client.
|
|
128
|
-
__classPrivateFieldGet(this, _messageReceiver).checkForPreviousClientConnection(routingInfo.channelId);
|
|
129
|
-
}
|
|
130
|
-
const answer = (_a = routingInfo.answer) !== null && _a !== void 0 ? _a : {
|
|
131
|
-
supportedProtocols: [{ type: 'classic', version: 1 }]
|
|
132
|
-
};
|
|
133
|
-
const createStrategyFromAnswer = async (protocol) => {
|
|
134
|
-
if (protocol.type === 'rtc' && rtcPacket) {
|
|
135
|
-
await __classPrivateFieldGet(this, _rtcConnectionManager).finishClientOffer(rtcPacket.rtcClient, protocol.payload.answer, rtcPacket.channelsOpened);
|
|
136
|
-
return new strategy_2.RTCStrategy();
|
|
137
|
-
}
|
|
138
|
-
if (protocol.type === 'classic') {
|
|
139
|
-
return new strategy_1.ClassicStrategy(this.wire, __classPrivateFieldGet(this, _messageReceiver), routingInfo.endpointId, routingInfo);
|
|
140
|
-
}
|
|
141
|
-
return null;
|
|
142
|
-
};
|
|
143
|
-
const allProtocols = (await Promise.all(answer.supportedProtocols.map(createStrategyFromAnswer))).filter((x) => x !== null);
|
|
144
|
-
// Clean up logic if provider didn't support rtc.
|
|
145
|
-
if (rtcPacket && !allProtocols.some((x) => x instanceof strategy_2.RTCStrategy)) {
|
|
146
|
-
if (rtcPacket) {
|
|
147
|
-
rtcPacket.rtcClient.close();
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
let strategy;
|
|
151
|
-
if (allProtocols.length >= 2) {
|
|
152
|
-
strategy = strategy_3.default.combine(allProtocols[0], allProtocols[1]);
|
|
153
|
-
}
|
|
154
|
-
else if (allProtocols.length) {
|
|
155
|
-
[strategy] = allProtocols;
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
// Should be impossible.
|
|
159
|
-
throw new Error('No compatible protocols');
|
|
160
|
-
}
|
|
161
|
-
// as casting rtcPacket because we won't have an rtcStrategy if rtcPacket is undefined;
|
|
162
|
-
const endpointPayload = { endpointIdentity: routingInfo, rtc: rtcPacket };
|
|
163
|
-
strategy.addEndpoint(routingInfo.channelId, endpointPayload);
|
|
164
|
-
return strategy;
|
|
165
|
-
}
|
|
166
|
-
async processChannelConnection(msg) {
|
|
167
|
-
const { clientIdentity, providerIdentity, ackToSender, payload, offer: clientOffer } = msg.payload;
|
|
168
|
-
if (!clientIdentity.endpointId) {
|
|
169
|
-
// Should be polyfilled by core but not in cases of node connecting to an old runtime.
|
|
170
|
-
clientIdentity.endpointId = this.wire.environment.getNextMessageId();
|
|
171
|
-
clientIdentity.isLocalEndpointId = true;
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
clientIdentity.isLocalEndpointId = false;
|
|
175
|
-
}
|
|
176
|
-
const key = providerIdentity.channelId;
|
|
177
|
-
const bus = this.providerMap.get(key);
|
|
178
|
-
if (!bus) {
|
|
179
|
-
ackToSender.payload.success = false;
|
|
180
|
-
ackToSender.payload.reason = `Channel "${providerIdentity.channelName}" has been destroyed.`;
|
|
181
|
-
return this.wire.sendRaw(ackToSender);
|
|
182
|
-
}
|
|
183
|
-
const { provider, strategy, supportedProtocols } = bus;
|
|
184
|
-
try {
|
|
185
|
-
if (!(provider instanceof provider_1.ChannelProvider)) {
|
|
186
|
-
throw Error('Cannot connect to a channel client');
|
|
187
|
-
}
|
|
188
|
-
const offer = clientOffer !== null && clientOffer !== void 0 ? clientOffer : {
|
|
189
|
-
supportedProtocols: [{ type: 'classic', version: 1 }],
|
|
190
|
-
maxProtocols: 1
|
|
191
|
-
};
|
|
192
|
-
const overlappingProtocols = this.protocolManager.getCompatibleProtocols(supportedProtocols, offer);
|
|
193
|
-
if (!overlappingProtocols.length) {
|
|
194
|
-
throw new Error('This provider does not support any of the offered protocols.');
|
|
195
|
-
}
|
|
196
|
-
const res = await provider.processConnection(clientIdentity, payload);
|
|
197
|
-
ackToSender.payload.payload = ackToSender.payload.payload || {};
|
|
198
|
-
// Loop through all supported protocols and accumulate them into the answer
|
|
199
|
-
// addEndpoint is tricky but we need to wait for channel resolution before adding the endpoint.
|
|
200
|
-
let clientAnswer = {
|
|
201
|
-
supportedProtocols: [],
|
|
202
|
-
endpointPayloadPromise: Promise.resolve({ endpointIdentity: clientIdentity })
|
|
203
|
-
};
|
|
204
|
-
clientAnswer = await overlappingProtocols.reduce(async (accumP, protocolToUse) => {
|
|
205
|
-
const answer = await accumP;
|
|
206
|
-
if (protocolToUse.type === 'rtc') {
|
|
207
|
-
const { answer: rtcAnswer, rtcClient, channels } = await __classPrivateFieldGet(this, _rtcConnectionManager).createProviderAnswer(protocolToUse.payload.rtcConnectionId, protocolToUse.payload.offer);
|
|
208
|
-
answer.supportedProtocols.push({
|
|
209
|
-
type: 'rtc',
|
|
210
|
-
version: strategy_2.RTCInfo.version,
|
|
211
|
-
payload: {
|
|
212
|
-
answer: rtcAnswer
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
answer.endpointPayloadPromise = answer.endpointPayloadPromise.then((endpointPayload) => channels.then((resolvedChannels) => {
|
|
216
|
-
return {
|
|
217
|
-
...endpointPayload,
|
|
218
|
-
rtc: {
|
|
219
|
-
rtcClient,
|
|
220
|
-
channels: resolvedChannels
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
}));
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
answer.supportedProtocols.push({ type: 'classic', version: strategy_1.ClassicInfo.version });
|
|
227
|
-
}
|
|
228
|
-
return answer;
|
|
229
|
-
}, Promise.resolve(clientAnswer));
|
|
230
|
-
// Need to as cast here.
|
|
231
|
-
clientAnswer.endpointPayloadPromise.then((endpointPayload) => strategy.addEndpoint(clientIdentity.endpointId, endpointPayload));
|
|
232
|
-
ackToSender.payload.payload.result = res;
|
|
233
|
-
ackToSender.payload.payload.answer = clientAnswer;
|
|
234
|
-
return this.wire.sendRaw(ackToSender);
|
|
235
|
-
}
|
|
236
|
-
catch (e) {
|
|
237
|
-
ackToSender.payload.success = false;
|
|
238
|
-
ackToSender.payload.reason = e.message;
|
|
239
|
-
return this.wire.sendRaw(ackToSender);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
exports.ConnectionManager = ConnectionManager;
|
|
244
|
-
_messageReceiver = new WeakMap(), _rtcConnectionManager = new WeakMap();
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) {
|
|
3
|
+
if (!privateMap.has(receiver)) {
|
|
4
|
+
throw new TypeError("attempted to set private field on non-instance");
|
|
5
|
+
}
|
|
6
|
+
privateMap.set(receiver, value);
|
|
7
|
+
return value;
|
|
8
|
+
};
|
|
9
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) {
|
|
10
|
+
if (!privateMap.has(receiver)) {
|
|
11
|
+
throw new TypeError("attempted to get private field on non-instance");
|
|
12
|
+
}
|
|
13
|
+
return privateMap.get(receiver);
|
|
14
|
+
};
|
|
15
|
+
var _messageReceiver, _rtcConnectionManager;
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.ConnectionManager = void 0;
|
|
18
|
+
const exhaustive_1 = require("../../../util/exhaustive");
|
|
19
|
+
const base_1 = require("../../base");
|
|
20
|
+
const strategy_1 = require("./protocols/classic/strategy");
|
|
21
|
+
const strategy_2 = require("./protocols/rtc/strategy");
|
|
22
|
+
const ice_manager_1 = require("./protocols/rtc/ice-manager");
|
|
23
|
+
const provider_1 = require("./provider");
|
|
24
|
+
const message_receiver_1 = require("./protocols/classic/message-receiver");
|
|
25
|
+
const protocol_manager_1 = require("./protocols/protocol-manager");
|
|
26
|
+
const strategy_3 = require("./protocols/combined/strategy");
|
|
27
|
+
class ConnectionManager extends base_1.Base {
|
|
28
|
+
constructor(wire) {
|
|
29
|
+
super(wire);
|
|
30
|
+
_messageReceiver.set(this, void 0);
|
|
31
|
+
_rtcConnectionManager.set(this, void 0);
|
|
32
|
+
this.removeChannelFromProviderMap = (channelId) => {
|
|
33
|
+
this.providerMap.delete(channelId);
|
|
34
|
+
};
|
|
35
|
+
this.onmessage = (msg) => {
|
|
36
|
+
if (msg.action === 'process-channel-connection') {
|
|
37
|
+
this.processChannelConnection(msg);
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
};
|
|
42
|
+
this.providerMap = new Map();
|
|
43
|
+
this.protocolManager = new protocol_manager_1.ProtocolManager(this.isNodeEnvironment() ? ['classic'] : ['rtc', 'classic']);
|
|
44
|
+
__classPrivateFieldSet(this, _messageReceiver, new message_receiver_1.MessageReceiver(wire));
|
|
45
|
+
__classPrivateFieldSet(this, _rtcConnectionManager, new ice_manager_1.RTCICEManager(wire));
|
|
46
|
+
wire.registerMessageHandler(this.onmessage.bind(this));
|
|
47
|
+
}
|
|
48
|
+
static getProtocolOptionsFromStrings(protocols) {
|
|
49
|
+
return protocols.map(protocol => {
|
|
50
|
+
switch (protocol) {
|
|
51
|
+
case 'rtc':
|
|
52
|
+
return strategy_2.RTCInfo;
|
|
53
|
+
case 'classic':
|
|
54
|
+
return strategy_1.ClassicInfo;
|
|
55
|
+
default:
|
|
56
|
+
return exhaustive_1.exhaustiveCheck(protocol, ['rtc', 'classic']);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
createProvider(options, providerIdentity) {
|
|
61
|
+
const opts = Object.assign(this.wire.environment.getDefaultChannelOptions().create, options || {});
|
|
62
|
+
const protocols = this.protocolManager.getProviderProtocols(opts === null || opts === void 0 ? void 0 : opts.protocols);
|
|
63
|
+
const createSingleStrategy = (stratType) => {
|
|
64
|
+
switch (stratType) {
|
|
65
|
+
case 'rtc':
|
|
66
|
+
return new strategy_2.RTCStrategy();
|
|
67
|
+
case 'classic':
|
|
68
|
+
return new strategy_1.ClassicStrategy(this.wire, __classPrivateFieldGet(this, _messageReceiver),
|
|
69
|
+
// Providers do not have an endpointId, use channelId as endpointId in the strategy.
|
|
70
|
+
providerIdentity.channelId, providerIdentity);
|
|
71
|
+
default:
|
|
72
|
+
return exhaustive_1.exhaustiveCheck(stratType, ['rtc', 'classic']);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const strategies = protocols.map(createSingleStrategy);
|
|
76
|
+
let strategy;
|
|
77
|
+
if (strategies.length === 2) {
|
|
78
|
+
const [a, b] = strategies;
|
|
79
|
+
strategy = strategy_3.default.combine(a, b);
|
|
80
|
+
}
|
|
81
|
+
else if (strategies.length === 1) {
|
|
82
|
+
[strategy] = strategies;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
// Should be impossible.
|
|
86
|
+
throw new Error('failed to combine strategies');
|
|
87
|
+
}
|
|
88
|
+
const channel = new provider_1.ChannelProvider(providerIdentity, this.wire, strategy);
|
|
89
|
+
const key = providerIdentity.channelId;
|
|
90
|
+
this.providerMap.set(key, { provider: channel, strategy, supportedProtocols: ConnectionManager.getProtocolOptionsFromStrings(protocols) });
|
|
91
|
+
provider_1.ChannelProvider.setProviderRemoval(channel, this.removeChannelFromProviderMap.bind(this));
|
|
92
|
+
return channel;
|
|
93
|
+
}
|
|
94
|
+
async createClientOffer(options) {
|
|
95
|
+
const protocols = this.protocolManager.getClientProtocols(options === null || options === void 0 ? void 0 : options.protocols);
|
|
96
|
+
let rtcPacket;
|
|
97
|
+
const supportedProtocols = await Promise.all(protocols.map(async (type) => {
|
|
98
|
+
switch (type) {
|
|
99
|
+
case 'rtc': {
|
|
100
|
+
const { rtcClient, channels, offer, rtcConnectionId, channelsOpened } = await __classPrivateFieldGet(this, _rtcConnectionManager).startClientOffer();
|
|
101
|
+
rtcPacket = { rtcClient, channels, channelsOpened };
|
|
102
|
+
return {
|
|
103
|
+
type: 'rtc',
|
|
104
|
+
version: strategy_2.RTCInfo.version,
|
|
105
|
+
payload: { offer, rtcConnectionId }
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
case 'classic':
|
|
109
|
+
return { type: 'classic', version: strategy_1.ClassicInfo.version };
|
|
110
|
+
default:
|
|
111
|
+
return exhaustive_1.exhaustiveCheck(type, ['rtc', 'classic']);
|
|
112
|
+
}
|
|
113
|
+
}));
|
|
114
|
+
return {
|
|
115
|
+
offer: {
|
|
116
|
+
supportedProtocols,
|
|
117
|
+
maxProtocols: 2
|
|
118
|
+
},
|
|
119
|
+
rtc: rtcPacket
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
async createClientStrategy(rtcPacket, routingInfo) {
|
|
123
|
+
var _a;
|
|
124
|
+
if (!routingInfo.endpointId) {
|
|
125
|
+
routingInfo.endpointId = this.wire.environment.getNextMessageId();
|
|
126
|
+
// For New Clients connecting to Old Providers. To prevent multi-dispatching and publishing, we delete previously-connected
|
|
127
|
+
// clients that are in the same context as the newly-connected client.
|
|
128
|
+
__classPrivateFieldGet(this, _messageReceiver).checkForPreviousClientConnection(routingInfo.channelId);
|
|
129
|
+
}
|
|
130
|
+
const answer = (_a = routingInfo.answer) !== null && _a !== void 0 ? _a : {
|
|
131
|
+
supportedProtocols: [{ type: 'classic', version: 1 }]
|
|
132
|
+
};
|
|
133
|
+
const createStrategyFromAnswer = async (protocol) => {
|
|
134
|
+
if (protocol.type === 'rtc' && rtcPacket) {
|
|
135
|
+
await __classPrivateFieldGet(this, _rtcConnectionManager).finishClientOffer(rtcPacket.rtcClient, protocol.payload.answer, rtcPacket.channelsOpened);
|
|
136
|
+
return new strategy_2.RTCStrategy();
|
|
137
|
+
}
|
|
138
|
+
if (protocol.type === 'classic') {
|
|
139
|
+
return new strategy_1.ClassicStrategy(this.wire, __classPrivateFieldGet(this, _messageReceiver), routingInfo.endpointId, routingInfo);
|
|
140
|
+
}
|
|
141
|
+
return null;
|
|
142
|
+
};
|
|
143
|
+
const allProtocols = (await Promise.all(answer.supportedProtocols.map(createStrategyFromAnswer))).filter((x) => x !== null);
|
|
144
|
+
// Clean up logic if provider didn't support rtc.
|
|
145
|
+
if (rtcPacket && !allProtocols.some((x) => x instanceof strategy_2.RTCStrategy)) {
|
|
146
|
+
if (rtcPacket) {
|
|
147
|
+
rtcPacket.rtcClient.close();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
let strategy;
|
|
151
|
+
if (allProtocols.length >= 2) {
|
|
152
|
+
strategy = strategy_3.default.combine(allProtocols[0], allProtocols[1]);
|
|
153
|
+
}
|
|
154
|
+
else if (allProtocols.length) {
|
|
155
|
+
[strategy] = allProtocols;
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
// Should be impossible.
|
|
159
|
+
throw new Error('No compatible protocols');
|
|
160
|
+
}
|
|
161
|
+
// as casting rtcPacket because we won't have an rtcStrategy if rtcPacket is undefined;
|
|
162
|
+
const endpointPayload = { endpointIdentity: routingInfo, rtc: rtcPacket };
|
|
163
|
+
strategy.addEndpoint(routingInfo.channelId, endpointPayload);
|
|
164
|
+
return strategy;
|
|
165
|
+
}
|
|
166
|
+
async processChannelConnection(msg) {
|
|
167
|
+
const { clientIdentity, providerIdentity, ackToSender, payload, offer: clientOffer } = msg.payload;
|
|
168
|
+
if (!clientIdentity.endpointId) {
|
|
169
|
+
// Should be polyfilled by core but not in cases of node connecting to an old runtime.
|
|
170
|
+
clientIdentity.endpointId = this.wire.environment.getNextMessageId();
|
|
171
|
+
clientIdentity.isLocalEndpointId = true;
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
clientIdentity.isLocalEndpointId = false;
|
|
175
|
+
}
|
|
176
|
+
const key = providerIdentity.channelId;
|
|
177
|
+
const bus = this.providerMap.get(key);
|
|
178
|
+
if (!bus) {
|
|
179
|
+
ackToSender.payload.success = false;
|
|
180
|
+
ackToSender.payload.reason = `Channel "${providerIdentity.channelName}" has been destroyed.`;
|
|
181
|
+
return this.wire.sendRaw(ackToSender);
|
|
182
|
+
}
|
|
183
|
+
const { provider, strategy, supportedProtocols } = bus;
|
|
184
|
+
try {
|
|
185
|
+
if (!(provider instanceof provider_1.ChannelProvider)) {
|
|
186
|
+
throw Error('Cannot connect to a channel client');
|
|
187
|
+
}
|
|
188
|
+
const offer = clientOffer !== null && clientOffer !== void 0 ? clientOffer : {
|
|
189
|
+
supportedProtocols: [{ type: 'classic', version: 1 }],
|
|
190
|
+
maxProtocols: 1
|
|
191
|
+
};
|
|
192
|
+
const overlappingProtocols = this.protocolManager.getCompatibleProtocols(supportedProtocols, offer);
|
|
193
|
+
if (!overlappingProtocols.length) {
|
|
194
|
+
throw new Error('This provider does not support any of the offered protocols.');
|
|
195
|
+
}
|
|
196
|
+
const res = await provider.processConnection(clientIdentity, payload);
|
|
197
|
+
ackToSender.payload.payload = ackToSender.payload.payload || {};
|
|
198
|
+
// Loop through all supported protocols and accumulate them into the answer
|
|
199
|
+
// addEndpoint is tricky but we need to wait for channel resolution before adding the endpoint.
|
|
200
|
+
let clientAnswer = {
|
|
201
|
+
supportedProtocols: [],
|
|
202
|
+
endpointPayloadPromise: Promise.resolve({ endpointIdentity: clientIdentity })
|
|
203
|
+
};
|
|
204
|
+
clientAnswer = await overlappingProtocols.reduce(async (accumP, protocolToUse) => {
|
|
205
|
+
const answer = await accumP;
|
|
206
|
+
if (protocolToUse.type === 'rtc') {
|
|
207
|
+
const { answer: rtcAnswer, rtcClient, channels } = await __classPrivateFieldGet(this, _rtcConnectionManager).createProviderAnswer(protocolToUse.payload.rtcConnectionId, protocolToUse.payload.offer);
|
|
208
|
+
answer.supportedProtocols.push({
|
|
209
|
+
type: 'rtc',
|
|
210
|
+
version: strategy_2.RTCInfo.version,
|
|
211
|
+
payload: {
|
|
212
|
+
answer: rtcAnswer
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
answer.endpointPayloadPromise = answer.endpointPayloadPromise.then((endpointPayload) => channels.then((resolvedChannels) => {
|
|
216
|
+
return {
|
|
217
|
+
...endpointPayload,
|
|
218
|
+
rtc: {
|
|
219
|
+
rtcClient,
|
|
220
|
+
channels: resolvedChannels
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
}));
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
answer.supportedProtocols.push({ type: 'classic', version: strategy_1.ClassicInfo.version });
|
|
227
|
+
}
|
|
228
|
+
return answer;
|
|
229
|
+
}, Promise.resolve(clientAnswer));
|
|
230
|
+
// Need to as cast here.
|
|
231
|
+
clientAnswer.endpointPayloadPromise.then((endpointPayload) => strategy.addEndpoint(clientIdentity.endpointId, endpointPayload));
|
|
232
|
+
ackToSender.payload.payload.result = res;
|
|
233
|
+
ackToSender.payload.payload.answer = clientAnswer;
|
|
234
|
+
return this.wire.sendRaw(ackToSender);
|
|
235
|
+
}
|
|
236
|
+
catch (e) {
|
|
237
|
+
ackToSender.payload.success = false;
|
|
238
|
+
ackToSender.payload.reason = e.message;
|
|
239
|
+
return this.wire.sendRaw(ackToSender);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
exports.ConnectionManager = ConnectionManager;
|
|
244
|
+
_messageReceiver = new WeakMap(), _rtcConnectionManager = new WeakMap();
|
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import ChannelClient from './client';
|
|
2
|
-
import { ChannelProvider } from './provider';
|
|
3
|
-
import { EmitterBase } from '../../base';
|
|
4
|
-
import Transport from '../../../transport/transport';
|
|
5
|
-
import { ChannelEvents } from '../../events/channel';
|
|
6
|
-
import ProviderIdentity = OpenFin.ProviderIdentity;
|
|
7
|
-
import Identity = OpenFin.Identity;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
1
|
+
import ChannelClient from './client';
|
|
2
|
+
import { ChannelProvider } from './provider';
|
|
3
|
+
import { EmitterBase } from '../../base';
|
|
4
|
+
import Transport, { Message } from '../../../transport/transport';
|
|
5
|
+
import { ChannelEvents } from '../../events/channel';
|
|
6
|
+
import ProviderIdentity = OpenFin.ProviderIdentity;
|
|
7
|
+
import Identity = OpenFin.Identity;
|
|
8
|
+
export interface ChannelMessage extends Message<any> {
|
|
9
|
+
senderIdentity: Identity;
|
|
10
|
+
ackToSender: any;
|
|
11
|
+
providerIdentity: ProviderIdentity;
|
|
12
|
+
connectAction: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare class Channel extends EmitterBase<ChannelEvents> {
|
|
15
|
+
#private;
|
|
16
|
+
constructor(wire: Transport);
|
|
17
|
+
getAllChannels(): Promise<ProviderIdentity[]>;
|
|
18
|
+
onChannelConnect(listener: (...args: any[]) => void): Promise<void>;
|
|
19
|
+
onChannelDisconnect(listener: (...args: any[]) => void): Promise<void>;
|
|
20
|
+
connect(channelName: string, options?: OpenFin.ChannelConnectOptions): Promise<ChannelClient>;
|
|
21
|
+
create(channelName: string, options?: OpenFin.ChannelCreateOptions): Promise<ChannelProvider>;
|
|
22
|
+
}
|