@openfin/core 32.75.6 → 32.75.8
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/package.json
CHANGED
package/src/OpenFin.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export interface ChannelMessage extends Message<any> {
|
|
|
15
15
|
export declare class Channel extends EmitterBase<ChannelEvent> {
|
|
16
16
|
#private;
|
|
17
17
|
constructor(wire: Transport);
|
|
18
|
+
private channelExists;
|
|
18
19
|
getAllChannels(): Promise<ProviderIdentity[]>;
|
|
19
20
|
onChannelConnect(listener: (...args: any[]) => void): Promise<void>;
|
|
20
21
|
onChannelDisconnect(listener: (...args: any[]) => void): Promise<void>;
|
|
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
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
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _Channel_connectionManager;
|
|
13
|
+
var _Channel_connectionManager, _Channel_internalEmitter, _Channel_readyToConnect;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.Channel = void 0;
|
|
16
16
|
/* eslint-disable no-console */
|
|
@@ -18,16 +18,27 @@ const client_1 = require("./client");
|
|
|
18
18
|
const provider_1 = require("./provider");
|
|
19
19
|
const base_1 = require("../../base");
|
|
20
20
|
const connection_manager_1 = require("./connection-manager");
|
|
21
|
-
|
|
22
|
-
const noop = () => { };
|
|
21
|
+
const events_1 = require("events");
|
|
23
22
|
class Channel extends base_1.EmitterBase {
|
|
24
23
|
constructor(wire) {
|
|
25
24
|
super(wire, 'channel');
|
|
26
25
|
_Channel_connectionManager.set(this, void 0);
|
|
26
|
+
_Channel_internalEmitter.set(this, new events_1.EventEmitter());
|
|
27
|
+
_Channel_readyToConnect.set(this, void 0);
|
|
27
28
|
__classPrivateFieldSet(this, _Channel_connectionManager, new connection_manager_1.ConnectionManager(wire), "f");
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
// OpenFin API has not been injected at construction time, *must* wait for API to be ready.
|
|
30
|
+
__classPrivateFieldSet(this, _Channel_readyToConnect, this.wire.environment.whenReady().then(() => {
|
|
31
|
+
this.on('disconnected', (eventPayload) => {
|
|
32
|
+
client_1.default.handleProviderDisconnect(eventPayload);
|
|
33
|
+
}).catch((e) => console.error('Error setting up a disconnected listener:', e));
|
|
34
|
+
return this.on('connected', (...args) => {
|
|
35
|
+
__classPrivateFieldGet(this, _Channel_internalEmitter, "f").emit('connected', ...args);
|
|
36
|
+
});
|
|
37
|
+
}), "f");
|
|
38
|
+
}
|
|
39
|
+
async channelExists(channelName) {
|
|
40
|
+
const channels = await this.getAllChannels();
|
|
41
|
+
return channels.some((providerIdentity) => providerIdentity.channelName === channelName);
|
|
31
42
|
}
|
|
32
43
|
async getAllChannels() {
|
|
33
44
|
return this.wire.sendAction('get-all-channels').then(({ payload }) => payload.data);
|
|
@@ -38,47 +49,38 @@ class Channel extends base_1.EmitterBase {
|
|
|
38
49
|
async onChannelDisconnect(listener) {
|
|
39
50
|
await this.on('disconnected', listener);
|
|
40
51
|
}
|
|
41
|
-
async connect(channelName, options) {
|
|
52
|
+
async connect(channelName, options = {}) {
|
|
42
53
|
if (!channelName || typeof channelName !== 'string') {
|
|
43
54
|
throw new Error('Please provide a channelName string to connect to a channel.');
|
|
44
55
|
}
|
|
45
|
-
const opts =
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
const opts = { wait: true, ...this.wire.environment.getDefaultChannelOptions().connect, ...options };
|
|
57
|
+
const shouldWait = opts.wait;
|
|
58
|
+
if (shouldWait) {
|
|
59
|
+
const channelExists = await this.channelExists(channelName);
|
|
60
|
+
if (!channelExists) {
|
|
61
|
+
console.warn(`Channel not found for channelName: ${channelName}, waiting for channel connection.`);
|
|
62
|
+
// Safeguard to ensure 'connected' listener was already added if we need to wait.
|
|
63
|
+
await __classPrivateFieldGet(this, _Channel_readyToConnect, "f");
|
|
64
|
+
await new Promise((resolve) => {
|
|
65
|
+
const connectedListener = (payload) => {
|
|
66
|
+
if (channelName === payload.channelName) {
|
|
67
|
+
__classPrivateFieldGet(this, _Channel_internalEmitter, "f").removeListener('connected', connectedListener);
|
|
68
|
+
resolve();
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
__classPrivateFieldGet(this, _Channel_internalEmitter, "f").on('connected', connectedListener);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
58
75
|
try {
|
|
59
76
|
const { offer, rtc: rtcPacket } = await __classPrivateFieldGet(this, _Channel_connectionManager, "f").createClientOffer(opts);
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
if (entityType === 'iframe') {
|
|
63
|
-
// @ts-expect-error
|
|
64
|
-
// TODO: type this correctly (frame types are broken)
|
|
65
|
-
connectionUrl = (await this.fin.me.getInfo()).url;
|
|
66
|
-
}
|
|
67
|
-
else if (entityType === 'window' || entityType === 'view') {
|
|
68
|
-
connectionUrl = (await this.fin.me.getInfo()).url;
|
|
69
|
-
}
|
|
70
|
-
const res = await this.wire.sendAction('connect-to-channel', {
|
|
77
|
+
const connectionUrl = (await this.fin.me.getInfo()).url;
|
|
78
|
+
const { payload: { data: routingInfo } } = await this.wire.sendAction('connect-to-channel', {
|
|
71
79
|
channelName,
|
|
72
80
|
...opts,
|
|
73
81
|
offer,
|
|
74
82
|
connectionUrl
|
|
75
83
|
});
|
|
76
|
-
const { payload: { data: routingInfo } } = res;
|
|
77
|
-
// If there isn't a matching channel, the above sendAction call will error out and go to catch, skipping the logic below.
|
|
78
|
-
if (resolver) {
|
|
79
|
-
resolver();
|
|
80
|
-
}
|
|
81
|
-
this.removeListener('connected', listener);
|
|
82
84
|
const strategy = await __classPrivateFieldGet(this, _Channel_connectionManager, "f").createClientStrategy(rtcPacket, routingInfo);
|
|
83
85
|
const channel = new client_1.default(routingInfo, this.wire, strategy);
|
|
84
86
|
// It is the client's responsibility to handle endpoint disconnection to the provider.
|
|
@@ -97,18 +99,13 @@ class Channel extends base_1.EmitterBase {
|
|
|
97
99
|
});
|
|
98
100
|
return channel;
|
|
99
101
|
}
|
|
100
|
-
catch (
|
|
101
|
-
const shouldWait = { wait: true, ...opts }.wait;
|
|
102
|
+
catch (error) {
|
|
102
103
|
const internalNackMessage = 'internal-nack';
|
|
103
|
-
if (
|
|
104
|
-
|
|
105
|
-
return waitResponse;
|
|
106
|
-
}
|
|
107
|
-
if (e.message === internalNackMessage) {
|
|
108
|
-
throw new Error(`No channel found for channelName: ${channelName}`);
|
|
104
|
+
if (error.message.includes(internalNackMessage)) {
|
|
105
|
+
throw new Error(`No channel found for channelName: ${channelName}.`);
|
|
109
106
|
}
|
|
110
107
|
else {
|
|
111
|
-
throw new Error(
|
|
108
|
+
throw new Error(error);
|
|
112
109
|
}
|
|
113
110
|
}
|
|
114
111
|
}
|
|
@@ -129,4 +126,4 @@ class Channel extends base_1.EmitterBase {
|
|
|
129
126
|
}
|
|
130
127
|
}
|
|
131
128
|
exports.Channel = Channel;
|
|
132
|
-
_Channel_connectionManager = new WeakMap();
|
|
129
|
+
_Channel_connectionManager = new WeakMap(), _Channel_internalEmitter = new WeakMap(), _Channel_readyToConnect = new WeakMap();
|