@openfin/core 47.100.27 → 47.100.29
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/out/mock-alpha.d.ts +87 -11
- package/out/mock-beta.d.ts +87 -11
- package/out/mock-public.d.ts +87 -11
- package/out/stub.d.ts +109 -18
- package/out/stub.js +275 -118
- package/out/stub.mjs +275 -118
- package/package.json +1 -1
package/out/stub.js
CHANGED
|
@@ -7739,19 +7739,39 @@ let ChannelError$1 = class ChannelError extends Error {
|
|
|
7739
7739
|
}
|
|
7740
7740
|
};
|
|
7741
7741
|
|
|
7742
|
-
|
|
7743
|
-
|
|
7744
|
-
|
|
7745
|
-
|
|
7746
|
-
|
|
7742
|
+
/**
|
|
7743
|
+
* Tracks live channel clients by their current endpoint id and routes runtime lifecycle events to them.
|
|
7744
|
+
*/
|
|
7745
|
+
class ChannelClientStore {
|
|
7746
|
+
// The provider for a channel has gone away: every client on that channel is disconnected.
|
|
7747
|
+
static handleProviderDisconnect(eventPayload) {
|
|
7748
|
+
[...ChannelClientStore.clients.values()].forEach((client) => {
|
|
7749
|
+
if (client.providerIdentity.channelId === eventPayload.channelId) {
|
|
7750
|
+
client[teardown](true, false);
|
|
7751
|
+
}
|
|
7752
|
+
});
|
|
7753
|
+
}
|
|
7754
|
+
// Old providers omit endpoint ids, so a new connection silently replaces the previous client on the channel.
|
|
7755
|
+
static handleEndpointDisconnect(endpointId) {
|
|
7756
|
+
ChannelClientStore.clients.get(endpointId)?.[teardown](false, false);
|
|
7757
|
+
}
|
|
7758
|
+
}
|
|
7759
|
+
ChannelClientStore.clients = new Map();
|
|
7760
|
+
|
|
7747
7761
|
var __classPrivateFieldSet$j = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7748
7762
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
7749
7763
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
7750
7764
|
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");
|
|
7751
7765
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7752
7766
|
};
|
|
7753
|
-
var
|
|
7754
|
-
|
|
7767
|
+
var __classPrivateFieldGet$k = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
7768
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
7769
|
+
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");
|
|
7770
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
7771
|
+
};
|
|
7772
|
+
var _ChannelClient_currentConnection, _ChannelClient_state, _ChannelClient_wire, _ChannelClient_reestablish, _ChannelClient_unsubscribeBFCache, _ChannelClient_disconnectListener, _ChannelClient_reconnectListener, _ChannelClient_releaseConnection, _ChannelClient_attach, _ChannelClient_sendDisconnectToRuntime, _ChannelClient_reconnect;
|
|
7773
|
+
// Key for ChannelClient's internal teardown function. Prevents the need to expose internal functions.
|
|
7774
|
+
const teardown = Symbol('teardown');
|
|
7755
7775
|
/**
|
|
7756
7776
|
* Instance created to enable use of a channel as a client. Allows for communication with the
|
|
7757
7777
|
* {@link ChannelProvider ChannelProvider} by invoking an action on the
|
|
@@ -7780,50 +7800,135 @@ class ChannelClient extends ChannelBase {
|
|
|
7780
7800
|
/**
|
|
7781
7801
|
* @internal
|
|
7782
7802
|
*/
|
|
7783
|
-
|
|
7784
|
-
|
|
7785
|
-
|
|
7786
|
-
|
|
7787
|
-
|
|
7803
|
+
constructor(config) {
|
|
7804
|
+
super();
|
|
7805
|
+
_ChannelClient_currentConnection.set(this, void 0);
|
|
7806
|
+
_ChannelClient_state.set(this, { status: 'connected' });
|
|
7807
|
+
_ChannelClient_wire.set(this, void 0);
|
|
7808
|
+
_ChannelClient_reestablish.set(this, void 0);
|
|
7809
|
+
_ChannelClient_unsubscribeBFCache.set(this, void 0);
|
|
7810
|
+
_ChannelClient_disconnectListener.set(this, void 0);
|
|
7811
|
+
_ChannelClient_reconnectListener.set(this, void 0);
|
|
7812
|
+
// needs to be bound;
|
|
7813
|
+
this.processAction = (action, payload, senderIdentity) => super.processAction(action, payload, senderIdentity);
|
|
7814
|
+
_ChannelClient_releaseConnection.set(this, async (connection, notifyRuntime) => {
|
|
7815
|
+
connection.strategy.close().catch(() => undefined);
|
|
7816
|
+
if (notifyRuntime) {
|
|
7817
|
+
await __classPrivateFieldGet$k(this, _ChannelClient_sendDisconnectToRuntime, "f").call(this, connection);
|
|
7818
|
+
}
|
|
7819
|
+
});
|
|
7820
|
+
_ChannelClient_attach.set(this, (instance) => {
|
|
7821
|
+
ChannelClientStore.clients.set(instance.routingInfo.endpointId, this);
|
|
7822
|
+
instance.strategy.receive(this.processAction);
|
|
7823
|
+
instance.strategy.onEndpointDisconnect(instance.routingInfo.channelId, () => {
|
|
7824
|
+
// Only a drop of the live endpoint disconnects. During a self-heal the endpoint is already being replaced
|
|
7825
|
+
// and the handshake decides the outcome; after it, closing the replaced strategy (RTC/combined fire this on
|
|
7826
|
+
// close) must not tear down the client now live on a fresh endpoint.
|
|
7827
|
+
if (__classPrivateFieldGet$k(this, _ChannelClient_currentConnection, "f") === instance && __classPrivateFieldGet$k(this, _ChannelClient_state, "f").status === 'connected') {
|
|
7828
|
+
this[teardown](true).catch((error) => {
|
|
7829
|
+
// eslint-disable-next-line no-console
|
|
7830
|
+
console.warn(`Failed to notify the runtime that channel '${instance.routingInfo.channelName}' endpoint ${instance.routingInfo.endpointId} disconnected.`, error);
|
|
7831
|
+
});
|
|
7832
|
+
}
|
|
7833
|
+
});
|
|
7834
|
+
});
|
|
7835
|
+
_ChannelClient_sendDisconnectToRuntime.set(this, async ({ routingInfo }) => {
|
|
7836
|
+
const { channelName, uuid, name, endpointId } = routingInfo;
|
|
7837
|
+
await __classPrivateFieldGet$k(this, _ChannelClient_wire, "f").sendAction('disconnect-from-channel', { channelName, uuid, name, endpointId });
|
|
7838
|
+
});
|
|
7839
|
+
// Re-handshakes (new endpointId) and swaps in the fresh endpoint. Client-side registrations and middleware live
|
|
7840
|
+
// on `this` (ChannelBase), so they carry over. Overlapping BF-Cache restores share one in-flight handshake.
|
|
7841
|
+
_ChannelClient_reconnect.set(this, async () => {
|
|
7842
|
+
if (__classPrivateFieldGet$k(this, _ChannelClient_state, "f").status === 'connected') {
|
|
7843
|
+
const performReconnect = async () => {
|
|
7844
|
+
let next;
|
|
7845
|
+
try {
|
|
7846
|
+
next = await __classPrivateFieldGet$k(this, _ChannelClient_reestablish, "f").call(this);
|
|
7847
|
+
}
|
|
7848
|
+
catch (error) {
|
|
7849
|
+
// No automatic retry: recovery is up to the onDisconnection handler.
|
|
7850
|
+
// eslint-disable-next-line no-console
|
|
7851
|
+
console.warn(`Channel '${__classPrivateFieldGet$k(this, _ChannelClient_currentConnection, "f").routingInfo.channelName}' failed to self-heal after BF-Cache restoration; disconnecting.`, error);
|
|
7852
|
+
await this[teardown](true).catch((disconnectError) => {
|
|
7853
|
+
// eslint-disable-next-line no-console
|
|
7854
|
+
console.warn(`Failed to notify the runtime that channel '${__classPrivateFieldGet$k(this, _ChannelClient_currentConnection, "f").routingInfo.channelName}' disconnected.`, disconnectError);
|
|
7855
|
+
});
|
|
7856
|
+
return;
|
|
7857
|
+
}
|
|
7858
|
+
// A disconnect() or provider disconnect may have landed while the handshake was in flight; if so,
|
|
7859
|
+
// tear down the freshly established endpoint instead of resurrecting a closed client.
|
|
7860
|
+
if (__classPrivateFieldGet$k(this, _ChannelClient_state, "f").status !== 'reconnecting') {
|
|
7861
|
+
__classPrivateFieldGet$k(this, _ChannelClient_releaseConnection, "f").call(this, next, true).catch(() => undefined);
|
|
7862
|
+
return;
|
|
7863
|
+
}
|
|
7864
|
+
const previous = __classPrivateFieldGet$k(this, _ChannelClient_currentConnection, "f");
|
|
7865
|
+
__classPrivateFieldSet$j(this, _ChannelClient_currentConnection, next, "f");
|
|
7866
|
+
__classPrivateFieldGet$k(this, _ChannelClient_attach, "f").call(this, next);
|
|
7867
|
+
__classPrivateFieldSet$j(this, _ChannelClient_state, { status: 'connected' }, "f");
|
|
7868
|
+
// A throwing listener must not abort the reconnect.
|
|
7869
|
+
try {
|
|
7870
|
+
__classPrivateFieldGet$k(this, _ChannelClient_reconnectListener, "f")?.call(this, {
|
|
7871
|
+
providerIdentity: this.providerIdentity,
|
|
7872
|
+
previousEndpointId: previous.routingInfo.endpointId,
|
|
7873
|
+
endpointId: next.routingInfo.endpointId
|
|
7874
|
+
});
|
|
7875
|
+
}
|
|
7876
|
+
catch (error) {
|
|
7877
|
+
// eslint-disable-next-line no-console
|
|
7878
|
+
console.warn(`An unexpected error occurred in a Channel Client Reconnection handler for channel ${next.routingInfo.channelName}`, error);
|
|
7879
|
+
}
|
|
7880
|
+
// The old endpoint is typically already gone (navigation); closing is best-effort cleanup.
|
|
7881
|
+
__classPrivateFieldGet$k(this, _ChannelClient_releaseConnection, "f").call(this, previous, false).catch(() => undefined);
|
|
7882
|
+
};
|
|
7883
|
+
// The endpoint is being replaced: against old providers the handshake supersedes it by id, which must
|
|
7884
|
+
// not close the reconnecting client.
|
|
7885
|
+
ChannelClientStore.clients.delete(__classPrivateFieldGet$k(this, _ChannelClient_currentConnection, "f").routingInfo.endpointId);
|
|
7886
|
+
const reconnectPromise = performReconnect();
|
|
7887
|
+
__classPrivateFieldSet$j(this, _ChannelClient_state, { status: 'reconnecting', waitForReconnection: () => reconnectPromise }, "f");
|
|
7888
|
+
}
|
|
7889
|
+
if (__classPrivateFieldGet$k(this, _ChannelClient_state, "f").status === 'reconnecting') {
|
|
7890
|
+
await __classPrivateFieldGet$k(this, _ChannelClient_state, "f").waitForReconnection();
|
|
7891
|
+
}
|
|
7892
|
+
});
|
|
7893
|
+
__classPrivateFieldSet$j(this, _ChannelClient_currentConnection, config.initialConnection, "f");
|
|
7894
|
+
__classPrivateFieldSet$j(this, _ChannelClient_wire, config.wire, "f");
|
|
7895
|
+
__classPrivateFieldSet$j(this, _ChannelClient_reestablish, config.reestablish, "f");
|
|
7896
|
+
__classPrivateFieldSet$j(this, _ChannelClient_unsubscribeBFCache, __classPrivateFieldGet$k(this, _ChannelClient_wire, "f").environment.onBFCacheRestore(__classPrivateFieldGet$k(this, _ChannelClient_reconnect, "f")), "f");
|
|
7897
|
+
__classPrivateFieldGet$k(this, _ChannelClient_attach, "f").call(this, config.initialConnection);
|
|
7788
7898
|
}
|
|
7789
7899
|
/**
|
|
7790
7900
|
* @internal
|
|
7791
|
-
*
|
|
7792
|
-
|
|
7793
|
-
|
|
7794
|
-
|
|
7795
|
-
|
|
7796
|
-
|
|
7797
|
-
|
|
7901
|
+
* Closes the client. `notifyRuntime` sends `disconnect-from-channel` for the current endpoint; `emitEvent` then
|
|
7902
|
+
* fires the onDisconnection listener, even if notifying the runtime failed.
|
|
7903
|
+
*/
|
|
7904
|
+
async [(_ChannelClient_currentConnection = new WeakMap(), _ChannelClient_state = new WeakMap(), _ChannelClient_wire = new WeakMap(), _ChannelClient_reestablish = new WeakMap(), _ChannelClient_unsubscribeBFCache = new WeakMap(), _ChannelClient_disconnectListener = new WeakMap(), _ChannelClient_reconnectListener = new WeakMap(), _ChannelClient_releaseConnection = new WeakMap(), _ChannelClient_attach = new WeakMap(), _ChannelClient_sendDisconnectToRuntime = new WeakMap(), _ChannelClient_reconnect = new WeakMap(), teardown)](emitEvent = false, notifyRuntime = true) {
|
|
7905
|
+
if (__classPrivateFieldGet$k(this, _ChannelClient_state, "f").status !== 'closed') {
|
|
7906
|
+
const identity = this.providerIdentity;
|
|
7907
|
+
const connection = __classPrivateFieldGet$k(this, _ChannelClient_currentConnection, "f");
|
|
7908
|
+
__classPrivateFieldSet$j(this, _ChannelClient_state, { status: 'closed' }, "f");
|
|
7909
|
+
__classPrivateFieldGet$k(this, _ChannelClient_unsubscribeBFCache, "f").call(this);
|
|
7910
|
+
ChannelClientStore.clients.delete(connection.routingInfo.endpointId);
|
|
7911
|
+
try {
|
|
7912
|
+
await __classPrivateFieldGet$k(this, _ChannelClient_releaseConnection, "f").call(this, connection, notifyRuntime);
|
|
7913
|
+
}
|
|
7914
|
+
finally {
|
|
7915
|
+
if (emitEvent) {
|
|
7916
|
+
try {
|
|
7917
|
+
__classPrivateFieldGet$k(this, _ChannelClient_disconnectListener, "f")?.call(this, identity);
|
|
7918
|
+
}
|
|
7919
|
+
catch (error) {
|
|
7920
|
+
// eslint-disable-next-line no-console
|
|
7921
|
+
console.warn(`An unexpected error occurred in a Channel Client Disconnection handler for channel ${identity.channelName}`, error);
|
|
7922
|
+
}
|
|
7923
|
+
}
|
|
7798
7924
|
}
|
|
7799
7925
|
}
|
|
7800
7926
|
}
|
|
7801
|
-
/**
|
|
7802
|
-
* @internal
|
|
7803
|
-
*/
|
|
7804
|
-
constructor(routingInfo, close, strategy) {
|
|
7805
|
-
super();
|
|
7806
|
-
_ChannelClient_protectedObj.set(this, void 0);
|
|
7807
|
-
_ChannelClient_strategy.set(this, void 0);
|
|
7808
|
-
// needs to be bound;
|
|
7809
|
-
this.processAction = (action, payload, senderIdentity) => super.processAction(action, payload, senderIdentity);
|
|
7810
|
-
_ChannelClient_close.set(this, () => {
|
|
7811
|
-
channelClientsByEndpointId.delete(this.endpointId);
|
|
7812
|
-
__classPrivateFieldGet$k(this, _ChannelClient_strategy, "f").close();
|
|
7813
|
-
});
|
|
7814
|
-
__classPrivateFieldSet$j(this, _ChannelClient_protectedObj, new ProtectedItems(routingInfo, close), "f");
|
|
7815
|
-
this.disconnectListener = () => undefined;
|
|
7816
|
-
this.endpointId = routingInfo.endpointId;
|
|
7817
|
-
__classPrivateFieldSet$j(this, _ChannelClient_strategy, strategy, "f");
|
|
7818
|
-
channelClientsByEndpointId.set(this.endpointId, this);
|
|
7819
|
-
strategy.receive(this.processAction);
|
|
7820
|
-
}
|
|
7821
7927
|
/**
|
|
7822
7928
|
* a read-only provider identity
|
|
7823
7929
|
*/
|
|
7824
7930
|
get providerIdentity() {
|
|
7825
|
-
|
|
7826
|
-
return protectedObj.providerIdentity;
|
|
7931
|
+
return { ...__classPrivateFieldGet$k(this, _ChannelClient_currentConnection, "f").routingInfo };
|
|
7827
7932
|
}
|
|
7828
7933
|
/**
|
|
7829
7934
|
* Dispatch the given action to the channel provider. Returns a promise that resolves with the response from
|
|
@@ -7851,17 +7956,22 @@ class ChannelClient extends ChannelBase {
|
|
|
7851
7956
|
* ```
|
|
7852
7957
|
*/
|
|
7853
7958
|
async dispatch(action, payload) {
|
|
7854
|
-
|
|
7855
|
-
|
|
7856
|
-
|
|
7857
|
-
throw new ChannelError$1(e, action, payload, callSites);
|
|
7858
|
-
});
|
|
7959
|
+
// App pageshow handlers run alongside the bfcache restore; sending now would go out on the frozen endpoint.
|
|
7960
|
+
if (__classPrivateFieldGet$k(this, _ChannelClient_state, "f").status === 'reconnecting') {
|
|
7961
|
+
await __classPrivateFieldGet$k(this, _ChannelClient_state, "f").waitForReconnection();
|
|
7859
7962
|
}
|
|
7860
|
-
|
|
7963
|
+
const connection = __classPrivateFieldGet$k(this, _ChannelClient_currentConnection, "f");
|
|
7964
|
+
if (!connection.strategy.isEndpointConnected(this.providerIdentity.channelId)) {
|
|
7965
|
+
throw new Error('The client you are trying to dispatch from is disconnected from the target provider.');
|
|
7966
|
+
}
|
|
7967
|
+
const callSites = RuntimeError.getCallSite();
|
|
7968
|
+
return connection.strategy.send(this.providerIdentity.channelId, action, payload).catch((e) => {
|
|
7969
|
+
throw new ChannelError$1(e, action, payload, callSites);
|
|
7970
|
+
});
|
|
7861
7971
|
}
|
|
7862
7972
|
/**
|
|
7863
|
-
* Register a listener that is called
|
|
7864
|
-
*
|
|
7973
|
+
* Register a listener that is called when this client loses its channel: the provider disconnects, the
|
|
7974
|
+
* endpoint drops, or a self-heal fails. It is passed the provider identity.
|
|
7865
7975
|
*
|
|
7866
7976
|
* @param listener
|
|
7867
7977
|
*
|
|
@@ -7878,17 +7988,46 @@ class ChannelClient extends ChannelBase {
|
|
|
7878
7988
|
* ```
|
|
7879
7989
|
*/
|
|
7880
7990
|
onDisconnection(listener) {
|
|
7881
|
-
this
|
|
7882
|
-
|
|
7883
|
-
|
|
7884
|
-
|
|
7885
|
-
|
|
7886
|
-
|
|
7887
|
-
|
|
7888
|
-
|
|
7889
|
-
|
|
7890
|
-
|
|
7891
|
-
|
|
7991
|
+
__classPrivateFieldSet$j(this, _ChannelClient_disconnectListener, listener, "f");
|
|
7992
|
+
}
|
|
7993
|
+
/**
|
|
7994
|
+
* Register a listener that is called each time this client transparently self-heals its connection to the
|
|
7995
|
+
* provider.
|
|
7996
|
+
*
|
|
7997
|
+
* @remarks
|
|
7998
|
+
* A channel client's underlying endpoint is torn down while its document sits in the back/forward cache
|
|
7999
|
+
* (bfcache). If the back/forward cache is supported and the document is restored from it, the client
|
|
8000
|
+
* automatically re-handshakes with the provider and swaps in a fresh endpoint; all of this client's
|
|
8001
|
+
* `register`/middleware handlers are preserved, so no re-registration is required.
|
|
8002
|
+
*
|
|
8003
|
+
* A restore is not guaranteed: Chromium may evict a cached document at any time, in which case navigating
|
|
8004
|
+
* back reloads the page and a new client must connect.
|
|
8005
|
+
*
|
|
8006
|
+
* This listener fires once per successful reconnect, after the new endpoint is live, and can fire multiple
|
|
8007
|
+
* times over the client's lifetime. It is triggered when the document is restored from the back/forward
|
|
8008
|
+
* cache (a bfcache `pageshow`). It does not fire for the initial connection, nor after
|
|
8009
|
+
* {@link ChannelClient#disconnect disconnect}. {@link ChannelClient#onDisconnection onDisconnection} fires
|
|
8010
|
+
* when the provider or endpoint goes away.
|
|
8011
|
+
*
|
|
8012
|
+
* The info provides the reconnected {@link OpenFin.ProviderIdentity provider identity} along with
|
|
8013
|
+
* the previous and new endpoint ids.
|
|
8014
|
+
*
|
|
8015
|
+
* @param listener
|
|
8016
|
+
*
|
|
8017
|
+
* @example
|
|
8018
|
+
*
|
|
8019
|
+
* ```js
|
|
8020
|
+
* (async () => {
|
|
8021
|
+
* const client = await fin.InterApplicationBus.Channel.connect('channelName');
|
|
8022
|
+
*
|
|
8023
|
+
* client.onReconnection(({ providerIdentity, previousEndpointId, endpointId }) => {
|
|
8024
|
+
* console.log(`Reconnected to ${providerIdentity.channelName}: ${previousEndpointId} -> ${endpointId}`);
|
|
8025
|
+
* });
|
|
8026
|
+
* })();
|
|
8027
|
+
* ```
|
|
8028
|
+
*/
|
|
8029
|
+
onReconnection(listener) {
|
|
8030
|
+
__classPrivateFieldSet$j(this, _ChannelClient_reconnectListener, listener, "f");
|
|
7892
8031
|
}
|
|
7893
8032
|
/**
|
|
7894
8033
|
* Disconnects the client from the channel.
|
|
@@ -7904,28 +8043,16 @@ class ChannelClient extends ChannelBase {
|
|
|
7904
8043
|
* ```
|
|
7905
8044
|
*/
|
|
7906
8045
|
async disconnect() {
|
|
7907
|
-
await this
|
|
7908
|
-
__classPrivateFieldGet$k(this, _ChannelClient_close, "f").call(this);
|
|
7909
|
-
}
|
|
7910
|
-
async sendDisconnectAction() {
|
|
7911
|
-
const protectedObj = __classPrivateFieldGet$k(this, _ChannelClient_protectedObj, "f");
|
|
7912
|
-
await protectedObj.close();
|
|
8046
|
+
await this[teardown](false);
|
|
7913
8047
|
}
|
|
7914
8048
|
/**
|
|
7915
8049
|
* @internal
|
|
7916
|
-
*
|
|
8050
|
+
* Notify the runtime that the current endpoint has disconnected.
|
|
7917
8051
|
*/
|
|
7918
|
-
|
|
7919
|
-
|
|
7920
|
-
await wire.sendAction('disconnect-from-channel', {
|
|
7921
|
-
channelName,
|
|
7922
|
-
uuid,
|
|
7923
|
-
name,
|
|
7924
|
-
endpointId
|
|
7925
|
-
});
|
|
8052
|
+
async sendDisconnectAction() {
|
|
8053
|
+
await this.disconnect();
|
|
7926
8054
|
}
|
|
7927
8055
|
}
|
|
7928
|
-
_ChannelClient_protectedObj = new WeakMap(), _ChannelClient_strategy = new WeakMap(), _ChannelClient_close = new WeakMap();
|
|
7929
8056
|
|
|
7930
8057
|
function exhaustiveCheck(value, allowed) {
|
|
7931
8058
|
throw new Error(`Unsupported value: ${value}${allowed ? `\n Supported values are: ${allowed.join('')}` : ''}`);
|
|
@@ -8849,7 +8976,7 @@ class MessageReceiver extends Base {
|
|
|
8849
8976
|
const endpointIdFromPreviousConnection = this.latestEndpointIdByChannelId.get(channelId);
|
|
8850
8977
|
if (endpointIdFromPreviousConnection) {
|
|
8851
8978
|
// Not convinced by this way of doing things, but pushing up for now.
|
|
8852
|
-
|
|
8979
|
+
ChannelClientStore.handleEndpointDisconnect(endpointIdFromPreviousConnection);
|
|
8853
8980
|
// eslint-disable-next-line no-console
|
|
8854
8981
|
console.warn('You have created a second connection to an older provider. First connection has been removed from the clientMap');
|
|
8855
8982
|
// eslint-disable-next-line no-console
|
|
@@ -9224,7 +9351,7 @@ var __classPrivateFieldGet$e = (undefined && undefined.__classPrivateFieldGet) |
|
|
|
9224
9351
|
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");
|
|
9225
9352
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
9226
9353
|
};
|
|
9227
|
-
var _Channel_connectionManager, _Channel_internalEmitter, _Channel_readyForProvider, _Channel_readyToConnect;
|
|
9354
|
+
var _Channel_connectionManager, _Channel_internalEmitter, _Channel_readyForProvider, _Channel_readyToConnect, _Channel_establishConnection;
|
|
9228
9355
|
function retryDelay(count) {
|
|
9229
9356
|
const interval = 500; // base delay
|
|
9230
9357
|
const steps = 10; // How many retries to do before incrementing the delay
|
|
@@ -9274,13 +9401,33 @@ class Channel extends EmitterBase {
|
|
|
9274
9401
|
await Promise.all([
|
|
9275
9402
|
__classPrivateFieldGet$e(this, _Channel_readyForProvider, "f").getValue(),
|
|
9276
9403
|
this.on('disconnected', (eventPayload) => {
|
|
9277
|
-
|
|
9404
|
+
ChannelClientStore.handleProviderDisconnect(eventPayload);
|
|
9278
9405
|
}),
|
|
9279
9406
|
this.on('connected', (...args) => {
|
|
9280
9407
|
__classPrivateFieldGet$e(this, _Channel_internalEmitter, "f").emit('connected', ...args);
|
|
9281
9408
|
})
|
|
9282
9409
|
]).catch(() => new Error('error setting up channel connection listeners'));
|
|
9283
9410
|
}));
|
|
9411
|
+
// Runs the client handshake (offer -> connect -> strategy). Re-runnable so a ChannelClient can reconnect
|
|
9412
|
+
// with a fresh endpointId; offers are single-use (esp. RTC) so a new offer is created each call.
|
|
9413
|
+
_Channel_establishConnection.set(this, async (channelName, opts, connectionUrl) => {
|
|
9414
|
+
const { offer, rtc: rtcPacket } = await __classPrivateFieldGet$e(this, _Channel_connectionManager, "f").createClientOffer(opts);
|
|
9415
|
+
// getInfo() can hang during a bfcache restore, so reconnects reuse the URL resolved on the first connect;
|
|
9416
|
+
// it cannot change within a client's lifetime.
|
|
9417
|
+
let targetUrl = connectionUrl;
|
|
9418
|
+
if (targetUrl === undefined && (this.fin.me.isFrame || this.fin.me.isView || this.fin.me.isWindow)) {
|
|
9419
|
+
targetUrl = (await this.fin.me.getInfo()).url;
|
|
9420
|
+
}
|
|
9421
|
+
const connectPayload = {
|
|
9422
|
+
channelName,
|
|
9423
|
+
...opts,
|
|
9424
|
+
offer,
|
|
9425
|
+
connectionUrl: targetUrl
|
|
9426
|
+
};
|
|
9427
|
+
const routingInfo = await this.safeConnect(channelName, opts.wait, connectPayload);
|
|
9428
|
+
const strategy = await __classPrivateFieldGet$e(this, _Channel_connectionManager, "f").createClientStrategy(rtcPacket, routingInfo);
|
|
9429
|
+
return { routingInfo, strategy, connectionUrl: targetUrl };
|
|
9430
|
+
});
|
|
9284
9431
|
__classPrivateFieldSet$d(this, _Channel_connectionManager, new ConnectionManager(wire), "f");
|
|
9285
9432
|
}
|
|
9286
9433
|
/**
|
|
@@ -9452,35 +9599,14 @@ class Channel extends EmitterBase {
|
|
|
9452
9599
|
throw new Error('Please provide a channelName string to connect to a channel.');
|
|
9453
9600
|
}
|
|
9454
9601
|
const opts = { wait: true, ...this.wire.environment.getDefaultChannelOptions().connect, ...options };
|
|
9455
|
-
const
|
|
9456
|
-
|
|
9457
|
-
|
|
9458
|
-
|
|
9459
|
-
|
|
9460
|
-
|
|
9461
|
-
channelName,
|
|
9462
|
-
...opts,
|
|
9463
|
-
offer,
|
|
9464
|
-
connectionUrl
|
|
9465
|
-
};
|
|
9466
|
-
const routingInfo = await this.safeConnect(channelName, opts.wait, connectPayload);
|
|
9467
|
-
const strategy = await __classPrivateFieldGet$e(this, _Channel_connectionManager, "f").createClientStrategy(rtcPacket, routingInfo);
|
|
9468
|
-
const channel = new ChannelClient(routingInfo, () => ChannelClient.wireClose(this.wire, routingInfo, routingInfo.endpointId), strategy);
|
|
9469
|
-
// It is the client's responsibility to handle endpoint disconnection to the provider.
|
|
9470
|
-
// If the endpoint dies, the client will force a disconnection through the core.
|
|
9471
|
-
// The provider does not care about endpoint disconnection.
|
|
9472
|
-
strategy.onEndpointDisconnect(routingInfo.channelId, async () => {
|
|
9473
|
-
try {
|
|
9474
|
-
await channel.sendDisconnectAction();
|
|
9475
|
-
}
|
|
9476
|
-
catch (error) {
|
|
9477
|
-
console.warn(`Something went wrong during disconnect for client with uuid: ${routingInfo.uuid} / name: ${routingInfo.name} / endpointId: ${routingInfo.endpointId}.`);
|
|
9478
|
-
}
|
|
9479
|
-
finally {
|
|
9480
|
-
ChannelClient.handleProviderDisconnect(routingInfo);
|
|
9481
|
-
}
|
|
9602
|
+
const initialConnection = await __classPrivateFieldGet$e(this, _Channel_establishConnection, "f").call(this, channelName, opts);
|
|
9603
|
+
// Never wait on a self-heal: a provider missing at restore has gone away, which is a disconnection. A provider
|
|
9604
|
+
// created later under the same name is a new instance without this client's provider-side state.
|
|
9605
|
+
return new ChannelClient({
|
|
9606
|
+
initialConnection,
|
|
9607
|
+
wire: this.wire,
|
|
9608
|
+
reestablish: () => __classPrivateFieldGet$e(this, _Channel_establishConnection, "f").call(this, channelName, { ...opts, wait: false }, initialConnection.connectionUrl)
|
|
9482
9609
|
});
|
|
9483
|
-
return channel;
|
|
9484
9610
|
}
|
|
9485
9611
|
/**
|
|
9486
9612
|
* Create a new channel.
|
|
@@ -9537,7 +9663,7 @@ class Channel extends EmitterBase {
|
|
|
9537
9663
|
return __classPrivateFieldGet$e(this, _Channel_connectionManager, "f").createProvider(options, providerIdentity);
|
|
9538
9664
|
}
|
|
9539
9665
|
}
|
|
9540
|
-
_Channel_connectionManager = new WeakMap(), _Channel_internalEmitter = new WeakMap(), _Channel_readyForProvider = new WeakMap(), _Channel_readyToConnect = new WeakMap();
|
|
9666
|
+
_Channel_connectionManager = new WeakMap(), _Channel_internalEmitter = new WeakMap(), _Channel_readyForProvider = new WeakMap(), _Channel_readyToConnect = new WeakMap(), _Channel_establishConnection = new WeakMap();
|
|
9541
9667
|
|
|
9542
9668
|
/**
|
|
9543
9669
|
* Entry point for the OpenFin `InterApplicationBus` API (`fin.InterApplicationBus`).
|
|
@@ -9571,11 +9697,27 @@ class InterApplicationBus extends Base {
|
|
|
9571
9697
|
subscriberRemoved: 'subscriber-removed'
|
|
9572
9698
|
};
|
|
9573
9699
|
this.refCounter = new RefCounter();
|
|
9700
|
+
/**
|
|
9701
|
+
* One entry per subscription the runtime knows about, keyed by the same subscription key the
|
|
9702
|
+
* emitter and the ref counter use. Listeners sharing a key share a single entry.
|
|
9703
|
+
*/
|
|
9704
|
+
this.activeSubscriptions = new Map();
|
|
9574
9705
|
this.Channel = new Channel(wire);
|
|
9575
9706
|
this.emitter = new events.EventEmitter();
|
|
9576
9707
|
wire.registerMessageHandler(this.onmessage.bind(this));
|
|
9577
9708
|
this.on = this.emitter.on.bind(this.emitter);
|
|
9578
9709
|
this.removeAllListeners = this.emitter.removeAllListeners.bind(this.emitter);
|
|
9710
|
+
wire.environment.onBFCacheRestore(() => {
|
|
9711
|
+
Array.from(this.activeSubscriptions.values()).forEach(async (subscription) => {
|
|
9712
|
+
try {
|
|
9713
|
+
await this.wire.sendAction('subscribe', subscription);
|
|
9714
|
+
}
|
|
9715
|
+
catch (error) {
|
|
9716
|
+
// eslint-disable-next-line no-console
|
|
9717
|
+
console.error('Failed to restore InterApplicationBus subscription after bfcache restore', error);
|
|
9718
|
+
}
|
|
9719
|
+
});
|
|
9720
|
+
});
|
|
9579
9721
|
}
|
|
9580
9722
|
/**
|
|
9581
9723
|
* Publishes a message to all applications running on OpenFin Runtime that
|
|
@@ -9627,30 +9769,39 @@ class InterApplicationBus extends Base {
|
|
|
9627
9769
|
* Subscribes to messages from the specified application on the specified topic.
|
|
9628
9770
|
* @param source This object is described in the Identity in the typedef
|
|
9629
9771
|
* @param topic The topic on which the message is sent
|
|
9630
|
-
* @param listener A function that is called when a message has
|
|
9631
|
-
*
|
|
9772
|
+
* @param listener A function that is called when a message has been received. It is passed
|
|
9773
|
+
* two arguments: the message, and the identity (`{ uuid, name }`) of the sender.
|
|
9632
9774
|
* The message can be either a primitive data type (string, number, or boolean) or
|
|
9633
9775
|
* composite data type (object, array) that is composed of other primitive or composite
|
|
9634
9776
|
* data types
|
|
9635
9777
|
*
|
|
9778
|
+
* @remarks This differs from the legacy `fin.desktop.InterApplicationBus.subscribe` API,
|
|
9779
|
+
* which passes `(message, uuid, name)` as separate arguments.
|
|
9780
|
+
*
|
|
9636
9781
|
* @example
|
|
9637
9782
|
* ```js
|
|
9638
9783
|
* // subscribe to a specified application
|
|
9639
|
-
* fin.InterApplicationBus.subscribe(fin.me, 'topic',
|
|
9784
|
+
* fin.InterApplicationBus.subscribe(fin.me, 'topic', (message, sender) => {
|
|
9785
|
+
* console.log(`Received from ${sender.uuid}/${sender.name}:`, message);
|
|
9786
|
+
* }).then(() => console.log('Subscribed to the specified application')).catch(err => console.log(err));
|
|
9640
9787
|
*
|
|
9641
9788
|
* // subscribe to wildcard
|
|
9642
9789
|
* fin.InterApplicationBus.subscribe({ uuid: '*' }, 'topic', sub_msg => console.log(sub_msg)).then(() => console.log('Subscribed to *')).catch(err => console.log(err));
|
|
9643
9790
|
* ```
|
|
9644
9791
|
*/
|
|
9645
9792
|
subscribe(source, topic, listener) {
|
|
9646
|
-
const
|
|
9793
|
+
const sourceWindowName = source.name || '*';
|
|
9794
|
+
const subKey = this.createSubscriptionKey(source.uuid, sourceWindowName, topic);
|
|
9795
|
+
const subscription = {
|
|
9796
|
+
sourceUuid: source.uuid,
|
|
9797
|
+
sourceWindowName,
|
|
9798
|
+
topic,
|
|
9799
|
+
destinationWindowName: this.me.name
|
|
9800
|
+
};
|
|
9647
9801
|
const sendSubscription = async () => {
|
|
9648
|
-
await
|
|
9649
|
-
|
|
9650
|
-
|
|
9651
|
-
topic,
|
|
9652
|
-
destinationWindowName: this.me.name
|
|
9653
|
-
});
|
|
9802
|
+
// Journaled before the await so a concurrent unsubscribe can find it.
|
|
9803
|
+
this.activeSubscriptions.set(subKey, subscription);
|
|
9804
|
+
await this.wire.sendAction('subscribe', subscription);
|
|
9654
9805
|
};
|
|
9655
9806
|
const alreadySubscribed = () => {
|
|
9656
9807
|
return Promise.resolve();
|
|
@@ -9686,6 +9837,9 @@ class InterApplicationBus extends Base {
|
|
|
9686
9837
|
const sourceWindowName = source.name || '*';
|
|
9687
9838
|
const subKey = this.createSubscriptionKey(source.uuid, sourceWindowName, topic);
|
|
9688
9839
|
const sendUnsubscription = async () => {
|
|
9840
|
+
// Dropped before the await so that a restoration landing while this unsubscribe is
|
|
9841
|
+
// still in flight does not replay the subscription being torn down.
|
|
9842
|
+
this.activeSubscriptions.delete(subKey);
|
|
9689
9843
|
await this.wire.sendAction('unsubscribe', {
|
|
9690
9844
|
sourceUuid: source.uuid,
|
|
9691
9845
|
sourceWindowName,
|
|
@@ -9694,6 +9848,9 @@ class InterApplicationBus extends Base {
|
|
|
9694
9848
|
});
|
|
9695
9849
|
};
|
|
9696
9850
|
const dontSendUnsubscription = () => {
|
|
9851
|
+
// TODO(CORE-2749): never settles - the executor evaluates `r` instead of calling it,
|
|
9852
|
+
// so awaiting a non-final unsubscribe hangs the caller. Should be `Promise.resolve()`,
|
|
9853
|
+
// but that changes long-standing behavior, so it is tracked separately from CORE-2740.
|
|
9697
9854
|
return new Promise((r) => r).then(() => undefined);
|
|
9698
9855
|
};
|
|
9699
9856
|
this.emitter.removeListener(subKey, listener);
|