@openfin/core 31.74.31 → 32.75.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.
Files changed (82) hide show
  1. package/package.json +1 -1
  2. package/src/OpenFin.d.ts +58 -13
  3. package/src/api/application/Instance.d.ts +13 -1
  4. package/src/api/application/Instance.js +39 -7
  5. package/src/api/base.d.ts +1 -2
  6. package/src/api/base.js +1 -2
  7. package/src/api/events/application.d.ts +4 -1
  8. package/src/api/events/system.d.ts +6 -3
  9. package/src/api/events/webcontents.d.ts +54 -5
  10. package/src/api/fin.js +1 -2
  11. package/src/api/interappbus/channel/client.d.ts +2 -2
  12. package/src/api/interappbus/channel/index.d.ts +4 -3
  13. package/src/api/interappbus/channel/index.js +111 -74
  14. package/src/api/interappbus/channel/protocols/classic/strategy.js +24 -6
  15. package/src/api/interappbus/index.js +1 -1
  16. package/src/api/interop/InteropClient.d.ts +1 -1
  17. package/src/api/interop/InteropClient.js +1 -1
  18. package/src/api/interop/SessionContextGroupBroker.d.ts +1 -1
  19. package/src/api/interop/SessionContextGroupBroker.js +5 -4
  20. package/src/api/interop/SessionContextGroupClient.js +1 -1
  21. package/src/api/interop/fdc3/PrivateChannelProvider.d.ts +1 -1
  22. package/src/api/interop/fdc3/PrivateChannelProvider.js +1 -8
  23. package/src/api/interop/fdc3/fdc3-1.2.js +34 -1
  24. package/src/api/interop/fdc3/utils.js +24 -4
  25. package/src/api/me.d.ts +1 -1
  26. package/src/api/me.js +2 -1
  27. package/src/api/platform/Factory.d.ts +3 -3
  28. package/src/api/platform/Factory.js +2 -11
  29. package/src/api/platform/Instance.d.ts +5 -4
  30. package/src/api/platform/Instance.js +2 -1
  31. package/src/api/platform/layout/Factory.d.ts +1 -1
  32. package/src/api/platform/layout/Factory.js +7 -39
  33. package/src/api/platform/layout/Instance.js +3 -0
  34. package/src/api/platform/layout/controllers/layout-entities-controller.d.ts +6 -2
  35. package/src/api/platform/layout/controllers/layout-entities-controller.js +40 -8
  36. package/src/api/platform/layout/entities/layout-entities.d.ts +143 -42
  37. package/src/api/platform/layout/entities/layout-entities.js +151 -43
  38. package/src/api/platform/layout/utils/layout-traversal.d.ts +1 -0
  39. package/src/api/platform/layout/utils/layout-traversal.js +11 -11
  40. package/src/api/platform/provider.d.ts +2 -1
  41. package/src/api/system/index.d.ts +9 -0
  42. package/src/api/system/index.js +78 -40
  43. package/src/api/view/Instance.d.ts +6 -3
  44. package/src/api/view/Instance.js +10 -9
  45. package/src/api/webcontents/main.d.ts +2 -22
  46. package/src/api/webcontents/main.js +2 -1
  47. package/src/api/window/Instance.d.ts +10 -0
  48. package/src/api/window/Instance.js +22 -0
  49. package/src/environment/browser.d.ts +4 -2
  50. package/src/environment/browser.js +5 -2
  51. package/src/environment/environment.d.ts +4 -2
  52. package/src/environment/mockEnvironment.d.ts +27 -0
  53. package/src/environment/mockEnvironment.js +61 -0
  54. package/src/environment/node-env.d.ts +3 -2
  55. package/src/environment/node-env.js +5 -2
  56. package/src/environment/openfin-env.d.ts +5 -3
  57. package/src/environment/openfin-env.js +12 -10
  58. package/src/mock.js +4 -83
  59. package/src/shapes/protocol.d.ts +26 -9
  60. package/src/transport/mockWire.d.ts +11 -0
  61. package/src/transport/mockWire.js +26 -0
  62. package/src/transport/transport-errors.d.ts +9 -1
  63. package/src/transport/transport-errors.js +45 -2
  64. package/src/transport/transport.d.ts +16 -5
  65. package/src/transport/transport.js +48 -20
  66. package/src/util/channel-api-relay.js +11 -1
  67. package/src/util/errors.d.ts +1 -0
  68. package/src/util/errors.js +1 -0
  69. package/src/util/lazy.d.ts +18 -0
  70. package/src/util/lazy.js +29 -1
  71. package/src/util/ref-counter.d.ts +1 -1
  72. package/src/util/ref-counter.js +3 -2
  73. package/src/api/platform/layout/controllers/splitter-controller.d.ts +0 -30
  74. package/src/api/platform/layout/controllers/splitter-controller.js +0 -83
  75. package/src/api/platform/layout/controllers/tab-drag-controller.d.ts +0 -58
  76. package/src/api/platform/layout/controllers/tab-drag-controller.js +0 -124
  77. package/src/api/platform/layout/utils/bounds-observer.d.ts +0 -19
  78. package/src/api/platform/layout/utils/bounds-observer.js +0 -52
  79. package/src/api/platform/layout/utils/view-overlay.d.ts +0 -35
  80. package/src/api/platform/layout/utils/view-overlay.js +0 -49
  81. package/src/transport/fin_store.d.ts +0 -4
  82. package/src/transport/fin_store.js +0 -16
