@openfin/core 33.76.36 → 33.77.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/OpenFin.d.ts +1 -1
- package/README.md +29 -4
- package/fin.d.ts +2 -2
- package/{src → out}/GlobalOpenFin.d.ts +1 -1
- package/out/mock-alpha.d.ts +16112 -0
- package/out/mock-beta.d.ts +16112 -0
- package/out/mock-public.d.ts +16112 -0
- package/out/mock.d.ts +16797 -0
- package/out/mock.js +17111 -0
- package/package.json +30 -23
- package/LICENSE +0 -13
- package/NOTICE +0 -16
- package/openfin-core-33.76.36.tgz +0 -0
- package/src/OpenFin.d.ts +0 -3091
- package/src/OpenFin.js +0 -2
- package/src/api/api-exposer/api-consumer.d.ts +0 -28
- package/src/api/api-exposer/api-consumer.js +0 -28
- package/src/api/api-exposer/api-exposer.d.ts +0 -35
- package/src/api/api-exposer/api-exposer.js +0 -38
- package/src/api/api-exposer/decorators.d.ts +0 -10
- package/src/api/api-exposer/decorators.js +0 -18
- package/src/api/api-exposer/index.d.ts +0 -4
- package/src/api/api-exposer/index.js +0 -20
- package/src/api/api-exposer/strategies/index.d.ts +0 -1
- package/src/api/api-exposer/strategies/index.js +0 -17
- package/src/api/api-exposer/strategies/openfin-channels/channels-consumer.d.ts +0 -14
- package/src/api/api-exposer/strategies/openfin-channels/channels-consumer.js +0 -20
- package/src/api/api-exposer/strategies/openfin-channels/channels-exposer.d.ts +0 -20
- package/src/api/api-exposer/strategies/openfin-channels/channels-exposer.js +0 -23
- package/src/api/api-exposer/strategies/openfin-channels/index.d.ts +0 -2
- package/src/api/api-exposer/strategies/openfin-channels/index.js +0 -18
- package/src/api/application/Factory.d.ts +0 -196
- package/src/api/application/Factory.js +0 -278
- package/src/api/application/Instance.d.ts +0 -692
- package/src/api/application/Instance.js +0 -821
- package/src/api/application/index.d.ts +0 -12
- package/src/api/application/index.js +0 -28
- package/src/api/base.d.ts +0 -117
- package/src/api/base.js +0 -246
- package/src/api/clipboard/index.d.ts +0 -172
- package/src/api/clipboard/index.js +0 -200
- package/src/api/events/application.d.ts +0 -158
- package/src/api/events/application.js +0 -14
- package/src/api/events/base.d.ts +0 -42
- package/src/api/events/base.js +0 -2
- package/src/api/events/channel.d.ts +0 -35
- package/src/api/events/channel.js +0 -7
- package/src/api/events/emitterMap.d.ts +0 -11
- package/src/api/events/emitterMap.js +0 -35
- package/src/api/events/eventAggregator.d.ts +0 -5
- package/src/api/events/eventAggregator.js +0 -35
- package/src/api/events/externalApplication.d.ts +0 -24
- package/src/api/events/externalApplication.js +0 -7
- package/src/api/events/frame.d.ts +0 -35
- package/src/api/events/frame.js +0 -2
- package/src/api/events/globalHotkey.d.ts +0 -25
- package/src/api/events/globalHotkey.js +0 -2
- package/src/api/events/platform.d.ts +0 -34
- package/src/api/events/platform.js +0 -10
- package/src/api/events/system.d.ts +0 -126
- package/src/api/events/system.js +0 -15
- package/src/api/events/typedEventEmitter.d.ts +0 -20
- package/src/api/events/typedEventEmitter.js +0 -2
- package/src/api/events/view.d.ts +0 -92
- package/src/api/events/view.js +0 -12
- package/src/api/events/webcontents.d.ts +0 -277
- package/src/api/events/webcontents.js +0 -13
- package/src/api/events/window.d.ts +0 -421
- package/src/api/events/window.js +0 -12
- package/src/api/external-application/Factory.d.ts +0 -34
- package/src/api/external-application/Factory.js +0 -47
- package/src/api/external-application/Instance.d.ts +0 -110
- package/src/api/external-application/Instance.js +0 -117
- package/src/api/external-application/index.d.ts +0 -12
- package/src/api/external-application/index.js +0 -28
- package/src/api/fin.d.ts +0 -54
- package/src/api/fin.js +0 -45
- package/src/api/frame/Factory.d.ts +0 -54
- package/src/api/frame/Factory.js +0 -86
- package/src/api/frame/Instance.d.ts +0 -136
- package/src/api/frame/Instance.js +0 -143
- package/src/api/frame/index.d.ts +0 -14
- package/src/api/frame/index.js +0 -30
- package/src/api/global-hotkey/index.d.ts +0 -106
- package/src/api/global-hotkey/index.js +0 -132
- package/src/api/interappbus/channel/channel.d.ts +0 -285
- package/src/api/interappbus/channel/channel.js +0 -334
- package/src/api/interappbus/channel/channels-docs.d.ts +0 -342
- package/src/api/interappbus/channel/channels-docs.js +0 -401
- package/src/api/interappbus/channel/client.d.ts +0 -117
- package/src/api/interappbus/channel/client.js +0 -181
- package/src/api/interappbus/channel/connection-manager.d.ts +0 -29
- package/src/api/interappbus/channel/connection-manager.js +0 -246
- package/src/api/interappbus/channel/index.d.ts +0 -189
- package/src/api/interappbus/channel/index.js +0 -333
- package/src/api/interappbus/channel/protocols/classic/message-receiver.d.ts +0 -13
- package/src/api/interappbus/channel/protocols/classic/message-receiver.js +0 -73
- package/src/api/interappbus/channel/protocols/classic/strategy.d.ts +0 -24
- package/src/api/interappbus/channel/protocols/classic/strategy.js +0 -101
- package/src/api/interappbus/channel/protocols/combined/strategy.d.ts +0 -20
- package/src/api/interappbus/channel/protocols/combined/strategy.js +0 -58
- package/src/api/interappbus/channel/protocols/index.d.ts +0 -47
- package/src/api/interappbus/channel/protocols/index.js +0 -2
- package/src/api/interappbus/channel/protocols/protocol-manager.d.ts +0 -10
- package/src/api/interappbus/channel/protocols/protocol-manager.js +0 -43
- package/src/api/interappbus/channel/protocols/rtc/endpoint.d.ts +0 -25
- package/src/api/interappbus/channel/protocols/rtc/endpoint.js +0 -141
- package/src/api/interappbus/channel/protocols/rtc/ice-manager.d.ts +0 -30
- package/src/api/interappbus/channel/protocols/rtc/ice-manager.js +0 -130
- package/src/api/interappbus/channel/protocols/rtc/strategy.d.ts +0 -24
- package/src/api/interappbus/channel/protocols/rtc/strategy.js +0 -85
- package/src/api/interappbus/channel/protocols/strategy-types.d.ts +0 -13
- package/src/api/interappbus/channel/protocols/strategy-types.js +0 -2
- package/src/api/interappbus/channel/protocols/strategy.d.ts +0 -17
- package/src/api/interappbus/channel/protocols/strategy.js +0 -2
- package/src/api/interappbus/channel/provider.d.ts +0 -206
- package/src/api/interappbus/channel/provider.js +0 -338
- package/src/api/interappbus/index.d.ts +0 -120
- package/src/api/interappbus/index.js +0 -210
- package/src/api/interop/Factory.d.ts +0 -57
- package/src/api/interop/Factory.js +0 -96
- package/src/api/interop/InteropBroker.d.ts +0 -665
- package/src/api/interop/InteropBroker.js +0 -1313
- package/src/api/interop/InteropClient.d.ts +0 -502
- package/src/api/interop/InteropClient.js +0 -683
- package/src/api/interop/SessionContextGroupBroker.d.ts +0 -27
- package/src/api/interop/SessionContextGroupBroker.js +0 -108
- package/src/api/interop/SessionContextGroupClient.d.ts +0 -21
- package/src/api/interop/SessionContextGroupClient.js +0 -86
- package/src/api/interop/fdc3/PrivateChannelClient.d.ts +0 -20
- package/src/api/interop/fdc3/PrivateChannelClient.js +0 -90
- package/src/api/interop/fdc3/PrivateChannelProvider.d.ts +0 -55
- package/src/api/interop/fdc3/PrivateChannelProvider.js +0 -276
- package/src/api/interop/fdc3/documentationStub.d.ts +0 -14
- package/src/api/interop/fdc3/documentationStub.js +0 -17
- package/src/api/interop/fdc3/fdc3-1.2.d.ts +0 -205
- package/src/api/interop/fdc3/fdc3-1.2.js +0 -435
- package/src/api/interop/fdc3/fdc3-2.0.d.ts +0 -298
- package/src/api/interop/fdc3/fdc3-2.0.js +0 -479
- package/src/api/interop/fdc3/fdc3.d.ts +0 -12
- package/src/api/interop/fdc3/fdc3.js +0 -35
- package/src/api/interop/fdc3/overrideCheck.d.ts +0 -4
- package/src/api/interop/fdc3/overrideCheck.js +0 -32
- package/src/api/interop/fdc3/shapes/fdc3v1.d.ts +0 -53
- package/src/api/interop/fdc3/shapes/fdc3v1.js +0 -4
- package/src/api/interop/fdc3/shapes/fdc3v2.d.ts +0 -75
- package/src/api/interop/fdc3/shapes/fdc3v2.js +0 -2
- package/src/api/interop/fdc3/utils.d.ts +0 -45
- package/src/api/interop/fdc3/utils.js +0 -239
- package/src/api/interop/fdc3/versions.d.ts +0 -1
- package/src/api/interop/fdc3/versions.js +0 -2
- package/src/api/interop/index.d.ts +0 -12
- package/src/api/interop/index.js +0 -28
- package/src/api/interop/utils.d.ts +0 -18
- package/src/api/interop/utils.js +0 -61
- package/src/api/me.d.ts +0 -40
- package/src/api/me.js +0 -134
- package/src/api/platform/Factory.d.ts +0 -171
- package/src/api/platform/Factory.js +0 -240
- package/src/api/platform/Instance.d.ts +0 -653
- package/src/api/platform/Instance.js +0 -834
- package/src/api/platform/common-utils.d.ts +0 -7
- package/src/api/platform/common-utils.js +0 -16
- package/src/api/platform/index.d.ts +0 -12
- package/src/api/platform/index.js +0 -28
- package/src/api/platform/layout/Factory.d.ts +0 -91
- package/src/api/platform/layout/Factory.js +0 -151
- package/src/api/platform/layout/Instance.d.ts +0 -192
- package/src/api/platform/layout/Instance.js +0 -224
- package/src/api/platform/layout/controllers/layout-content-cache.d.ts +0 -9
- package/src/api/platform/layout/controllers/layout-content-cache.js +0 -54
- package/src/api/platform/layout/controllers/layout-entities-controller.d.ts +0 -119
- package/src/api/platform/layout/controllers/layout-entities-controller.js +0 -287
- package/src/api/platform/layout/entities/layout-entities.d.ts +0 -427
- package/src/api/platform/layout/entities/layout-entities.js +0 -504
- package/src/api/platform/layout/entities/shapes.d.ts +0 -6
- package/src/api/platform/layout/entities/shapes.js +0 -2
- package/src/api/platform/layout/index.d.ts +0 -11
- package/src/api/platform/layout/index.js +0 -27
- package/src/api/platform/layout/layout.constants.d.ts +0 -1
- package/src/api/platform/layout/layout.constants.js +0 -4
- package/src/api/platform/layout/shapes.d.ts +0 -16
- package/src/api/platform/layout/shapes.js +0 -2
- package/src/api/platform/layout/utils/layout-traversal.d.ts +0 -4
- package/src/api/platform/layout/utils/layout-traversal.js +0 -65
- package/src/api/platform/provider.d.ts +0 -510
- package/src/api/platform/provider.js +0 -2
- package/src/api/snapshot-source/Factory.d.ts +0 -53
- package/src/api/snapshot-source/Factory.js +0 -81
- package/src/api/snapshot-source/Instance.d.ts +0 -53
- package/src/api/snapshot-source/Instance.js +0 -154
- package/src/api/snapshot-source/index.d.ts +0 -12
- package/src/api/snapshot-source/index.js +0 -28
- package/src/api/snapshot-source/utils.d.ts +0 -2
- package/src/api/snapshot-source/utils.js +0 -6
- package/src/api/system/index.d.ts +0 -1468
- package/src/api/system/index.js +0 -1851
- package/src/api/view/Factory.d.ts +0 -88
- package/src/api/view/Factory.js +0 -141
- package/src/api/view/Instance.d.ts +0 -601
- package/src/api/view/Instance.js +0 -671
- package/src/api/view/index.d.ts +0 -12
- package/src/api/view/index.js +0 -28
- package/src/api/webcontents/main.d.ts +0 -922
- package/src/api/webcontents/main.js +0 -1046
- package/src/api/window/Factory.d.ts +0 -96
- package/src/api/window/Factory.js +0 -142
- package/src/api/window/Instance.d.ts +0 -1598
- package/src/api/window/Instance.js +0 -1851
- package/src/api/window/index.d.ts +0 -14
- package/src/api/window/index.js +0 -30
- package/src/browser.d.ts +0 -10
- package/src/browser.js +0 -36
- package/src/environment/browser.d.ts +0 -29
- package/src/environment/browser.js +0 -60
- package/src/environment/environment.d.ts +0 -33
- package/src/environment/environment.js +0 -4
- package/src/environment/mockEnvironment.d.ts +0 -27
- package/src/environment/mockEnvironment.js +0 -61
- package/src/environment/node-env.d.ts +0 -29
- package/src/environment/node-env.js +0 -72
- package/src/fdc3.d.ts +0 -3
- package/src/fdc3.js +0 -9
- package/src/mock.d.ts +0 -3
- package/src/mock.js +0 -18
- package/src/namespaces.d.ts +0 -22
- package/src/namespaces.js +0 -26
- package/src/shapes/ERROR_BOX_TYPES.d.ts +0 -1
- package/src/shapes/ERROR_BOX_TYPES.js +0 -2
- package/src/shapes/WebOptions.d.ts +0 -13
- package/src/shapes/WebOptions.js +0 -2
- package/src/shapes/WindowOptions.d.ts +0 -43
- package/src/shapes/WindowOptions.js +0 -2
- package/src/shapes/protocol.d.ts +0 -204
- package/src/shapes/protocol.js +0 -2
- package/src/transport/mockWire.d.ts +0 -11
- package/src/transport/mockWire.js +0 -26
- package/src/transport/transport-errors.d.ts +0 -31
- package/src/transport/transport-errors.js +0 -79
- package/src/transport/transport.d.ts +0 -73
- package/src/transport/transport.js +0 -219
- package/src/transport/wire.d.ts +0 -77
- package/src/transport/wire.js +0 -36
- package/src/util/asyncFilter.d.ts +0 -1
- package/src/util/asyncFilter.js +0 -7
- package/src/util/channel-api-relay.d.ts +0 -13
- package/src/util/channel-api-relay.js +0 -47
- package/src/util/errors.d.ts +0 -10
- package/src/util/errors.js +0 -12
- package/src/util/exhaustive.d.ts +0 -1
- package/src/util/exhaustive.js +0 -7
- package/src/util/http.d.ts +0 -11
- package/src/util/http.js +0 -90
- package/src/util/inaccessibleObject.d.ts +0 -2
- package/src/util/inaccessibleObject.js +0 -49
- package/src/util/lazy.d.ts +0 -34
- package/src/util/lazy.js +0 -54
- package/src/util/normalize-config.d.ts +0 -3
- package/src/util/normalize-config.js +0 -52
- package/src/util/promises.d.ts +0 -5
- package/src/util/promises.js +0 -27
- package/src/util/ref-counter.d.ts +0 -7
- package/src/util/ref-counter.js +0 -52
- package/src/util/reversible-map.d.ts +0 -11
- package/src/util/reversible-map.js +0 -49
- package/src/util/runtimeVersioning.d.ts +0 -3
- package/src/util/runtimeVersioning.js +0 -25
- package/src/util/utilTypes.d.ts +0 -8
- package/src/util/utilTypes.js +0 -2
- package/src/util/validate.d.ts +0 -3
- package/src/util/validate.js +0 -11
|
@@ -1,333 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
-
};
|
|
8
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
-
};
|
|
13
|
-
var _Channel_connectionManager, _Channel_internalEmitter, _Channel_readyToConnect;
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.Channel = void 0;
|
|
16
|
-
/* eslint-disable no-console */
|
|
17
|
-
const events_1 = require("events");
|
|
18
|
-
const lazy_1 = require("../../../util/lazy");
|
|
19
|
-
const base_1 = require("../../base");
|
|
20
|
-
const client_1 = require("./client");
|
|
21
|
-
const connection_manager_1 = require("./connection-manager");
|
|
22
|
-
const provider_1 = require("./provider");
|
|
23
|
-
function retryDelay(count) {
|
|
24
|
-
const interval = 500; // base delay
|
|
25
|
-
const steps = 10; // How many retries to do before incrementing the delay
|
|
26
|
-
const base = 2; // How much to multiply the previous delay by
|
|
27
|
-
const max = 30000; // max delay
|
|
28
|
-
const step = Math.floor(count / steps);
|
|
29
|
-
const delay = Math.min(max, interval * base ** step);
|
|
30
|
-
return new Promise((resolve) => {
|
|
31
|
-
setTimeout(() => {
|
|
32
|
-
resolve(false);
|
|
33
|
-
}, delay);
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* The Channel API allows an OpenFin application to create a channel as a {@link ChannelProvider ChannelProvider},
|
|
38
|
-
* or connect to a channel as a {@link ChannelClient ChannelClient}.
|
|
39
|
-
* @remarks The "handshake" between the communication partners is
|
|
40
|
-
* simplified when using a channel. A request to connect to a channel as a client will return a promise that resolves if/when the channel has been created. Both the
|
|
41
|
-
* provider and client can dispatch actions that have been registered on their opposites, and dispatch returns a promise that resolves with a payload from the other
|
|
42
|
-
* communication participant. There can be only one provider per channel, but many clients. Version `9.61.35.*` or later is required for both communication partners.
|
|
43
|
-
*
|
|
44
|
-
* Asynchronous Methods:
|
|
45
|
-
* * {@link Channel.create create(channelName, options)}
|
|
46
|
-
* * {@link Channel.connect connect(channelName, options)}
|
|
47
|
-
* * {@link Channel.onChannelConnect onChannelConnect(listener)}
|
|
48
|
-
* * {@link Channel.onChannelDisconnect onChannelDisconnect(listener)}
|
|
49
|
-
*/
|
|
50
|
-
class Channel extends base_1.EmitterBase {
|
|
51
|
-
/**
|
|
52
|
-
* @internal
|
|
53
|
-
*/
|
|
54
|
-
constructor(wire) {
|
|
55
|
-
super(wire, 'channel');
|
|
56
|
-
_Channel_connectionManager.set(this, void 0);
|
|
57
|
-
_Channel_internalEmitter.set(this, new events_1.EventEmitter());
|
|
58
|
-
// OpenFin API has not been injected at construction time, *must* wait for API to be ready.
|
|
59
|
-
_Channel_readyToConnect.set(this, new lazy_1.AsyncRetryableLazy(async () => {
|
|
60
|
-
await Promise.all([
|
|
61
|
-
this.on('disconnected', (eventPayload) => {
|
|
62
|
-
client_1.default.handleProviderDisconnect(eventPayload);
|
|
63
|
-
}),
|
|
64
|
-
this.on('connected', (...args) => {
|
|
65
|
-
__classPrivateFieldGet(this, _Channel_internalEmitter, "f").emit('connected', ...args);
|
|
66
|
-
})
|
|
67
|
-
]).catch(() => new Error('error setting up channel connection listeners'));
|
|
68
|
-
}));
|
|
69
|
-
__classPrivateFieldSet(this, _Channel_connectionManager, new connection_manager_1.ConnectionManager(wire), "f");
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
*
|
|
73
|
-
* @internal
|
|
74
|
-
*/
|
|
75
|
-
async getAllChannels() {
|
|
76
|
-
return this.wire.sendAction('get-all-channels').then(({ payload }) => payload.data);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Listens for channel connections.
|
|
80
|
-
*
|
|
81
|
-
* @param listener - callback to execute.
|
|
82
|
-
*
|
|
83
|
-
* @example
|
|
84
|
-
*
|
|
85
|
-
* ```js
|
|
86
|
-
* const listener = (channelPayload) => console.log(channelPayload); // see return value below
|
|
87
|
-
*
|
|
88
|
-
* fin.InterApplicationBus.Channel.onChannelConnect(listener);
|
|
89
|
-
*
|
|
90
|
-
* // example shape
|
|
91
|
-
* {
|
|
92
|
-
* "topic": "channel",
|
|
93
|
-
* "type": "connected",
|
|
94
|
-
* "uuid": "OpenfinPOC",
|
|
95
|
-
* "name": "OpenfinPOC",
|
|
96
|
-
* "channelName": "counter",
|
|
97
|
-
* "channelId": "OpenfinPOC/OpenfinPOC/counter"
|
|
98
|
-
* }
|
|
99
|
-
*
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
|
-
async onChannelConnect(listener) {
|
|
103
|
-
await this.on('connected', listener);
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Listen for channel disconnections.
|
|
107
|
-
*
|
|
108
|
-
* @param listener - callback to execute.
|
|
109
|
-
*
|
|
110
|
-
* @example
|
|
111
|
-
*
|
|
112
|
-
* ```js
|
|
113
|
-
* const listener = (channelPayload) => console.log(channelPayload); // see return value below
|
|
114
|
-
*
|
|
115
|
-
* fin.InterApplicationBus.Channel.onChannelDisconnect(listener);
|
|
116
|
-
*
|
|
117
|
-
* // example shape
|
|
118
|
-
* {
|
|
119
|
-
* "topic": "channel",
|
|
120
|
-
* "type": "disconnected",
|
|
121
|
-
* "uuid": "OpenfinPOC",
|
|
122
|
-
* "name": "OpenfinPOC",
|
|
123
|
-
* "channelName": "counter",
|
|
124
|
-
* "channelId": "OpenfinPOC/OpenfinPOC/counter"
|
|
125
|
-
* }
|
|
126
|
-
*
|
|
127
|
-
* ```
|
|
128
|
-
*/
|
|
129
|
-
async onChannelDisconnect(listener) {
|
|
130
|
-
await this.on('disconnected', listener);
|
|
131
|
-
}
|
|
132
|
-
async safeConnect(channelName, shouldWait, connectPayload) {
|
|
133
|
-
const retryInfo = { count: 0 };
|
|
134
|
-
/* eslint-disable no-await-in-loop, no-constant-condition */
|
|
135
|
-
do {
|
|
136
|
-
// setup a listener and a connected promise to await in case we connect before the channel is ready
|
|
137
|
-
let connectedListener = () => undefined;
|
|
138
|
-
const connectedPromise = new Promise((resolve) => {
|
|
139
|
-
connectedListener = (payload) => {
|
|
140
|
-
if (channelName === payload.channelName) {
|
|
141
|
-
resolve(true);
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
__classPrivateFieldGet(this, _Channel_internalEmitter, "f").on('connected', connectedListener);
|
|
145
|
-
});
|
|
146
|
-
try {
|
|
147
|
-
if (retryInfo.count > 0) {
|
|
148
|
-
// Wait before retrying
|
|
149
|
-
// Delay returns false connectedPromise returns true so we can know if a retry is due to connected event
|
|
150
|
-
retryInfo.gotConnectedEvent = await Promise.race([retryDelay(retryInfo.count), connectedPromise]);
|
|
151
|
-
const result = await this.wire.sendAction('connect-to-channel', { ...connectPayload, retryInfo });
|
|
152
|
-
// log only if there was a retry
|
|
153
|
-
console.log(`Successfully connected to channelName: ${channelName}`);
|
|
154
|
-
return result.payload.data;
|
|
155
|
-
}
|
|
156
|
-
// Send retryInfo to the core for debug log inclusion
|
|
157
|
-
const sentMessagePromise = this.wire.sendAction('connect-to-channel', connectPayload);
|
|
158
|
-
// Save messageId from the first connection attempt
|
|
159
|
-
retryInfo.originalMessageId = sentMessagePromise.messageId;
|
|
160
|
-
const result = await sentMessagePromise;
|
|
161
|
-
return result.payload.data;
|
|
162
|
-
}
|
|
163
|
-
catch (error) {
|
|
164
|
-
if (!error.message.includes('internal-nack')) {
|
|
165
|
-
// Not an internal nack, break the loop
|
|
166
|
-
throw error;
|
|
167
|
-
}
|
|
168
|
-
if (shouldWait && retryInfo.count === 0) {
|
|
169
|
-
// start waiting on the next iteration, warn the user
|
|
170
|
-
console.warn(`No channel found for channelName: ${channelName}. Waiting for connection...`);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
finally {
|
|
174
|
-
retryInfo.count += 1;
|
|
175
|
-
// in case of other errors, remove our listener
|
|
176
|
-
__classPrivateFieldGet(this, _Channel_internalEmitter, "f").removeListener('connected', connectedListener);
|
|
177
|
-
}
|
|
178
|
-
} while (shouldWait); // If we're waiting we retry the above loop
|
|
179
|
-
// Should wait was false, no channel was found.
|
|
180
|
-
throw new Error(`No channel found for channelName: ${channelName}.`);
|
|
181
|
-
/* eslint-enable no-await-in-loop, no-constant-condition */
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Connect to a channel. If you wish to send a payload to the provider, add a payload property to the options argument.
|
|
185
|
-
* EXPERIMENTAL: pass { protocols: ['rtc'] } as options to opt-in to High Throughput Channels.
|
|
186
|
-
*
|
|
187
|
-
* @param channelName - Name of the target channel.
|
|
188
|
-
* @param options - Connection options.
|
|
189
|
-
* @returns Returns a promise that resolves with an instance of {@link ChannelClient ChannelClient}.
|
|
190
|
-
*
|
|
191
|
-
* @remarks The connection request will be routed to the channelProvider if/when the channel is created. If the connect
|
|
192
|
-
* request is sent prior to creation, the promise will not resolve or reject until the channel is created by a channelProvider
|
|
193
|
-
* (whether or not to wait for creation is configurable in the connectOptions).
|
|
194
|
-
*
|
|
195
|
-
* The connect call returns a promise that will resolve with a channelClient bus if accepted by the channelProvider, or reject if
|
|
196
|
-
* the channelProvider throws an error to reject the connection. This bus can communicate with the Provider, but not to other
|
|
197
|
-
* clients on the channel. Using the bus, the channelClient can register actions and middleware. Channel lifecycle can also be
|
|
198
|
-
* handled with an onDisconnection listener.
|
|
199
|
-
*
|
|
200
|
-
* @example
|
|
201
|
-
*
|
|
202
|
-
* ```js
|
|
203
|
-
* async function makeClient(channelName) {
|
|
204
|
-
* // A payload can be sent along with channel connection requests to help with authentication
|
|
205
|
-
* const connectPayload = { payload: 'token' };
|
|
206
|
-
*
|
|
207
|
-
* // If the channel has been created this request will be sent to the provider. If not, the
|
|
208
|
-
* // promise will not be resolved or rejected until the channel has been created.
|
|
209
|
-
* const clientBus = await fin.InterApplicationBus.Channel.connect(channelName, connectPayload);
|
|
210
|
-
*
|
|
211
|
-
* clientBus.onDisconnection(channelInfo => {
|
|
212
|
-
* // handle the channel lifecycle here - we can connect again which will return a promise
|
|
213
|
-
* // that will resolve if/when the channel is re-created.
|
|
214
|
-
* makeClient(channelInfo.channelName);
|
|
215
|
-
* })
|
|
216
|
-
*
|
|
217
|
-
* clientBus.register('topic', (payload, identity) => {
|
|
218
|
-
* // register a callback for a topic to which the channel provider can dispatch an action
|
|
219
|
-
* console.log('Action dispatched by provider: ', JSON.stringify(identity));
|
|
220
|
-
* console.log('Payload sent in dispatch: ', JSON.stringify(payload));
|
|
221
|
-
* return {
|
|
222
|
-
* echo: payload
|
|
223
|
-
* };
|
|
224
|
-
* });
|
|
225
|
-
* }
|
|
226
|
-
*
|
|
227
|
-
* makeClient('channelName')
|
|
228
|
-
* .then(() => console.log('Connected'))
|
|
229
|
-
* .catch(console.error);
|
|
230
|
-
* ```
|
|
231
|
-
*/
|
|
232
|
-
async connect(channelName, options = {}) {
|
|
233
|
-
// Make sure we don't connect before listeners are set up
|
|
234
|
-
// This also errors if we're not in OpenFin, ensuring we don't run unnecessary code
|
|
235
|
-
await __classPrivateFieldGet(this, _Channel_readyToConnect, "f").getValue();
|
|
236
|
-
if (!channelName || typeof channelName !== 'string') {
|
|
237
|
-
throw new Error('Please provide a channelName string to connect to a channel.');
|
|
238
|
-
}
|
|
239
|
-
const opts = { wait: true, ...this.wire.environment.getDefaultChannelOptions().connect, ...options };
|
|
240
|
-
const { offer, rtc: rtcPacket } = await __classPrivateFieldGet(this, _Channel_connectionManager, "f").createClientOffer(opts);
|
|
241
|
-
let connectionUrl;
|
|
242
|
-
if (this.fin.me.isFrame || this.fin.me.isView || this.fin.me.isWindow) {
|
|
243
|
-
connectionUrl = (await this.fin.me.getInfo()).url;
|
|
244
|
-
}
|
|
245
|
-
const connectPayload = {
|
|
246
|
-
channelName,
|
|
247
|
-
...opts,
|
|
248
|
-
offer,
|
|
249
|
-
connectionUrl
|
|
250
|
-
};
|
|
251
|
-
const routingInfo = await this.safeConnect(channelName, opts.wait, connectPayload);
|
|
252
|
-
const strategy = await __classPrivateFieldGet(this, _Channel_connectionManager, "f").createClientStrategy(rtcPacket, routingInfo);
|
|
253
|
-
const channel = new client_1.default(routingInfo, this.wire, strategy);
|
|
254
|
-
// It is the client's responsibility to handle endpoint disconnection to the provider.
|
|
255
|
-
// If the endpoint dies, the client will force a disconnection through the core.
|
|
256
|
-
// The provider does not care about endpoint disconnection.
|
|
257
|
-
strategy.onEndpointDisconnect(routingInfo.channelId, async () => {
|
|
258
|
-
try {
|
|
259
|
-
await channel.sendDisconnectAction();
|
|
260
|
-
}
|
|
261
|
-
catch (error) {
|
|
262
|
-
console.warn(`Something went wrong during disconnect for client with uuid: ${routingInfo.uuid} / name: ${routingInfo.name} / endpointId: ${routingInfo.endpointId}.`);
|
|
263
|
-
}
|
|
264
|
-
finally {
|
|
265
|
-
client_1.default.handleProviderDisconnect(routingInfo);
|
|
266
|
-
}
|
|
267
|
-
});
|
|
268
|
-
return channel;
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* Create a new channel.
|
|
272
|
-
* You must provide a unique channelName. If a channelName is not provided, or it is not unique, the creation will fail.
|
|
273
|
-
* EXPERIMENTAL: pass { protocols: ['rtc'] } as options to opt-in to High Throughput Channels.
|
|
274
|
-
*
|
|
275
|
-
* @param channelName - Name of the channel to be created.
|
|
276
|
-
* @param options - Creation options.
|
|
277
|
-
* @returns Returns a promise that resolves with an instance of {@link ChannelProvider ChannelProvider}.
|
|
278
|
-
*
|
|
279
|
-
* @remarks If successful, the create method returns a promise that resolves to an instance of the channelProvider bus. The caller
|
|
280
|
-
* then becomes the “channel provider” and can use the channelProvider bus to register actions and middleware.
|
|
281
|
-
*
|
|
282
|
-
* The caller can also set an onConnection and/or onDisconnection listener that will execute on any new channel
|
|
283
|
-
* connection/disconnection attempt from a channel client. To reject a connection, simply throw an error in the
|
|
284
|
-
* onConnection listener. The default behavior is to accept all new connections.
|
|
285
|
-
*
|
|
286
|
-
* A map of client connections is updated automatically on client connection and disconnection and saved in the
|
|
287
|
-
* [read-only] `connections` property on the channelProvider bus. The channel will exist until the provider
|
|
288
|
-
* destroys it or disconnects by closing or destroying the context (navigating or reloading). To setup a channel
|
|
289
|
-
* as a channelProvider, call `Channel.create` with a unique channel name. A map of client connections is updated
|
|
290
|
-
* automatically on client connection and disconnection.
|
|
291
|
-
*
|
|
292
|
-
* @example
|
|
293
|
-
*
|
|
294
|
-
* ```js
|
|
295
|
-
* (async ()=> {
|
|
296
|
-
* // entity creates a channel and becomes the channelProvider
|
|
297
|
-
* const providerBus = await fin.InterApplicationBus.Channel.create('channelName');
|
|
298
|
-
*
|
|
299
|
-
* providerBus.onConnection((identity, payload) => {
|
|
300
|
-
* // can reject a connection here by throwing an error
|
|
301
|
-
* console.log('Client connection request identity: ', JSON.stringify(identity));
|
|
302
|
-
* console.log('Client connection request payload: ', JSON.stringify(payload));
|
|
303
|
-
* });
|
|
304
|
-
*
|
|
305
|
-
* providerBus.register('topic', (payload, identity) => {
|
|
306
|
-
* // register a callback for a 'topic' to which clients can dispatch an action
|
|
307
|
-
* console.log('Action dispatched by client: ', JSON.stringify(identity));
|
|
308
|
-
* console.log('Payload sent in dispatch: ', JSON.stringify(payload));
|
|
309
|
-
* return {
|
|
310
|
-
* echo: payload
|
|
311
|
-
* };
|
|
312
|
-
* });
|
|
313
|
-
* })();
|
|
314
|
-
* ```
|
|
315
|
-
*/
|
|
316
|
-
async create(channelName, options) {
|
|
317
|
-
if (!channelName) {
|
|
318
|
-
throw new Error('Please provide a channelName to create a channel');
|
|
319
|
-
}
|
|
320
|
-
const { payload: { data: providerIdentity } } = await this.wire.sendAction('create-channel', { channelName });
|
|
321
|
-
const channel = __classPrivateFieldGet(this, _Channel_connectionManager, "f").createProvider(options, providerIdentity);
|
|
322
|
-
// TODO: fix typing (internal)
|
|
323
|
-
// @ts-expect-error
|
|
324
|
-
this.on('client-disconnected', (eventPayload) => {
|
|
325
|
-
if (eventPayload.channelName === channelName) {
|
|
326
|
-
provider_1.ChannelProvider.handleClientDisconnection(channel, eventPayload);
|
|
327
|
-
}
|
|
328
|
-
});
|
|
329
|
-
return channel;
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
exports.Channel = Channel;
|
|
333
|
-
_Channel_connectionManager = new WeakMap(), _Channel_internalEmitter = new WeakMap(), _Channel_readyToConnect = new WeakMap();
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Transport } from '../../../../../transport/transport';
|
|
2
|
-
import { Base } from '../../../../base';
|
|
3
|
-
import { ChannelBase } from '../../channel';
|
|
4
|
-
export declare class MessageReceiver extends Base {
|
|
5
|
-
private endpointMap;
|
|
6
|
-
private latestEndpointIdByChannelId;
|
|
7
|
-
constructor(wire: Transport);
|
|
8
|
-
private processChannelMessage;
|
|
9
|
-
private onmessage;
|
|
10
|
-
addEndpoint(handler: ChannelBase['processAction'], channelId: string, endpointId: string): void;
|
|
11
|
-
removeEndpoint(channelId: string, endpointId: string): void;
|
|
12
|
-
checkForPreviousClientConnection(channelId: string): void;
|
|
13
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MessageReceiver = void 0;
|
|
4
|
-
const client_1 = require("../../client");
|
|
5
|
-
const base_1 = require("../../../../base");
|
|
6
|
-
/*
|
|
7
|
-
This is a singleton (per fin object) tasked with routing messages coming off the ipc to the correct endpoint.
|
|
8
|
-
It needs to be a singleton because there can only be one per wire. It tracks both clients and providers' processAction passed in via the strategy.
|
|
9
|
-
If functionality is not about receiving messages, it does not belong here.
|
|
10
|
-
*/
|
|
11
|
-
class MessageReceiver extends base_1.Base {
|
|
12
|
-
constructor(wire) {
|
|
13
|
-
super(wire);
|
|
14
|
-
this.onmessage = (msg) => {
|
|
15
|
-
if (msg.action === 'process-channel-message') {
|
|
16
|
-
this.processChannelMessage(msg);
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
return false;
|
|
20
|
-
};
|
|
21
|
-
this.endpointMap = new Map();
|
|
22
|
-
this.latestEndpointIdByChannelId = new Map();
|
|
23
|
-
wire.registerMessageHandler(this.onmessage.bind(this));
|
|
24
|
-
}
|
|
25
|
-
async processChannelMessage(msg) {
|
|
26
|
-
var _a, _b;
|
|
27
|
-
const { senderIdentity, providerIdentity, action, ackToSender, payload, intendedTargetIdentity } = msg.payload;
|
|
28
|
-
const key = (_b = (_a = intendedTargetIdentity.channelId) !== null && _a !== void 0 ? _a : intendedTargetIdentity.endpointId) !== null && _b !== void 0 ? _b : this.latestEndpointIdByChannelId.get(providerIdentity.channelId); // No endpointId was passed, make best attempt
|
|
29
|
-
const handler = this.endpointMap.get(key);
|
|
30
|
-
if (!handler) {
|
|
31
|
-
ackToSender.payload.success = false;
|
|
32
|
-
ackToSender.payload.reason = `Client connection with identity uuid: ${this.wire.me.uuid} / name: ${this.wire.me.name} / endpointId: ${key} no longer connected.`;
|
|
33
|
-
return this.wire.sendRaw(ackToSender);
|
|
34
|
-
}
|
|
35
|
-
try {
|
|
36
|
-
const res = await handler(action, payload, senderIdentity);
|
|
37
|
-
ackToSender.payload.payload = ackToSender.payload.payload || {};
|
|
38
|
-
ackToSender.payload.payload.result = res;
|
|
39
|
-
return this.wire.sendRaw(ackToSender);
|
|
40
|
-
}
|
|
41
|
-
catch (e) {
|
|
42
|
-
ackToSender.payload.success = false;
|
|
43
|
-
ackToSender.payload.reason = e.message;
|
|
44
|
-
return this.wire.sendRaw(ackToSender);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
addEndpoint(handler, channelId, endpointId) {
|
|
48
|
-
this.endpointMap.set(endpointId, handler);
|
|
49
|
-
// Providers have the same endpointId and channelId.
|
|
50
|
-
// This is only used when clients are receiving messages from providers, so we shouldn't save provider endpointId here.
|
|
51
|
-
if (channelId !== endpointId) {
|
|
52
|
-
this.latestEndpointIdByChannelId.set(channelId, endpointId);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
removeEndpoint(channelId, endpointId) {
|
|
56
|
-
this.endpointMap.delete(endpointId);
|
|
57
|
-
if (this.latestEndpointIdByChannelId.get(channelId) === endpointId) {
|
|
58
|
-
this.latestEndpointIdByChannelId.delete(channelId);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
checkForPreviousClientConnection(channelId) {
|
|
62
|
-
const endpointIdFromPreviousConnection = this.latestEndpointIdByChannelId.get(channelId);
|
|
63
|
-
if (endpointIdFromPreviousConnection) {
|
|
64
|
-
// Not convinced by this way of doing things, but pushing up for now.
|
|
65
|
-
client_1.default.closeChannelByEndpointId(endpointIdFromPreviousConnection);
|
|
66
|
-
// eslint-disable-next-line no-console
|
|
67
|
-
console.warn('You have created a second connection to an older provider. First connection has been removed from the clientMap');
|
|
68
|
-
// eslint-disable-next-line no-console
|
|
69
|
-
console.warn('If the provider calls publish(), you may receive multiple messages.');
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
exports.MessageReceiver = MessageReceiver;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type * as OpenFin from '../../../../../OpenFin';
|
|
2
|
-
import { Transport } from '../../../../../transport/transport';
|
|
3
|
-
import { MessageReceiver } from './message-receiver';
|
|
4
|
-
import { ChannelStrategy, EndpointPayload } from '../strategy';
|
|
5
|
-
import { LocalSupportedProtocol } from '..';
|
|
6
|
-
type ProviderIdentity = OpenFin.ProviderIdentity;
|
|
7
|
-
export declare class ClassicStrategy implements ChannelStrategy<EndpointPayload> {
|
|
8
|
-
#private;
|
|
9
|
-
private messageReceiver;
|
|
10
|
-
private endpointId;
|
|
11
|
-
private providerIdentity;
|
|
12
|
-
constructor(wire: Transport, messageReceiver: MessageReceiver, endpointId: string, // Provider endpointId is channelId
|
|
13
|
-
providerIdentity: ProviderIdentity);
|
|
14
|
-
onEndpointDisconnect(endpointId: string, listener: () => void): void;
|
|
15
|
-
receive(listener: (action: string, payload: any, identity: OpenFin.ClientIdentity | OpenFin.ClientIdentityMultiRuntime | ProviderIdentity) => Promise<any>): void;
|
|
16
|
-
send: (endpointId: string, action: string, payload: any) => Promise<any>;
|
|
17
|
-
close: () => Promise<void>;
|
|
18
|
-
closeEndpoint(endpointId: string): Promise<void>;
|
|
19
|
-
isEndpointConnected(endpointId: string): boolean;
|
|
20
|
-
addEndpoint(endpointId: string, payload: EndpointPayload): void;
|
|
21
|
-
isValidEndpointPayload(payload: any): payload is EndpointPayload;
|
|
22
|
-
}
|
|
23
|
-
export declare const ClassicInfo: LocalSupportedProtocol;
|
|
24
|
-
export {};
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
-
};
|
|
8
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
-
};
|
|
13
|
-
var _ClassicStrategy_wire, _ClassicStrategy_endpointIdentityMap, _ClassicStrategy_pendingMessagesByEndpointId;
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.ClassicInfo = exports.ClassicStrategy = void 0;
|
|
16
|
-
/*
|
|
17
|
-
This is used to abstract out ipc messaging from the channels implementation. It is only concerned with sending messages and registration with the MessageReceiver
|
|
18
|
-
*/
|
|
19
|
-
class ClassicStrategy {
|
|
20
|
-
constructor(wire, messageReceiver, endpointId, // Provider endpointId is channelId
|
|
21
|
-
providerIdentity) {
|
|
22
|
-
this.messageReceiver = messageReceiver;
|
|
23
|
-
this.endpointId = endpointId;
|
|
24
|
-
this.providerIdentity = providerIdentity;
|
|
25
|
-
_ClassicStrategy_wire.set(this, void 0);
|
|
26
|
-
// Store full endpointIdentity by endpointId of all known endpoints for this strategy instance.
|
|
27
|
-
// (clients will only have 1: the provider, the provider will have all clients)
|
|
28
|
-
_ClassicStrategy_endpointIdentityMap.set(this, new Map());
|
|
29
|
-
// Store a set of cancellable promises to be able to reject them when client
|
|
30
|
-
// connection problems occur
|
|
31
|
-
_ClassicStrategy_pendingMessagesByEndpointId.set(this, new Map);
|
|
32
|
-
this.send = async (endpointId, action, payload) => {
|
|
33
|
-
var _a;
|
|
34
|
-
const to = __classPrivateFieldGet(this, _ClassicStrategy_endpointIdentityMap, "f").get(endpointId);
|
|
35
|
-
if (!to) {
|
|
36
|
-
throw new Error(`Could not locate routing info for endpoint ${endpointId}`);
|
|
37
|
-
}
|
|
38
|
-
// as casting to any because typescript complains. The following is only relevant if this is a locally set endpointId on a ClientIdentity.
|
|
39
|
-
// We delete these properties to not change backwards compatibility.
|
|
40
|
-
const cleanId = { ...to };
|
|
41
|
-
if (cleanId.isLocalEndpointId) {
|
|
42
|
-
delete cleanId.endpointId;
|
|
43
|
-
}
|
|
44
|
-
delete cleanId.isLocalEndpointId;
|
|
45
|
-
// grab the promise before awaiting it to save in our pending messages map
|
|
46
|
-
const p = __classPrivateFieldGet(this, _ClassicStrategy_wire, "f")
|
|
47
|
-
.sendAction('send-channel-message', {
|
|
48
|
-
...cleanId,
|
|
49
|
-
providerIdentity: this.providerIdentity,
|
|
50
|
-
action,
|
|
51
|
-
payload
|
|
52
|
-
});
|
|
53
|
-
(_a = __classPrivateFieldGet(this, _ClassicStrategy_pendingMessagesByEndpointId, "f").get(endpointId)) === null || _a === void 0 ? void 0 : _a.add(p);
|
|
54
|
-
const raw = await p.catch((error) => {
|
|
55
|
-
throw new Error(error.message);
|
|
56
|
-
}).finally(() => {
|
|
57
|
-
var _a;
|
|
58
|
-
// clean up the pending promise
|
|
59
|
-
(_a = __classPrivateFieldGet(this, _ClassicStrategy_pendingMessagesByEndpointId, "f").get(endpointId)) === null || _a === void 0 ? void 0 : _a.delete(p);
|
|
60
|
-
});
|
|
61
|
-
return raw.payload.data.result;
|
|
62
|
-
};
|
|
63
|
-
this.close = async () => {
|
|
64
|
-
this.messageReceiver.removeEndpoint(this.providerIdentity.channelId, this.endpointId);
|
|
65
|
-
[...__classPrivateFieldGet(this, _ClassicStrategy_endpointIdentityMap, "f").keys()].forEach((id) => this.closeEndpoint(id));
|
|
66
|
-
__classPrivateFieldSet(this, _ClassicStrategy_endpointIdentityMap, new Map(), "f");
|
|
67
|
-
};
|
|
68
|
-
__classPrivateFieldSet(this, _ClassicStrategy_wire, wire, "f");
|
|
69
|
-
}
|
|
70
|
-
onEndpointDisconnect(endpointId, listener) {
|
|
71
|
-
// Never fires for 'classic'.
|
|
72
|
-
}
|
|
73
|
-
receive(listener) {
|
|
74
|
-
this.messageReceiver.addEndpoint(listener, this.providerIdentity.channelId, this.endpointId);
|
|
75
|
-
}
|
|
76
|
-
async closeEndpoint(endpointId) {
|
|
77
|
-
const id = __classPrivateFieldGet(this, _ClassicStrategy_endpointIdentityMap, "f").get(endpointId);
|
|
78
|
-
__classPrivateFieldGet(this, _ClassicStrategy_endpointIdentityMap, "f").delete(endpointId);
|
|
79
|
-
const pendingSet = __classPrivateFieldGet(this, _ClassicStrategy_pendingMessagesByEndpointId, "f").get(endpointId);
|
|
80
|
-
pendingSet === null || pendingSet === void 0 ? void 0 : pendingSet.forEach((p) => {
|
|
81
|
-
const errorMsg = `Channel connection with identity uuid: ${id === null || id === void 0 ? void 0 : id.uuid} / name: ${id === null || id === void 0 ? void 0 : id.name} / endpointId: ${endpointId} no longer connected.`;
|
|
82
|
-
p.cancel(new Error(errorMsg));
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
isEndpointConnected(endpointId) {
|
|
86
|
-
return __classPrivateFieldGet(this, _ClassicStrategy_endpointIdentityMap, "f").has(endpointId);
|
|
87
|
-
}
|
|
88
|
-
addEndpoint(endpointId, payload) {
|
|
89
|
-
__classPrivateFieldGet(this, _ClassicStrategy_endpointIdentityMap, "f").set(endpointId, payload.endpointIdentity);
|
|
90
|
-
__classPrivateFieldGet(this, _ClassicStrategy_pendingMessagesByEndpointId, "f").set(endpointId, new Set());
|
|
91
|
-
}
|
|
92
|
-
isValidEndpointPayload(payload) {
|
|
93
|
-
var _a, _b;
|
|
94
|
-
return (typeof ((_a = payload === null || payload === void 0 ? void 0 : payload.endpointIdentity) === null || _a === void 0 ? void 0 : _a.endpointId) === 'string' ||
|
|
95
|
-
typeof ((_b = payload === null || payload === void 0 ? void 0 : payload.endpointIdentity) === null || _b === void 0 ? void 0 : _b.channelId) === 'string');
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
exports.ClassicStrategy = ClassicStrategy;
|
|
99
|
-
_ClassicStrategy_wire = new WeakMap(), _ClassicStrategy_endpointIdentityMap = new WeakMap(), _ClassicStrategy_pendingMessagesByEndpointId = new WeakMap();
|
|
100
|
-
// Arbitrarily starting at 5 to leave the door open to backfilling pre endpointId etc.
|
|
101
|
-
exports.ClassicInfo = { version: 5, minimumVersion: 0, type: 'classic' };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ChannelStrategy } from '../strategy';
|
|
2
|
-
type OverlapsOnlyIfMatching<T, U> = {
|
|
3
|
-
[K in Extract<keyof T, keyof U>]: U[K] extends T[K] ? U[K] : T[K] extends U[K] ? T[K] : never;
|
|
4
|
-
};
|
|
5
|
-
type OnlyIfCompatible<A, B, D = OverlapsOnlyIfMatching<A, B>> = D extends Record<any, never> ? keyof D extends never ? A | B : never : A | B;
|
|
6
|
-
export default class CombinedStrategy<A, B> implements ChannelStrategy<OnlyIfCompatible<A, B>> {
|
|
7
|
-
private primary;
|
|
8
|
-
private secondary;
|
|
9
|
-
static combine<A, B>(a: ChannelStrategy<A>, b: ChannelStrategy<B>): OnlyIfCompatible<A, B> extends never ? never : CombinedStrategy<A, B>;
|
|
10
|
-
private constructor();
|
|
11
|
-
onEndpointDisconnect(endpointId: string, listener: () => void): void;
|
|
12
|
-
isValidEndpointPayload(payload: unknown): payload is OnlyIfCompatible<A, B>;
|
|
13
|
-
closeEndpoint(endpointId: string): Promise<void>;
|
|
14
|
-
isEndpointConnected(endpoint: string): boolean;
|
|
15
|
-
addEndpoint(endpoint: string, payload: OnlyIfCompatible<A, B>): Promise<void>;
|
|
16
|
-
receive(listener: (action: string, payload: any, identity: any) => Promise<any>): void;
|
|
17
|
-
send(endpointId: string, action: string, payload: any): Promise<any>;
|
|
18
|
-
close(): Promise<void>;
|
|
19
|
-
}
|
|
20
|
-
export {};
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
class CombinedStrategy {
|
|
4
|
-
// Making this a static method because the constructor can't be typed.
|
|
5
|
-
// Otherwise it will error when calling addEndpoint but I'd rather the whole instance be typed as never.
|
|
6
|
-
static combine(a, b) {
|
|
7
|
-
return new CombinedStrategy(a, b);
|
|
8
|
-
}
|
|
9
|
-
// eslint-disable-next-line no-useless-constructor
|
|
10
|
-
constructor(primary, secondary) {
|
|
11
|
-
this.primary = primary;
|
|
12
|
-
this.secondary = secondary;
|
|
13
|
-
}
|
|
14
|
-
onEndpointDisconnect(endpointId, listener) {
|
|
15
|
-
this.primary.onEndpointDisconnect(endpointId, () => {
|
|
16
|
-
if (!this.secondary.isEndpointConnected(endpointId)) {
|
|
17
|
-
listener();
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
this.secondary.onEndpointDisconnect(endpointId, () => {
|
|
21
|
-
if (!this.primary.isEndpointConnected(endpointId)) {
|
|
22
|
-
listener();
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
isValidEndpointPayload(payload) {
|
|
27
|
-
return this.primary.isValidEndpointPayload(payload) || this.secondary.isValidEndpointPayload(payload);
|
|
28
|
-
}
|
|
29
|
-
async closeEndpoint(endpointId) {
|
|
30
|
-
await this.primary.closeEndpoint(endpointId);
|
|
31
|
-
await this.secondary.closeEndpoint(endpointId);
|
|
32
|
-
}
|
|
33
|
-
isEndpointConnected(endpoint) {
|
|
34
|
-
return this.primary.isEndpointConnected(endpoint) || this.secondary.isEndpointConnected(endpoint);
|
|
35
|
-
}
|
|
36
|
-
async addEndpoint(endpoint, payload) {
|
|
37
|
-
if (this.primary.isValidEndpointPayload(payload)) {
|
|
38
|
-
await this.primary.addEndpoint(endpoint, payload);
|
|
39
|
-
}
|
|
40
|
-
if (this.secondary.isValidEndpointPayload(payload)) {
|
|
41
|
-
await this.secondary.addEndpoint(endpoint, payload);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
receive(listener) {
|
|
45
|
-
this.primary.receive(listener);
|
|
46
|
-
this.secondary.receive(listener);
|
|
47
|
-
}
|
|
48
|
-
send(endpointId, action, payload) {
|
|
49
|
-
if (this.primary.isEndpointConnected(endpointId)) {
|
|
50
|
-
return this.primary.send(endpointId, action, payload);
|
|
51
|
-
}
|
|
52
|
-
return this.secondary.send(endpointId, action, payload);
|
|
53
|
-
}
|
|
54
|
-
async close() {
|
|
55
|
-
await Promise.all([this.primary.close(), this.secondary.close()]);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.default = CombinedStrategy;
|