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