@@ -10,24 +10,46 @@ 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 */
17
- const client_1 = require("./client");
18
- const provider_1 = require("./provider");
17
+ const events_1 = require("events");
18
+ const lazy_1 = require("../../../util/lazy");
19
19
  const base_1 = require("../../base");
20
+ const client_1 = require("./client");
20
21
  const connection_manager_1 = require("./connection-manager");
21
- // eslint-disable-next-line @typescript-eslint/no-empty-function
22
- const noop = () => { };
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
+ }
23
36
  class Channel extends base_1.EmitterBase {
24
37
  constructor(wire) {
25
38
  super(wire, 'channel');
26
39
  _Channel_connectionManager.set(this, void 0);
40
+ _Channel_internalEmitter.set(this, new events_1.EventEmitter());
41
+ // OpenFin API has not been injected at construction time, *must* wait for API to be ready.
42
+ _Channel_readyToConnect.set(this, new lazy_1.AsyncRetryableLazy(async () => {
43
+ await Promise.all([
44
+ this.on('disconnected', (eventPayload) => {
45
+ client_1.default.handleProviderDisconnect(eventPayload);
46
+ }),
47
+ this.on('connected', (...args) => {
48
+ __classPrivateFieldGet(this, _Channel_internalEmitter, "f").emit('connected', ...args);
49
+ })
50
+ ]).catch(() => new Error('error setting up channel connection listeners'));
51
+ }));
27
52
  __classPrivateFieldSet(this, _Channel_connectionManager, new connection_manager_1.ConnectionManager(wire), "f");
28
- this.on('disconnected', (eventPayload) => {
29
- client_1.default.handleProviderDisconnect(eventPayload);
30
- }).catch((e) => console.error('Error setting up a disconnected listener:', e));
31
53
  }
32
54
  async getAllChannels() {
33
55
  return this.wire.sendAction('get-all-channels').then(({ payload }) => payload.data);
@@ -38,79 +60,94 @@ class Channel extends base_1.EmitterBase {
38
60
  async onChannelDisconnect(listener) {
39
61
  await this.on('disconnected', listener);
40
62
  }
41
- async connect(channelName, options) {
42
- if (!channelName || typeof channelName !== 'string') {
43
- throw new Error('Please provide a channelName string to connect to a channel.');
44
- }
45
- const opts = Object.assign(this.wire.environment.getDefaultChannelOptions().connect, options || {});
46
- let resolver = noop;
47
- let listener = noop;
48
- const waitResponse = new Promise((resolve) => {
49
- resolver = resolve;
50
- listener = (payload) => {
51
- if (channelName === payload.channelName) {
52
- this.removeListener('connected', listener);
53
- resolve(this.connect(channelName, opts));
54
- }
55
- };
56
- this.on('connected', listener);
57
- });
58
- try {
59
- const { offer, rtc: rtcPacket } = await __classPrivateFieldGet(this, _Channel_connectionManager, "f").createClientOffer(opts);
60
- let connectionUrl;
61
- const entityType = this.wire.environment.getCurrentEntityType();
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', {
71
- channelName,
72
- ...opts,
73
- offer,
74
- connectionUrl
63
+ async safeConnect(channelName, shouldWait, connectPayload) {
64
+ const retryInfo = { count: 0 };
65
+ /* eslint-disable no-await-in-loop, no-constant-condition */
66
+ do {
67
+ // setup a listener and a connected promise to await in case we connect before the channel is ready
68
+ let connectedListener = () => undefined;
69
+ const connectedPromise = new Promise((resolve) => {
70
+ connectedListener = (payload) => {
71
+ if (channelName === payload.channelName) {
72
+ resolve(true);
73
+ }
74
+ };
75
+ __classPrivateFieldGet(this, _Channel_internalEmitter, "f").on('connected', connectedListener);
75
76
  });
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
- const strategy = await __classPrivateFieldGet(this, _Channel_connectionManager, "f").createClientStrategy(rtcPacket, routingInfo);
83
- const channel = new client_1.default(routingInfo, this.wire, strategy);
84
- // It is the client's responsibility to handle endpoint disconnection to the provider.
85
- // If the endpoint dies, the client will force a disconnection through the core.
86
- // The provider does not care about endpoint disconnection.
87
- strategy.onEndpointDisconnect(routingInfo.channelId, async () => {
88
- try {
89
- await channel.sendDisconnectAction();
77
+ try {
78
+ if (retryInfo.count > 0) {
79
+ // Wait before retrying
80
+ // Delay returns false connectedPromise returns true so we can know if a retry is due to connected event
81
+ retryInfo.gotConnectedEvent = await Promise.race([retryDelay(retryInfo.count), connectedPromise]);
82
+ const result = await this.wire.sendAction('connect-to-channel', { ...connectPayload, retryInfo });
83
+ // log only if there was a retry
84
+ console.log(`Successfully connected to channelName: ${channelName}`);
85
+ return result.payload.data;
90
86
  }
91
- catch (error) {
92
- console.warn(`Something went wrong during disconnect for client with uuid: ${routingInfo.uuid} / name: ${routingInfo.name} / endpointId: ${routingInfo.endpointId}.`);
87
+ // Send retryInfo to the core for debug log inclusion
88
+ const sentMessagePromise = this.wire.sendAction('connect-to-channel', connectPayload);
89
+ // Save messageId from the first connection attempt
90
+ retryInfo.originalMessageId = sentMessagePromise.messageId;
91
+ const result = await sentMessagePromise;
92
+ return result.payload.data;
93
+ }
94
+ catch (error) {
95
+ if (!error.message.includes('internal-nack')) {
96
+ // Not an internal nack, break the loop
97
+ throw error;
93
98
  }
94
- finally {
95
- client_1.default.handleProviderDisconnect(routingInfo);
99
+ if (shouldWait && retryInfo.count === 0) {
100
+ // start waiting on the next iteration, warn the user
101
+ console.warn(`No channel found for channelName: ${channelName}. Waiting for connection...`);
96
102
  }
97
- });
98
- return channel;
103
+ }
104
+ finally {
105
+ retryInfo.count += 1;
106
+ // in case of other errors, remove our listener
107
+ __classPrivateFieldGet(this, _Channel_internalEmitter, "f").removeListener('connected', connectedListener);
108
+ }
109
+ } while (shouldWait); // If we're waiting we retry the above loop
110
+ // Should wait was false, no channel was found.
111
+ throw new Error(`No channel found for channelName: ${channelName}.`);
112
+ /* eslint-enable no-await-in-loop, no-constant-condition */
113
+ }
114
+ async connect(channelName, options = {}) {
115
+ // Make sure we don't connect before listeners are set up
116
+ // This also errors if we're not in OpenFin, ensuring we don't run unnecessary code
117
+ await __classPrivateFieldGet(this, _Channel_readyToConnect, "f").getValue();
118
+ if (!channelName || typeof channelName !== 'string') {
119
+ throw new Error('Please provide a channelName string to connect to a channel.');
120
+ }
121
+ const opts = { wait: true, ...this.wire.environment.getDefaultChannelOptions().connect, ...options };
122
+ const { offer, rtc: rtcPacket } = await __classPrivateFieldGet(this, _Channel_connectionManager, "f").createClientOffer(opts);
123
+ let connectionUrl;
124
+ if (this.fin.me.isFrame || this.fin.me.isView || this.fin.me.isWindow) {
125
+ connectionUrl = (await this.fin.me.getInfo()).url;
99
126
  }
100
- catch (e) {
101
- const shouldWait = { wait: true, ...opts }.wait;
102
- const internalNackMessage = 'internal-nack';
103
- if (shouldWait && e.message && e.message.includes(internalNackMessage)) {
104
- console.warn(`Channel not found for channelName: ${channelName}, waiting for channel connection.`);
105
- return waitResponse;
127
+ const connectPayload = {
128
+ channelName,
129
+ ...opts,
130
+ offer,
131
+ connectionUrl
132
+ };
133
+ const routingInfo = await this.safeConnect(channelName, opts.wait, connectPayload);
134
+ const strategy = await __classPrivateFieldGet(this, _Channel_connectionManager, "f").createClientStrategy(rtcPacket, routingInfo);
135
+ const channel = new client_1.default(routingInfo, this.wire, strategy);
136
+ // It is the client's responsibility to handle endpoint disconnection to the provider.
137
+ // If the endpoint dies, the client will force a disconnection through the core.
138
+ // The provider does not care about endpoint disconnection.
139
+ strategy.onEndpointDisconnect(routingInfo.channelId, async () => {
140
+ try {
141
+ await channel.sendDisconnectAction();
106
142
  }
107
- if (e.message === internalNackMessage) {
108
- throw new Error(`No channel found for channelName: ${channelName}`);
143
+ catch (error) {
144
+ console.warn(`Something went wrong during disconnect for client with uuid: ${routingInfo.uuid} / name: ${routingInfo.name} / endpointId: ${routingInfo.endpointId}.`);
109
145
  }
110
- else {
111
- throw new Error(e);
146
+ finally {
147
+ client_1.default.handleProviderDisconnect(routingInfo);
112
148
  }
113
- }
149
+ });
150
+ return channel;
114
151
  }
115
152
  async create(channelName, options) {
116
153
  if (!channelName) {
@@ -129,4 +166,4 @@ class Channel extends base_1.EmitterBase {
129
166
  }
130
167
  }
131
168
  exports.Channel = Channel;
132
- _Channel_connectionManager = new WeakMap();
169
+ _Channel_connectionManager = new WeakMap(), _Channel_internalEmitter = new WeakMap(), _Channel_readyToConnect = new WeakMap();
@@ -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 _ClassicStrategy_wire, _ClassicStrategy_endpointIdentityMap;
13
+ var _ClassicStrategy_wire, _ClassicStrategy_endpointIdentityMap, _ClassicStrategy_pendingMessagesByEndpointId;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.ClassicInfo = exports.ClassicStrategy = void 0;
16
16
  /*
@@ -26,7 +26,11 @@ class ClassicStrategy {
26
26
  // Store full endpointIdentity by endpointId of all known endpoints for this strategy instance.
27
27
  // (clients will only have 1: the provider, the provider will have all clients)
28
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);
29
32
  this.send = async (endpointId, action, payload) => {
33
+ var _a;
30
34
  const to = __classPrivateFieldGet(this, _ClassicStrategy_endpointIdentityMap, "f").get(endpointId);
31
35
  if (!to) {
32
36
  throw new Error(`Could not locate routing info for endpoint ${endpointId}`);
@@ -38,20 +42,27 @@ class ClassicStrategy {
38
42
  delete cleanId.endpointId;
39
43
  }
40
44
  delete cleanId.isLocalEndpointId;
41
- const raw = await __classPrivateFieldGet(this, _ClassicStrategy_wire, "f")
45
+ // grab the promise before awaiting it to save in our pending messages map
46
+ const p = __classPrivateFieldGet(this, _ClassicStrategy_wire, "f")
42
47
  .sendAction('send-channel-message', {
43
48
  ...cleanId,
44
49
  providerIdentity: this.providerIdentity,
45
50
  action,
46
51
  payload
47
- })
48
- .catch((reason) => {
49
- throw new Error(reason.message);
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);
50
60
  });
51
61
  return raw.payload.data.result;
52
62
  };
53
63
  this.close = async () => {
54
64
  this.messageReceiver.removeEndpoint(this.providerIdentity.channelId, this.endpointId);
65
+ [...__classPrivateFieldGet(this, _ClassicStrategy_endpointIdentityMap, "f").keys()].forEach((id) => this.closeEndpoint(id));
55
66
  __classPrivateFieldSet(this, _ClassicStrategy_endpointIdentityMap, new Map(), "f");
56
67
  };
57
68
  __classPrivateFieldSet(this, _ClassicStrategy_wire, wire, "f");
@@ -63,13 +74,20 @@ class ClassicStrategy {
63
74
  this.messageReceiver.addEndpoint(listener, this.providerIdentity.channelId, this.endpointId);
64
75
  }
65
76
  async closeEndpoint(endpointId) {
77
+ const id = __classPrivateFieldGet(this, _ClassicStrategy_endpointIdentityMap, "f").get(endpointId);
66
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
+ });
67
84
  }
68
85
  isEndpointConnected(endpointId) {
69
86
  return __classPrivateFieldGet(this, _ClassicStrategy_endpointIdentityMap, "f").has(endpointId);
70
87
  }
71
88
  addEndpoint(endpointId, payload) {
72
89
  __classPrivateFieldGet(this, _ClassicStrategy_endpointIdentityMap, "f").set(endpointId, payload.endpointIdentity);
90
+ __classPrivateFieldGet(this, _ClassicStrategy_pendingMessagesByEndpointId, "f").set(endpointId, new Set());
73
91
  }
74
92
  isValidEndpointPayload(payload) {
75
93
  var _a, _b;
@@ -78,6 +96,6 @@ class ClassicStrategy {
78
96
  }
79
97
  }
80
98
  exports.ClassicStrategy = ClassicStrategy;
81
- _ClassicStrategy_wire = new WeakMap(), _ClassicStrategy_endpointIdentityMap = new WeakMap();
99
+ _ClassicStrategy_wire = new WeakMap(), _ClassicStrategy_endpointIdentityMap = new WeakMap(), _ClassicStrategy_pendingMessagesByEndpointId = new WeakMap();
82
100
  // Arbitrarily starting at 5 to leave the door open to backfilling pre endpointId etc.
83
101
  exports.ClassicInfo = { version: 5, minimumVersion: 0, type: 'classic' };
@@ -17,7 +17,7 @@ class InterApplicationBus extends base_1.Base {
17
17
  subscriberAdded: 'subscriber-added',
18
18
  subscriberRemoved: 'subscriber-removed'
19
19
  };
20
- this.refCounter = new ref_counter_1.default();
20
+ this.refCounter = new ref_counter_1.RefCounter();
21
21
  this.Channel = new index_1.Channel(wire);
22
22
  this.emitter = new events_1.EventEmitter();
23
23
  wire.registerMessageHandler(this.onmessage.bind(this));
@@ -88,7 +88,7 @@ import { Base } from '../base';
88
88
  * @summary A SessionContextGroup instance method for adding a handler for context change.
89
89
  * @param {ContextHandler} contextHandler The callback to be invoked. Is invoked when (a) the context changes or (b) immediately after getting created if the context is already set.
90
90
  * @param {string} [contextType] The context type this handler should listen to. If not specified, a global handler for all context types will get created. Only one global handler is allowed per SessionContextGroup.
91
- * @return {Promise<void>}
91
+ * @return {Promise<Subscription>}
92
92
  */
93
93
  /**
94
94
  * {@link https://developers.openfin.co/of-docs/docs/enable-color-linking}
@@ -103,7 +103,7 @@ const utils_1 = require("./utils");
103
103
  * @summary A SessionContextGroup instance method for adding a handler for context change.
104
104
  * @param {ContextHandler} contextHandler The callback to be invoked. Is invoked when (a) the context changes or (b) immediately after getting created if the context is already set.
105
105
  * @param {string} [contextType] The context type this handler should listen to. If not specified, a global handler for all context types will get created. Only one global handler is allowed per SessionContextGroup.
106
- * @return {Promise<void>}
106
+ * @return {Promise<Subscription>}
107
107
  */
108
108
  /**
109
109
  * {@link https://developers.openfin.co/of-docs/docs/enable-color-linking}
@@ -18,7 +18,7 @@ export default class SessionContextGroupBroker {
18
18
  handlerAdded(payload: {
19
19
  handlerId: string;
20
20
  contextType?: string;
21
- }, clientIdentity: OpenFin.ClientIdentity): void;
21
+ }, clientIdentity: OpenFin.ClientIdentity): Promise<void>;
22
22
  handlerRemoved(payload: {
23
23
  handlerId: string;
24
24
  }, clientIdentity: OpenFin.ClientIdentity): void;
@@ -48,7 +48,7 @@ class SessionContextGroupBroker {
48
48
  getClientState(id) {
49
49
  return this.clients.get(id.endpointId);
50
50
  }
51
- handlerAdded(payload, clientIdentity) {
51
+ async handlerAdded(payload, clientIdentity) {
52
52
  const { handlerId, contextType } = payload;
53
53
  const clientSubscriptionState = this.getClientState(clientIdentity);
54
54
  if (!clientSubscriptionState) {
@@ -59,17 +59,18 @@ class SessionContextGroupBroker {
59
59
  clientSubscriptionState.contextHandlers.set(contextType, [...currentHandlerList, handlerId]);
60
60
  const currentContext = this.contextGroupMap.get(contextType);
61
61
  if (currentContext) {
62
- this.provider.dispatch(clientIdentity, handlerId, currentContext);
62
+ await this.provider.dispatch(clientIdentity, handlerId, currentContext);
63
63
  }
64
64
  }
65
65
  else {
66
66
  clientSubscriptionState.globalHandler = handlerId;
67
- [...this.contextGroupMap.keys()].forEach((currentContextType) => {
67
+ const globalDispatchPromises = [...this.contextGroupMap.keys()].map(async (currentContextType) => {
68
68
  const currentContext = this.contextGroupMap.get(currentContextType);
69
69
  if (currentContext) {
70
- this.provider.dispatch(clientIdentity, handlerId, currentContext);
70
+ await this.provider.dispatch(clientIdentity, handlerId, currentContext);
71
71
  }
72
72
  });
73
+ await Promise.all(globalDispatchPromises);
73
74
  }
74
75
  }
75
76
  handlerRemoved(payload, clientIdentity) {
@@ -63,7 +63,7 @@ class SessionContextGroupClient extends base_1.Base {
63
63
  handlerId = `sessionContextHandler:invoke-${this.id}`;
64
64
  }
65
65
  client.register(handlerId, (0, utils_1.wrapContextHandler)(contextHandler, handlerId));
66
- client.dispatch(`sessionContextGroup:handlerAdded-${this.id}`, { handlerId, contextType });
66
+ await client.dispatch(`sessionContextGroup:handlerAdded-${this.id}`, { handlerId, contextType });
67
67
  return { unsubscribe: await this.createUnsubscribeCb(handlerId) };
68
68
  }
69
69
  async createUnsubscribeCb(handlerId) {
@@ -1,5 +1,5 @@
1
1
  import type * as OpenFin from '../../../OpenFin';
2
- import { ChannelProvider } from '../../interappbus/channel/provider';
2
+ type ChannelProvider = OpenFin.ChannelProvider;
3
3
  type HandlerId = string;
4
4
  type ContextType = string;
5
5
  interface PrivateChannelClientState {
@@ -84,16 +84,9 @@ class PrivateChannelProvider {
84
84
  if (contextType) {
85
85
  const currentHandlersList = senderClientState.handlerIdsByContextTypes.get(contextType) || [];
86
86
  senderClientState.handlerIdsByContextTypes.set(contextType, [...currentHandlersList, handlerId]);
87
- const currContext = this.contextByContextType.get(contextType);
88
- if (currContext) {
89
- this.provider.dispatch(senderClientIdentity, handlerId, currContext);
90
- }
91
87
  }
92
88
  else {
93
89
  senderClientState.globalHandler = handlerId;
94
- if (this.lastContext) {
95
- this.provider.dispatch(senderClientIdentity, handlerId, this.lastContext);
96
- }
97
90
  }
98
91
  Array.from(this.clients.values()).forEach((currClientState) => {
99
92
  if (currClientState.clientIdentity.endpointId !== senderClientIdentity.endpointId &&
@@ -271,7 +264,7 @@ class PrivateChannelProvider {
271
264
  const allClientInfo = await this.provider.getAllClientInfo();
272
265
  return Array.from(this.clients.values()).filter((clientState) => {
273
266
  const { uuid, name } = clientState.clientIdentity;
274
- return allClientInfo.some(clientInfo => {
267
+ return allClientInfo.some((clientInfo) => {
275
268
  return name === clientInfo.name && uuid === clientInfo.uuid;
276
269
  });
277
270
  });
@@ -4,6 +4,7 @@ const base_1 = require("../../base");
4
4
  const utils_1 = require("./utils");
5
5
  const utils_2 = require("../utils");
6
6
  const InteropClient_1 = require("../InteropClient");
7
+ const lodash_1 = require("lodash");
7
8
  /**
8
9
  * @typedef { object } Listener
9
10
  * @summary Listener object returned by addContextListener and addIntentListener
@@ -393,7 +394,39 @@ class Fdc3Module extends base_1.Base {
393
394
  return {
394
395
  ...currentContextGroupInfo,
395
396
  type: 'system',
396
- addContextListener: this.addContextListener.bind(this),
397
+ addContextListener: (contextType, handler) => {
398
+ let realHandler;
399
+ let realType;
400
+ if (typeof contextType === 'function') {
401
+ console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
402
+ realHandler = contextType;
403
+ }
404
+ else {
405
+ realHandler = handler;
406
+ if (typeof contextType === 'string') {
407
+ realType = contextType;
408
+ }
409
+ }
410
+ const listener = (async () => {
411
+ let first = true;
412
+ const currentContext = await this.fin.me.interop.getCurrentContext(realType);
413
+ const wrappedHandler = (context, contextMetadata) => {
414
+ if (first) {
415
+ first = false;
416
+ if ((0, lodash_1.isEqual)(currentContext, context)) {
417
+ return;
418
+ }
419
+ }
420
+ // eslint-disable-next-line consistent-return
421
+ return realHandler(context, contextMetadata);
422
+ };
423
+ return this.fin.me.interop.addContextHandler(wrappedHandler, realType);
424
+ })();
425
+ return {
426
+ ...listener,
427
+ unsubscribe: () => listener.then((l) => l.unsubscribe())
428
+ };
429
+ },
397
430
  broadcast: this.broadcast.bind(this),
398
431
  getCurrentContext: async (contextType) => {
399
432
  const context = await this.fin.me.interop.getCurrentContext(contextType);
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getIntentResolution = exports.isChannel = exports.isContext = exports.connectPrivateChannel = exports.buildAppChannelObject = exports.buildPrivateChannelObject = exports.ChannelError = exports.ResultError = exports.UnsupportedChannelApiError = exports.getUnsupportedChannelApis = void 0;
4
4
  const utils_1 = require("../utils");
5
5
  const PrivateChannelClient_1 = require("./PrivateChannelClient");
6
+ const lodash_1 = require("lodash");
6
7
  const getUnsupportedChannelApis = (channelType) => {
7
8
  return {
8
9
  addContextListener: () => {
@@ -111,14 +112,33 @@ const buildAppChannelObject = (sessionContextGroup) => {
111
112
  return context === undefined ? null : context;
112
113
  },
113
114
  addContextListener: (contextType, handler) => {
114
- let listener;
115
+ let realHandler;
116
+ let realType;
115
117
  if (typeof contextType === 'function') {
116
118
  console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
117
- listener = sessionContextGroup.addContextHandler(contextType);
119
+ realHandler = contextType;
118
120
  }
119
121
  else {
120
- listener = sessionContextGroup.addContextHandler(handler, contextType === null ? undefined : contextType);
122
+ realHandler = handler;
123
+ if (typeof contextType === 'string') {
124
+ realType = contextType;
125
+ }
121
126
  }
127
+ const listener = (async () => {
128
+ let first = true;
129
+ const currentContext = await sessionContextGroup.getCurrentContext(realType);
130
+ const wrappedHandler = (context, contextMetadata) => {
131
+ if (first) {
132
+ first = false;
133
+ if ((0, lodash_1.isEqual)(currentContext, context)) {
134
+ return;
135
+ }
136
+ }
137
+ // eslint-disable-next-line consistent-return
138
+ return realHandler(context, contextMetadata);
139
+ };
140
+ return sessionContextGroup.addContextHandler(wrappedHandler, realType);
141
+ })();
122
142
  return {
123
143
  ...listener,
124
144
  unsubscribe: () => listener.then((l) => l.unsubscribe())
@@ -149,7 +169,7 @@ exports.isContext = isContext;
149
169
  const isChannel = (channel) => {
150
170
  if (channel && typeof channel === 'object' && 'type' in channel && 'id' in channel) {
151
171
  const { type, id } = channel;
152
- return (typeof type === 'string' && typeof id === 'string' && (type === 'app' || type === 'private'));
172
+ return typeof type === 'string' && typeof id === 'string' && (type === 'app' || type === 'private');
153
173
  }
154
174
  return false;
155
175
  };
package/src/api/me.d.ts CHANGED
@@ -33,7 +33,7 @@ export declare function getBaseMe<T extends EntityType = EntityType>(entityType:
33
33
  export interface WithInterop {
34
34
  interop: InteropClient;
35
35
  }
36
- export type Me<MeType extends EntityType> = OpenFin.EntityInfo & (MeType extends 'view' ? EntityTypeHelpers<'view'> & OpenFin.View & WithInterop : MeType extends 'window' ? EntityTypeHelpers<'window'> & OpenFin.Window & WithInterop : MeType extends 'iframe' ? EntityTypeHelpers<'iframe'> & OpenFin.Frame & WithInterop : EntityTypeHelpers<MeType> & WithInterop) & {
36
+ export type Me<MeType extends EntityType> = OpenFin.EntityInfo & (MeType extends 'view' ? EntityTypeHelpers<'view'> & OpenFin.View & WithInterop : MeType extends 'window' ? EntityTypeHelpers<'window'> & OpenFin.Window & WithInterop : MeType extends 'iframe' ? EntityTypeHelpers<'iframe'> & OpenFin.Frame & WithInterop : MeType extends 'external connection' ? EntityTypeHelpers<'external connection'> & OpenFin.ExternalApplication & WithInterop : EntityTypeHelpers<MeType> & WithInterop) & {
37
37
  isOpenFin: boolean;
38
38
  };
39
39
  export declare function getMe<MeType extends EntityType>(wire: Transport<MeType>): Me<MeType>;
package/src/api/me.js CHANGED
@@ -4,6 +4,7 @@ exports.getMe = exports.getBaseMe = exports.environmentUnsupportedMessage = void
4
4
  const view_1 = require("./view");
5
5
  const frame_1 = require("./frame");
6
6
  const window_1 = require("./window");
7
+ const external_application_1 = require("./external-application");
7
8
  exports.environmentUnsupportedMessage = 'You are not running in OpenFin.';
8
9
  function getBaseMe(entityType, uuid, name) {
9
10
  const entityTypeHelpers = {
@@ -117,7 +118,7 @@ function getMe(wire) {
117
118
  isOpenFin: true
118
119
  });
119
120
  case 'external connection':
120
- return Object.assign(new window_1._Window(wire, { uuid, name }), getBaseMe(entityType, uuid, name), {
121
+ return Object.assign(new external_application_1.ExternalApplication(wire, { uuid }), getBaseMe(entityType, uuid, name), {
121
122
  interop: fallbackInterop,
122
123
  isOpenFin: false
123
124
  });
@@ -1,8 +1,8 @@
1
1
  import type * as OpenFin from '../../OpenFin';
2
- import { Base } from '../base';
3
- import { Channel } from '../interappbus/channel/index';
4
2
  import { Transport } from '../../transport/transport';
3
+ import { Base } from '../base';
5
4
  import { LayoutModule } from './layout/index';
5
+ type Channel = OpenFin.Fin['InterApplicationBus']['Channel'];
6
6
  /**
7
7
  * @PORTED
8
8
  * InitPlatformOptions interface
@@ -51,7 +51,6 @@ import { LayoutModule } from './layout/index';
51
51
  export default class PlatformModule extends Base {
52
52
  private _channel;
53
53
  Layout: LayoutModule;
54
- private _initializer;
55
54
  constructor(wire: Transport, channel: Channel);
56
55
  /**
57
56
  * Initializes a Platform. Must be called from the Provider when using a custom provider.
@@ -113,3 +112,4 @@ export default class PlatformModule extends Base {
113
112
  */
114
113
  startFromManifest(manifestUrl: string, opts?: OpenFin.RvmLaunchOptions): Promise<OpenFin.Platform>;
115
114
  }
115
+ export {};
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- /* eslint-disable no-undef, no-underscore-dangle */
4
3
  const base_1 = require("../base");
5
- const index_1 = require("./layout/index");
6
4
  const Instance_1 = require("./Instance");
5
+ const index_1 = require("./layout/index");
7
6
  /**
8
7
  * @PORTED
9
8
  * InitPlatformOptions interface
@@ -53,9 +52,6 @@ class PlatformModule extends base_1.Base {
53
52
  constructor(wire, channel) {
54
53
  super(wire);
55
54
  this._channel = channel;
56
- this._initializer = (...args) => this.wire.environment
57
- .getProviderInitializer()
58
- .then((initConstructor) => initConstructor(this.wire.environment)(...args));
59
55
  /**
60
56
  * @namespace
61
57
  * @desc Layouts give app providers the ability to embed multiple views in a single window. The Layout namespace
@@ -74,12 +70,7 @@ class PlatformModule extends base_1.Base {
74
70
  * @static
75
71
  */
76
72
  async init(options) {
77
- const overrideCallback = options === null || options === void 0 ? void 0 : options.overrideCallback;
78
- const interopBroker = await this.fin.Interop.init(this.fin.me.uuid, options === null || options === void 0 ? void 0 : options.interopOverride);
79
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
80
- // @ts-expect-error debugging purposes
81
- window.interopBroker = interopBroker;
82
- return this._initializer(overrideCallback, interopBroker);
73
+ return this.wire.environment.initPlatform(this.fin, options);
83
74
  }
84
75
  /**
85
76
  * Asynchronously returns a Platform object that represents an existing platform.
@@ -1,9 +1,9 @@
1
1
  import type * as OpenFin from '../../OpenFin';
2
- import { View } from '../view';
3
2
  import { EmitterBase } from '../base';
4
- import { Channel } from '../interappbus/channel/index';
5
- import ChannelClient from '../interappbus/channel/client';
6
- import { LayoutModule } from './layout';
3
+ type View = OpenFin.View;
4
+ type Channel = OpenFin.Fin['InterApplicationBus']['Channel'];
5
+ type ChannelClient = OpenFin.ChannelClient;
6
+ type LayoutModule = OpenFin.Fin['Platform']['Layout'];
7
7
  /** Manages the life cycle of windows and views in the application.
8
8
  *
9
9
  * Enables taking snapshots of itself and applyi
@@ -147,3 +147,4 @@ export declare class Platform extends EmitterBase<OpenFin.PlatformEvent> {
147
147
  skipBeforeUnload: boolean;
148
148
  }): Promise<void>;
149
149
  }
150
+ export {};