@openfin/core 30.73.28 → 31.74.2

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 (160) hide show
  1. package/LICENSE.md +4 -0
  2. package/package.json +2 -2
  3. package/src/OpenFin.d.ts +1929 -407
  4. package/src/OpenFin.js +0 -2
  5. package/src/api/api-exposer/api-consumer.d.ts +28 -0
  6. package/src/api/api-exposer/api-consumer.js +28 -0
  7. package/src/api/api-exposer/api-exposer.d.ts +35 -0
  8. package/src/api/api-exposer/api-exposer.js +38 -0
  9. package/src/api/api-exposer/decorators.d.ts +10 -0
  10. package/src/api/api-exposer/decorators.js +18 -0
  11. package/src/api/api-exposer/index.d.ts +4 -0
  12. package/src/api/api-exposer/index.js +20 -0
  13. package/src/api/api-exposer/strategies/index.d.ts +1 -0
  14. package/src/api/api-exposer/strategies/index.js +17 -0
  15. package/src/api/api-exposer/strategies/openfin-channels/channels-consumer.d.ts +14 -0
  16. package/src/api/api-exposer/strategies/openfin-channels/channels-consumer.js +20 -0
  17. package/src/api/api-exposer/strategies/openfin-channels/channels-exposer.d.ts +20 -0
  18. package/src/api/api-exposer/strategies/openfin-channels/channels-exposer.js +23 -0
  19. package/src/api/api-exposer/strategies/openfin-channels/index.d.ts +2 -0
  20. package/src/api/api-exposer/strategies/openfin-channels/index.js +18 -0
  21. package/src/api/application/Factory.d.ts +1 -0
  22. package/src/api/application/Factory.js +2 -2
  23. package/src/api/application/Instance.d.ts +2 -1
  24. package/src/api/application/Instance.js +1 -0
  25. package/src/api/base.d.ts +4 -4
  26. package/src/api/clipboard/index.d.ts +1 -0
  27. package/src/api/clipboard/index.js +1 -0
  28. package/src/api/events/application.d.ts +22 -22
  29. package/src/api/events/base.d.ts +6 -9
  30. package/src/api/events/channel.d.ts +5 -5
  31. package/src/api/events/emitterMap.d.ts +1 -1
  32. package/src/api/events/externalApplication.d.ts +3 -3
  33. package/src/api/events/frame.d.ts +5 -5
  34. package/src/api/events/globalHotkey.d.ts +3 -3
  35. package/src/api/events/platform.d.ts +6 -7
  36. package/src/api/events/system.d.ts +20 -21
  37. package/src/api/events/typedEventEmitter.d.ts +1 -1
  38. package/src/api/events/view.d.ts +17 -14
  39. package/src/api/events/webcontents.d.ts +40 -18
  40. package/src/api/events/window.d.ts +65 -57
  41. package/src/api/external-application/Instance.d.ts +1 -1
  42. package/src/api/fin.d.ts +2 -2
  43. package/src/api/frame/Instance.d.ts +2 -2
  44. package/src/api/global-hotkey/index.d.ts +1 -1
  45. package/src/api/interappbus/channel/channel.d.ts +5 -5
  46. package/src/api/interappbus/channel/channel.js +3 -3
  47. package/src/api/interappbus/channel/channels-docs.d.ts +7 -0
  48. package/src/api/interappbus/channel/channels-docs.js +7 -0
  49. package/src/api/interappbus/channel/client.d.ts +5 -4
  50. package/src/api/interappbus/channel/client.js +24 -17
  51. package/src/api/interappbus/channel/connection-manager.d.ts +2 -2
  52. package/src/api/interappbus/channel/connection-manager.js +12 -12
  53. package/src/api/interappbus/channel/index.d.ts +3 -3
  54. package/src/api/interappbus/channel/index.js +6 -8
  55. package/src/api/interappbus/channel/protocols/classic/message-receiver.d.ts +1 -1
  56. package/src/api/interappbus/channel/protocols/classic/strategy.d.ts +2 -2
  57. package/src/api/interappbus/channel/protocols/combined/strategy.d.ts +2 -2
  58. package/src/api/interappbus/channel/protocols/combined/strategy.js +5 -5
  59. package/src/api/interappbus/channel/protocols/index.d.ts +7 -4
  60. package/src/api/interappbus/channel/protocols/rtc/endpoint.d.ts +1 -1
  61. package/src/api/interappbus/channel/protocols/rtc/endpoint.js +10 -2
  62. package/src/api/interappbus/channel/protocols/rtc/ice-manager.d.ts +1 -1
  63. package/src/api/interappbus/channel/protocols/rtc/strategy.d.ts +1 -1
  64. package/src/api/interappbus/channel/protocols/rtc/strategy.js +1 -1
  65. package/src/api/interappbus/channel/protocols/strategy-types.d.ts +4 -4
  66. package/src/api/interappbus/channel/protocols/strategy.d.ts +3 -3
  67. package/src/api/interappbus/channel/provider.d.ts +6 -6
  68. package/src/api/interappbus/channel/provider.js +24 -24
  69. package/src/api/interappbus/index.d.ts +1 -1
  70. package/src/api/interop/Factory.d.ts +1 -2
  71. package/src/api/interop/Factory.js +20 -4
  72. package/src/api/interop/InteropBroker.d.ts +16 -48
  73. package/src/api/interop/InteropBroker.js +38 -48
  74. package/src/api/interop/InteropClient.d.ts +10 -9
  75. package/src/api/interop/InteropClient.js +9 -8
  76. package/src/api/interop/SessionContextGroupClient.d.ts +1 -1
  77. package/src/api/interop/fdc3/PrivateChannelClient.d.ts +2 -1
  78. package/src/api/interop/fdc3/PrivateChannelClient.js +15 -7
  79. package/src/api/interop/fdc3/PrivateChannelProvider.d.ts +16 -2
  80. package/src/api/interop/fdc3/PrivateChannelProvider.js +80 -21
  81. package/src/api/interop/fdc3/fdc3-1.2.js +27 -12
  82. package/src/api/interop/fdc3/fdc3-2.0.d.ts +13 -12
  83. package/src/api/interop/fdc3/fdc3-2.0.js +33 -26
  84. package/src/api/interop/fdc3/fdc3.d.ts +4 -5
  85. package/src/api/interop/fdc3/overrideCheck.d.ts +4 -0
  86. package/src/api/interop/fdc3/overrideCheck.js +32 -0
  87. package/src/api/interop/fdc3/shapes/fdc3v1.d.ts +3 -3
  88. package/src/api/interop/fdc3/shapes/fdc3v2.d.ts +5 -5
  89. package/src/api/interop/fdc3/utils.d.ts +17 -0
  90. package/src/api/interop/fdc3/utils.js +52 -18
  91. package/src/api/interop/fdc3/versions.d.ts +1 -0
  92. package/src/api/interop/fdc3/versions.js +2 -0
  93. package/src/api/interop/utils.d.ts +0 -1
  94. package/src/api/interop/utils.js +1 -9
  95. package/src/api/me.d.ts +4 -4
  96. package/src/api/platform/Factory.d.ts +6 -1
  97. package/src/api/platform/Factory.js +10 -9
  98. package/src/api/platform/Instance.d.ts +5 -3
  99. package/src/api/platform/Instance.js +5 -3
  100. package/src/api/platform/common-utils.d.ts +1 -1
  101. package/src/api/platform/layout/Factory.d.ts +5 -1
  102. package/src/api/platform/layout/Factory.js +15 -3
  103. package/src/api/platform/layout/Instance.d.ts +10 -4
  104. package/src/api/platform/layout/Instance.js +26 -1
  105. package/src/api/platform/layout/controllers/layout-content-cache.d.ts +9 -0
  106. package/src/api/platform/layout/controllers/layout-content-cache.js +54 -0
  107. package/src/api/platform/layout/controllers/layout-entities-controller.d.ts +117 -0
  108. package/src/api/platform/layout/controllers/layout-entities-controller.js +270 -0
  109. package/src/api/platform/layout/controllers/splitter-controller.d.ts +1 -1
  110. package/src/api/platform/layout/entities/layout-entities.d.ts +144 -0
  111. package/src/api/platform/layout/entities/layout-entities.js +216 -0
  112. package/src/api/platform/layout/entities/shapes.d.ts +6 -0
  113. package/src/api/platform/layout/entities/shapes.js +2 -0
  114. package/src/api/platform/layout/layout.constants.d.ts +1 -0
  115. package/src/api/platform/layout/layout.constants.js +4 -0
  116. package/src/api/platform/layout/shapes.d.ts +4 -1
  117. package/src/api/platform/layout/utils/layout-traversal.d.ts +4 -0
  118. package/src/api/platform/layout/utils/layout-traversal.js +65 -0
  119. package/src/api/platform/layout/utils/view-overlay.d.ts +1 -1
  120. package/src/api/platform/provider.d.ts +162 -0
  121. package/src/api/platform/provider.js +2 -0
  122. package/src/api/snapshot-source/Factory.d.ts +1 -0
  123. package/src/api/snapshot-source/Factory.js +1 -0
  124. package/src/api/snapshot-source/Instance.d.ts +1 -1
  125. package/src/api/system/index.d.ts +14 -484
  126. package/src/api/system/index.js +6 -476
  127. package/src/api/view/Instance.d.ts +20 -6
  128. package/src/api/view/Instance.js +48 -8
  129. package/src/api/webcontents/main.d.ts +18 -4
  130. package/src/api/window/Instance.d.ts +21 -1
  131. package/src/api/window/Instance.js +20 -0
  132. package/src/browser.js +1 -1
  133. package/src/environment/browser.d.ts +1 -1
  134. package/src/environment/environment.d.ts +1 -1
  135. package/src/environment/node-env.d.ts +1 -1
  136. package/src/environment/openfin-env.d.ts +1 -1
  137. package/src/mock.d.ts +1 -1
  138. package/src/mock.js +6 -3
  139. package/src/namespaces.d.ts +21 -0
  140. package/src/namespaces.js +24 -0
  141. package/src/shapes/ERROR_BOX_TYPES.d.ts +1 -1
  142. package/src/shapes/protocol.d.ts +3 -3
  143. package/src/transport/fin_store.d.ts +1 -1
  144. package/src/transport/transport-errors.d.ts +7 -2
  145. package/src/transport/transport-errors.js +1 -2
  146. package/src/transport/transport.d.ts +11 -8
  147. package/src/transport/transport.js +12 -6
  148. package/src/transport/wire.d.ts +14 -13
  149. package/src/util/channel-api-relay.d.ts +13 -0
  150. package/src/util/channel-api-relay.js +37 -0
  151. package/src/util/errors.d.ts +2 -2
  152. package/src/util/http.js +4 -2
  153. package/src/util/inaccessibleObject.d.ts +2 -0
  154. package/src/util/inaccessibleObject.js +49 -0
  155. package/src/util/lazy.d.ts +16 -0
  156. package/src/util/lazy.js +26 -0
  157. package/src/util/promises.d.ts +1 -1
  158. package/src/util/reversible-map.d.ts +11 -0
  159. package/src/util/reversible-map.js +49 -0
  160. package/src/util/utilTypes.d.ts +1 -1
@@ -17,12 +17,14 @@ const base_1 = require("../base");
17
17
  const SessionContextGroupClient_1 = require("./SessionContextGroupClient");
18
18
  const utils_1 = require("./utils");
19
19
  /**
20
+ * @PORTED
20
21
  * @typedef { object } Intent
21
22
  * @summary The combination of an action and a context that is passed to an application for resolution.
22
23
  * @property { string } name Name of the intent.
23
24
  * @property { Context } context Data associated with the intent
24
25
  */
25
26
  /**
27
+ * @REMOVED
26
28
  * @typedef { object } Subscription
27
29
  * @summary Object returned when subscribing a handler.
28
30
  * @property { function } unsubscribe Function to unsubscribe the handler.
@@ -36,6 +38,7 @@ const utils_1 = require("./utils");
36
38
  * @summary Subscription function for registerIntentHandler
37
39
  */
38
40
  /**
41
+ * @PORTED
39
42
  * @typedef { object } ClientIdentity
40
43
  * @summary The Identity for a Channel Client. Includes endpointId to differentiate between different connections for an entity.
41
44
  * @property {string} uuid GUID of an application.
@@ -43,12 +46,14 @@ const utils_1 = require("./utils");
43
46
  * @property {string} endpointId Unique differentiator for different Channel connections for an entity.
44
47
  */
45
48
  /**
49
+ * @PORTED
46
50
  * @typedef { object } ContextGroupInfo
47
51
  * @summary Information for a Context Group. Contains metadata for displaying the group properly.
48
52
  * @property {string} id Name of the context group
49
53
  * @property {DisplayMetadata} displayMetadata Metadata for the Context Group. Contains the group's human-readable name, color, and an image, as defined by the Interop Broker.
50
54
  */
51
55
  /**
56
+ * @PORTED
52
57
  * @typedef { object } DisplayMetadata
53
58
  * @summary The display data for a Context Group.
54
59
  * @property {string} name A user-readable name for this context group, e.g: `"Red"`
@@ -56,6 +61,7 @@ const utils_1 = require("./utils");
56
61
  * @property {string} [glyph] A URL of an image that can be used to display this context group
57
62
  */
58
63
  /**
64
+ * @PORTED
59
65
  * @typedef { object } Context
60
66
  * @summary Data passed between entities and applications.
61
67
  * @property {object} [id] An object containing string key-value pairs for the bulk of the data for the context. Differs between context types.
@@ -63,6 +69,7 @@ const utils_1 = require("./utils");
63
69
  * @property {string} type Conserved type for the context (e.g. `instrument` or `country`)
64
70
  */
65
71
  /**
72
+ * @REMOVED
66
73
  * @typedef { object } ContextForIntent
67
74
  * @summary Data passed between entities and applications, including an optional metadata.
68
75
  * @property {object} [id] An object containing string key-value pairs for the bulk of the data for the context. Differs between context types.
@@ -71,6 +78,7 @@ const utils_1 = require("./utils");
71
78
  * @property {any} [metadata]
72
79
  */
73
80
  /**
81
+ * @REMOVED
74
82
  * @typedef { object } SessionContextGroup
75
83
  * @summary An instance of a SessionContextGroup
76
84
  * @property {string} id The SessionContextGroup's id.
@@ -98,7 +106,7 @@ const utils_1 = require("./utils");
98
106
  * @return {Promise<void>}
99
107
  */
100
108
  /**
101
- * {@link https://developers.openfin.co/of-docs/docs/enable-color-linking **THE INTEROP API IS EXPERIMENTAL. IF YOU WOULD LIKE TO USE IT, PLEASE USE OUR DEFAULT IMPLEMENTATION IN BROWSER**}
109
+ * {@link https://developers.openfin.co/of-docs/docs/enable-color-linking}
102
110
  *
103
111
  * The Interop Client API is broken up into two groups:
104
112
  *
@@ -305,7 +313,6 @@ class InteropClient extends base_1.Base {
305
313
  * @param { Intent } intent - The combination of an action and a context that is passed to an application for resolution.
306
314
  * @return { Promise<unknown>}
307
315
  * @tutorial interop.fireIntent
308
- * @experimental
309
316
  */
310
317
  async fireIntent(intent) {
311
318
  this.wire.sendAction('interop-client-fire-intent').catch((e) => {
@@ -320,7 +327,6 @@ class InteropClient extends base_1.Base {
320
327
  * @param { string } intentName - The name of an intent.
321
328
  * @return { Promise<Subscription> }
322
329
  * @tutorial interop.registerIntentHandler
323
- * @experimental
324
330
  */
325
331
  async registerIntentHandler(handler, intentName, options) {
326
332
  this.wire.sendAction('interop-client-register-intent-handler').catch((e) => {
@@ -348,7 +354,6 @@ class InteropClient extends base_1.Base {
348
354
  * @param { string } [contextType]
349
355
  * @return { Promise<Context> }
350
356
  * @tutorial interop.getCurrentContext
351
- * @experimental
352
357
  */
353
358
  async getCurrentContext(contextType) {
354
359
  this.wire.sendAction('interop-client-get-current-context').catch((e) => {
@@ -362,7 +367,6 @@ class InteropClient extends base_1.Base {
362
367
  * @param { InfoForIntentOptions } options
363
368
  * @return { Promise<unknown> }
364
369
  * @tutorial interop.getInfoForIntent
365
- * @experimental
366
370
  */
367
371
  async getInfoForIntent(options) {
368
372
  this.wire.sendAction('interop-client-get-info-for-intent').catch((e) => {
@@ -376,7 +380,6 @@ class InteropClient extends base_1.Base {
376
380
  * @param { Context } context
377
381
  * @return { Promise<unknown> }
378
382
  * @tutorial interop.getInfoForIntentsByContext
379
- * @experimental
380
383
  */
381
384
  async getInfoForIntentsByContext(context) {
382
385
  this.wire.sendAction('interop-client-get-info-for-intents-by-context').catch((e) => {
@@ -391,7 +394,6 @@ class InteropClient extends base_1.Base {
391
394
  * @param { ContextForIntent } context
392
395
  * @return { Promise<unknown> }
393
396
  * @tutorial interop.fireIntentForContext
394
- * @experimental
395
397
  */
396
398
  async fireIntentForContext(context) {
397
399
  this.wire.sendAction('interop-client-fire-intent-for-context').catch((e) => {
@@ -407,7 +409,6 @@ class InteropClient extends base_1.Base {
407
409
  * @param { string } sessionContextGroupId - Id of the context group.
408
410
  * @return { Promise<SessionContextGroup>}
409
411
  * @tutorial interop.joinSessionContextGroup
410
- * @experimental
411
412
  */
412
413
  async joinSessionContextGroup(sessionContextGroupId) {
413
414
  try {
@@ -1,5 +1,5 @@
1
1
  import type * as OpenFin from '../../OpenFin';
2
- import Transport from '../../transport/transport';
2
+ import { Transport } from '../../transport/transport';
3
3
  import { Base } from '../base';
4
4
  export default class SessionContextGroupClient extends Base {
5
5
  #private;
@@ -1,6 +1,6 @@
1
1
  import type * as OpenFin from '../../../OpenFin';
2
2
  import type { Listener, Context, ContextHandler } from './shapes/fdc3v2';
3
- declare type HandlerId = string;
3
+ type HandlerId = string;
4
4
  export declare class PrivateChannelClient {
5
5
  id: string;
6
6
  client: OpenFin.ChannelClient;
@@ -14,6 +14,7 @@ export declare class PrivateChannelClient {
14
14
  onAddContextListener(handler: (contextType?: string) => void): Listener;
15
15
  onDisconnect(handler: () => void): Listener;
16
16
  onUnsubscribe(handler: (contextType?: string) => void): Listener;
17
+ cleanUpAllSubs(): Promise<void>;
17
18
  disconnect(): Promise<void>;
18
19
  }
19
20
  export {};
@@ -69,14 +69,22 @@ class PrivateChannelClient {
69
69
  this.client.dispatch(`onUnsubscribeHandlerAdded`, { handlerId });
70
70
  return listener;
71
71
  }
72
- async disconnect() {
73
- const listenerUnsubscribers = Array.from(this.listeners.values());
74
- const promises = listenerUnsubscribers.map(async (listenerUnsubscriber) => {
75
- await listenerUnsubscriber.unsubscribe();
72
+ async cleanUpAllSubs() {
73
+ const listenerUnsubscribers = Array.from(this.listeners.keys());
74
+ listenerUnsubscribers.forEach((handlerId) => {
75
+ this.client.remove(handlerId);
76
+ this.listeners.delete(handlerId);
76
77
  });
77
- await Promise.all(promises);
78
- await this.client.dispatch('clientDisconnecting');
79
- await this.client.disconnect();
78
+ }
79
+ async disconnect() {
80
+ try {
81
+ await this.client.dispatch('clientDisconnecting');
82
+ await this.cleanUpAllSubs();
83
+ await this.client.disconnect();
84
+ }
85
+ catch (error) {
86
+ throw new Error(error.message);
87
+ }
80
88
  }
81
89
  }
82
90
  exports.PrivateChannelClient = PrivateChannelClient;
@@ -1,6 +1,15 @@
1
1
  import type * as OpenFin from '../../../OpenFin';
2
2
  import { ChannelProvider } from '../../interappbus/channel/provider';
3
- declare type HandlerId = string;
3
+ type HandlerId = string;
4
+ type ContextType = string;
5
+ interface PrivateChannelClientState {
6
+ clientIdentity: OpenFin.ClientIdentity;
7
+ handlerIdsByContextTypes: Map<ContextType, HandlerId[]>;
8
+ globalHandler: HandlerId | undefined;
9
+ onAddContextListenerHandlerId: HandlerId | undefined;
10
+ onUnsubscribeHandlerId: HandlerId | undefined;
11
+ onDisconnectHandlerId: HandlerId | undefined;
12
+ }
4
13
  export declare class PrivateChannelProvider {
5
14
  id: string;
6
15
  private provider;
@@ -35,7 +44,12 @@ export declare class PrivateChannelProvider {
35
44
  onUnsubscribeHandlerAdded(payload: {
36
45
  handlerId: HandlerId;
37
46
  }, id: OpenFin.ClientIdentity): void;
38
- clientDisconnecting(payload: {}, disconnectingClientIdentity: OpenFin.ClientIdentity): Promise<void>;
47
+ removeClient(disconnectingClientIdentity: OpenFin.ClientIdentity): void;
48
+ fireOnDisconnectForOtherClients(disconnectingClientIdentity: OpenFin.ClientIdentity): Promise<void>;
49
+ unsubscribeAll(clientIdentity: OpenFin.ClientIdentity): Promise<void>;
50
+ handleClientDisconnecting(disconnectingClientIdentity: OpenFin.ClientIdentity): Promise<void>;
39
51
  registerNewClient(clientIdentity: OpenFin.ClientIdentity): void;
52
+ getConnectedClients(): Promise<PrivateChannelClientState[]>;
53
+ static init(channelProvider: OpenFin.ChannelProvider, id: string): PrivateChannelProvider;
40
54
  }
41
55
  export {};
@@ -11,7 +11,15 @@ class PrivateChannelProvider {
11
11
  this.contextByContextType = new Map();
12
12
  this.lastContext = undefined;
13
13
  this.provider.onConnection((clientIdentity) => this.registerNewClient(clientIdentity));
14
- this.provider.onDisconnection((clientIdentity) => this.clients.delete(clientIdentity.endpointId));
14
+ this.provider.onDisconnection(async (clientIdentity) => {
15
+ const { endpointId } = clientIdentity;
16
+ if (this.clients.has(endpointId)) {
17
+ await this.handleClientDisconnecting(clientIdentity);
18
+ }
19
+ if ((await this.provider.getAllClientInfo()).length === 0) {
20
+ this.provider.destroy();
21
+ }
22
+ });
15
23
  }
16
24
  getClientState(id) {
17
25
  return this.clients.get(id.endpointId);
@@ -25,7 +33,9 @@ class PrivateChannelProvider {
25
33
  this.provider.register('onAddContextHandlerAdded', this.onAddContextHandlerAdded.bind(this));
26
34
  this.provider.register('onDisconnectHandlerAdded', this.onDisconnectHandlerAdded.bind(this));
27
35
  this.provider.register('onUnsubscribeHandlerAdded', this.onUnsubscribeHandlerAdded.bind(this));
28
- this.provider.register('clientDisconnecting', this.clientDisconnecting.bind(this));
36
+ this.provider.register('clientDisconnecting', (payload, clientIdentity) => {
37
+ this.handleClientDisconnecting(clientIdentity);
38
+ });
29
39
  }
30
40
  broadcast(payload, broadcasterClientIdentity) {
31
41
  const { context } = payload;
@@ -110,17 +120,18 @@ class PrivateChannelProvider {
110
120
  }
111
121
  }
112
122
  }
113
- const dispatchesToSend = [];
114
- const otherClientStates = Array.from(this.clients.values());
115
- for (let i = 0; i < otherClientStates.length; i++) {
116
- const otherClientState = otherClientStates[i];
117
- if (otherClientState.clientIdentity.endpointId !== removingClientIdentity.endpointId &&
118
- otherClientState.onUnsubscribeHandlerId) {
119
- dispatchesToSend.push(this.provider.dispatch(otherClientState.clientIdentity, otherClientState.onUnsubscribeHandlerId, contextType));
123
+ // getting only valid client connections here, it is possible we haven't removed a disconnected client from the map yet
124
+ // so we need to ensure we don't dispatch to any disconnected client
125
+ // TODO: Take a look at our client disconnection logic and see if we can handle client disconnection cleanly
126
+ const clientsToDispatchTo = await this.getConnectedClients();
127
+ const dispatchPromises = clientsToDispatchTo.map(async (otherClientState) => {
128
+ const { clientIdentity, clientIdentity: { endpointId }, onUnsubscribeHandlerId } = otherClientState;
129
+ if (endpointId !== removingClientIdentity.endpointId && onUnsubscribeHandlerId) {
130
+ await this.provider.dispatch(clientIdentity, onUnsubscribeHandlerId, contextType);
120
131
  }
121
- }
132
+ });
122
133
  try {
123
- await Promise.all(dispatchesToSend);
134
+ await Promise.all(dispatchPromises);
124
135
  }
125
136
  catch (error) {
126
137
  console.error(`Problem when attempting to dispatch to onUnsubscribeHandlers. Error: ${error} Removing Client: ${handlerId}. uuid: ${removingClientIdentity.uuid}. name: ${removingClientIdentity.name}. endpointId: ${removingClientIdentity.endpointId}`);
@@ -181,32 +192,68 @@ class PrivateChannelProvider {
181
192
  }
182
193
  clientState.onUnsubscribeHandlerId = handlerId;
183
194
  }
184
- async clientDisconnecting(payload, disconnectingClientIdentity) {
195
+ removeClient(disconnectingClientIdentity) {
185
196
  const disconnectingClientState = this.getClientState(disconnectingClientIdentity);
186
197
  if (!disconnectingClientState) {
187
198
  throw new Error(`Client with Identity: ${disconnectingClientIdentity.uuid} ${disconnectingClientIdentity.name}, tried to call disconnect, is not connected to this Private Channel`);
188
199
  }
189
200
  disconnectingClientState.handlerIdsByContextTypes.clear();
190
201
  this.clients.delete(disconnectingClientIdentity.endpointId);
191
- const dispatchesToSend = [];
202
+ }
203
+ async fireOnDisconnectForOtherClients(disconnectingClientIdentity) {
192
204
  // TODO: call onDisconnect Handler of the other client only.
193
205
  // CURRENTLY, just calling the onDisconnect handler for all the other clients. Once we limit it to just one other client, we can eliminate all the iteration code.
194
- const otherClientStates = Array.from(this.clients.values());
195
- for (let i = 0; i < otherClientStates.length; i++) {
196
- const otherClientState = otherClientStates[i];
197
- if (otherClientState.clientIdentity.endpointId !== disconnectingClientIdentity.endpointId &&
198
- otherClientState.onDisconnectHandlerId) {
199
- dispatchesToSend.push(this.provider.dispatch(otherClientState.clientIdentity, otherClientState.onDisconnectHandlerId));
206
+ const { endpointId } = disconnectingClientIdentity;
207
+ // getting only valid client connections here, it is possible we haven't removed a disconnected client from the map yet
208
+ // so we need to ensure we don't dispatch to any disconnected client
209
+ // TODO: Take a look at our client disconnection logic and see if we can handle client disconnection cleanly
210
+ const clientsToDispatchTo = await this.getConnectedClients();
211
+ const dispatchPromises = clientsToDispatchTo.map(async (otherClientState) => {
212
+ const { clientIdentity: { endpointId: otherClientEndpointId }, onDisconnectHandlerId } = otherClientState;
213
+ if (otherClientEndpointId !== endpointId && onDisconnectHandlerId) {
214
+ await this.provider.dispatch(otherClientState.clientIdentity, onDisconnectHandlerId);
200
215
  }
201
- }
216
+ });
202
217
  try {
203
- await Promise.all(dispatchesToSend);
218
+ await Promise.all(dispatchPromises);
204
219
  }
205
220
  catch (error) {
206
221
  console.error(`Problem when attempting to dispatch to onDisconnectHandlers. Error: ${error} Disconnecting Client: uuid: ${disconnectingClientIdentity.uuid}. name: ${disconnectingClientIdentity.name}. endpointId: ${disconnectingClientIdentity.endpointId}`);
207
222
  throw new Error(error);
208
223
  }
209
224
  }
225
+ async unsubscribeAll(clientIdentity) {
226
+ const { endpointId } = clientIdentity;
227
+ const state = this.clients.get(endpointId);
228
+ if (state) {
229
+ const contextTypeHandlerIds = Array.from(state.handlerIdsByContextTypes.values()).flat();
230
+ const globalHandlerId = state.globalHandler;
231
+ if (contextTypeHandlerIds.length > 0) {
232
+ const unsubPromises = contextTypeHandlerIds.map(async (handlerId) => {
233
+ return this.contextHandlerRemoved({ handlerId }, clientIdentity);
234
+ });
235
+ try {
236
+ await Promise.all(unsubPromises);
237
+ }
238
+ catch (error) {
239
+ console.error(error.message);
240
+ }
241
+ }
242
+ if (globalHandlerId) {
243
+ try {
244
+ await this.contextHandlerRemoved({ handlerId: globalHandlerId }, clientIdentity);
245
+ }
246
+ catch (error) {
247
+ console.error(error.message);
248
+ }
249
+ }
250
+ }
251
+ }
252
+ async handleClientDisconnecting(disconnectingClientIdentity) {
253
+ await this.unsubscribeAll(disconnectingClientIdentity);
254
+ this.removeClient(disconnectingClientIdentity);
255
+ await this.fireOnDisconnectForOtherClients(disconnectingClientIdentity);
256
+ }
210
257
  registerNewClient(clientIdentity) {
211
258
  if (!this.clients.has(clientIdentity.endpointId)) {
212
259
  const clientSubscriptionState = {
@@ -220,5 +267,17 @@ class PrivateChannelProvider {
220
267
  this.clients.set(clientIdentity.endpointId, clientSubscriptionState);
221
268
  }
222
269
  }
270
+ async getConnectedClients() {
271
+ const allClientInfo = await this.provider.getAllClientInfo();
272
+ return Array.from(this.clients.values()).filter((clientState) => {
273
+ const { uuid, name } = clientState.clientIdentity;
274
+ return allClientInfo.some(clientInfo => {
275
+ return name === clientInfo.name && uuid === clientInfo.uuid;
276
+ });
277
+ });
278
+ }
279
+ static init(channelProvider, id) {
280
+ return new PrivateChannelProvider(channelProvider, id);
281
+ }
223
282
  }
224
283
  exports.PrivateChannelProvider = PrivateChannelProvider;
@@ -130,7 +130,7 @@ class Fdc3Module extends base_1.Base {
130
130
  this.wire.sendAction('fdc3-broadcast').catch((e) => {
131
131
  // we do not want to expose this error, just continue if this analytics-only call fails
132
132
  });
133
- this.fin.me.interop.setContext(context);
133
+ return this.fin.me.interop.setContext(context);
134
134
  }
135
135
  /**
136
136
  * Returns the Interop-Broker-defined context groups available for an entity to join.
@@ -165,15 +165,19 @@ class Fdc3Module extends base_1.Base {
165
165
  // we do not want to expose this error, just continue if this analytics-only call fails
166
166
  });
167
167
  try {
168
- await this.fin.me.interop.joinContextGroup(channelId);
168
+ return await this.fin.me.interop.joinContextGroup(channelId);
169
169
  }
170
170
  catch (error) {
171
171
  if (error.message === utils_2.BROKER_ERRORS.joinSessionContextGroupWithJoinContextGroup) {
172
- throw new Error('The Channel you have tried to join is an App Channel. Custom Channels can only be defined by the Interop Broker through code or manifest configuration. Please use getOrCreateChannel.');
172
+ console.error('The Channel you have tried to join is an App Channel. Custom Channels can only be defined by the Interop Broker through code or manifest configuration. Please use getOrCreateChannel.');
173
173
  }
174
174
  else {
175
- throw new Error(error.message);
175
+ console.error(error.message);
176
176
  }
177
+ if (error.message.startsWith('Attempting to join a context group that does not exist')) {
178
+ throw new Error(utils_1.ChannelError.NoChannelFound);
179
+ }
180
+ throw new Error(utils_1.ChannelError.AccessDenied);
177
181
  }
178
182
  }
179
183
  /**
@@ -187,7 +191,7 @@ class Fdc3Module extends base_1.Base {
187
191
  this.wire.sendAction('fdc3-leave-current-channel').catch((e) => {
188
192
  // we do not want to expose this error, just continue if this analytics-only call fails
189
193
  });
190
- this.fin.me.interop.removeFromContextGroup();
194
+ return this.fin.me.interop.removeFromContextGroup();
191
195
  }
192
196
  /**
193
197
  * Adds a listener for incoming Intents.
@@ -232,7 +236,7 @@ class Fdc3Module extends base_1.Base {
232
236
  return await this.fin.me.interop.fireIntent(intentObj);
233
237
  }
234
238
  catch (error) {
235
- const errorToThrow = error.message === utils_2.BROKER_ERRORS.fireIntent ? 'ResolverUnavailable' : error;
239
+ const errorToThrow = error.message === utils_2.BROKER_ERRORS.fireIntent ? 'ResolverUnavailable' : error.message;
236
240
  throw new Error(errorToThrow);
237
241
  }
238
242
  }
@@ -266,7 +270,7 @@ class Fdc3Module extends base_1.Base {
266
270
  return await this.fin.me.interop.getInfoForIntent({ name: intent, context });
267
271
  }
268
272
  catch (error) {
269
- const errorToThrow = error.message === utils_2.BROKER_ERRORS.getInfoForIntent ? 'ResolverUnavailable' : error;
273
+ const errorToThrow = error.message === utils_2.BROKER_ERRORS.getInfoForIntent ? 'ResolverUnavailable' : error.message;
270
274
  throw new Error(errorToThrow);
271
275
  }
272
276
  }
@@ -284,7 +288,7 @@ class Fdc3Module extends base_1.Base {
284
288
  return await this.fin.me.interop.getInfoForIntentsByContext(context);
285
289
  }
286
290
  catch (error) {
287
- const errorToThrow = error.message === utils_2.BROKER_ERRORS.getInfoForIntentsByContext ? 'ResolverUnavailable' : error;
291
+ const errorToThrow = error.message === utils_2.BROKER_ERRORS.getInfoForIntentsByContext ? 'ResolverUnavailable' : error.message;
288
292
  throw new Error(errorToThrow);
289
293
  }
290
294
  }
@@ -303,7 +307,7 @@ class Fdc3Module extends base_1.Base {
303
307
  return await this.fin.me.interop.fireIntentForContext({ ...context, metadata: { target: app } });
304
308
  }
305
309
  catch (error) {
306
- const errorToThrow = error.message === utils_2.BROKER_ERRORS.fireIntentForContext ? 'ResolverUnavailable' : error;
310
+ const errorToThrow = error.message === utils_2.BROKER_ERRORS.fireIntentForContext ? 'ResolverUnavailable' : error.message;
307
311
  throw new Error(errorToThrow);
308
312
  }
309
313
  }
@@ -317,8 +321,19 @@ class Fdc3Module extends base_1.Base {
317
321
  this.wire.sendAction('fdc3-get-or-create-channel').catch((e) => {
318
322
  // we do not want to expose this error, just continue if this analytics-only call fails
319
323
  });
320
- const sessionContextGroup = await this.fin.me.interop.joinSessionContextGroup(channelId);
321
- return (0, utils_1.buildAppChannelObject)(sessionContextGroup);
324
+ const systemChannels = await this.getSystemChannels();
325
+ const userChannel = systemChannels.find((channel) => channel.id === channelId);
326
+ if (userChannel) {
327
+ return { ...userChannel, type: 'system', ...(0, utils_1.getUnsupportedChannelApis)() };
328
+ }
329
+ try {
330
+ const sessionContextGroup = await this.fin.me.interop.joinSessionContextGroup(channelId);
331
+ return (0, utils_1.buildAppChannelObject)(sessionContextGroup);
332
+ }
333
+ catch (error) {
334
+ console.error(error.message);
335
+ throw new Error(utils_1.ChannelError.CreationFailed);
336
+ }
322
337
  }
323
338
  /**
324
339
  * Returns metadata relating to the FDC3 object and its provider, including the supported version of the FDC3 specification and the name of the provider of the implementation.
@@ -354,7 +369,7 @@ class Fdc3Module extends base_1.Base {
354
369
  return await InteropClient_1.InteropClient.ferryFdc3Call(this.fin.me.interop, 'fdc3Open', { app, context });
355
370
  }
356
371
  catch (error) {
357
- const errorToThrow = error.message === utils_2.BROKER_ERRORS.fdc3Open ? 'ResolverUnavailable' : error;
372
+ const errorToThrow = error.message === utils_2.BROKER_ERRORS.fdc3Open ? 'ResolverUnavailable' : error.message;
358
373
  throw new Error(errorToThrow);
359
374
  }
360
375
  }
@@ -1,7 +1,7 @@
1
1
  import type * as FDC3v1 from './shapes/fdc3v1';
2
2
  import type * as FDC3v2 from './shapes/fdc3v2';
3
3
  import { Base } from '../../base';
4
- import Transport from '../../../transport/transport';
4
+ import { Transport } from '../../../transport/transport';
5
5
  /**
6
6
  * @typedef { object } AppIdentifier
7
7
  * @summary Identifies an application, or instance of an application, and is used to target FDC3 API calls at specific applications.
@@ -171,14 +171,14 @@ export default class Fdc3Module2 extends Base implements FDC3v2.DesktopAgent {
171
171
  * Find all the available instances for a particular application.
172
172
  * @param { AppIdentifier } app
173
173
  * @returns { Promise<Array<AppIdentifier>> }
174
- * @tutorial findInstances
174
+ * @tutorial fdc3v2.findInstances
175
175
  */
176
176
  findInstances(app: FDC3v2.AppIdentifier): Promise<Array<FDC3v2.AppIdentifier>>;
177
177
  /**
178
178
  * Retrieves the AppMetadata for an AppIdentifier, which provides additional metadata (such as icons, a title and description) from the App Directory record for the application, that may be used for display purposes.
179
179
  * @param { AppIdentifier } app
180
180
  * @returns { Promise<AppMetadata(2)> }
181
- * @tutorial getAppMetadata
181
+ * @tutorial fdc3v2.getAppMetadata
182
182
  */
183
183
  getAppMetadata(app: FDC3v2.AppIdentifier): Promise<FDC3v2.AppMetadata>;
184
184
  /**
@@ -210,7 +210,7 @@ export default class Fdc3Module2 extends Base implements FDC3v2.DesktopAgent {
210
210
  * @param { Context } context
211
211
  * @param { string } [resultType] The type of result returned for any intent specified during resolution.
212
212
  * @returns { Promise<Array<AppIntent(2)>> }
213
- * @tutorial findIntentsByContext
213
+ * @tutorial fdc3v2.findIntentsByContext
214
214
  */
215
215
  findIntentsByContext(context: FDC3v2.Context, resultType?: string): Promise<Array<FDC3v2.AppIntent>>;
216
216
  /**
@@ -219,7 +219,7 @@ export default class Fdc3Module2 extends Base implements FDC3v2.DesktopAgent {
219
219
  * @param { Context } context Context associated with the Intent
220
220
  * @param { AppIdentifier | TargetApp } [app]
221
221
  * @returns { Promise<IntentResolution(2)> }
222
- * @tutorial raiseIntent
222
+ * @tutorial fdc3v2.raiseIntent
223
223
  */
224
224
  raiseIntent(intent: string, context: FDC3v2.Context, app?: FDC3v2.AppIdentifier | FDC3v1.TargetApp): Promise<FDC3v2.IntentResolution>;
225
225
  /**
@@ -227,7 +227,7 @@ export default class Fdc3Module2 extends Base implements FDC3v2.DesktopAgent {
227
227
  * @param { Context } context Context associated with the Intent
228
228
  * @param { AppIdentifier | TargetApp } [app]
229
229
  * @returns { Promise<IntentResolution(2)> }
230
- * @tutorial raiseIntentForContext
230
+ * @tutorial fdc3v2.raiseIntentForContext
231
231
  */
232
232
  raiseIntentForContext(context: FDC3v2.Context, app?: FDC3v2.AppIdentifier | FDC3v1.TargetApp): Promise<FDC3v2.IntentResolution>;
233
233
  /**
@@ -244,17 +244,17 @@ export default class Fdc3Module2 extends Base implements FDC3v2.DesktopAgent {
244
244
  * @returns { Promise<Channel> }
245
245
  * @tutorial fdc3.getOrCreateChannel
246
246
  */
247
- getOrCreateChannel(channelId: string): Promise<FDC3v1.Channel>;
247
+ getOrCreateChannel(channelId: string): Promise<FDC3v2.Channel>;
248
248
  /**
249
249
  * Returns a Channel with an auto-generated identity that is intended for private communication between applications. Primarily used to create channels that will be returned to other applications via an IntentResolution for a raised intent.
250
250
  * @returns { Promise<PrivateChannel> }
251
- * @tutorial createPrivateChannel
251
+ * @tutorial fdc3v2.createPrivateChannel
252
252
  */
253
253
  createPrivateChannel(): Promise<FDC3v2.PrivateChannel>;
254
254
  /**
255
255
  * Retrieves a list of the User Channels available for the app to join.
256
256
  * @returns { Promise<Channel[]>}
257
- * @tutorial getUserChannels
257
+ * @tutorial fdc3v2.getUserChannels
258
258
  */
259
259
  getUserChannels(): Promise<Array<FDC3v1.SystemChannel>>;
260
260
  /**
@@ -268,7 +268,7 @@ export default class Fdc3Module2 extends Base implements FDC3v2.DesktopAgent {
268
268
  * Join an app to a specified User channel.
269
269
  * @param { string } channelId Channel name
270
270
  * @returns { Promise<void> }
271
- * @tutorial joinUserChannel
271
+ * @tutorial fdc3v2.joinUserChannel
272
272
  */
273
273
  joinUserChannel(channelId: string): Promise<void>;
274
274
  /**
@@ -282,8 +282,9 @@ export default class Fdc3Module2 extends Base implements FDC3v2.DesktopAgent {
282
282
  /**
283
283
  * Returns the Channel object for the current User channel membership
284
284
  * @returns { Promise<FDC3.Channel | null> }
285
+ * @tutorial fdc3.getCurrentChannel
285
286
  */
286
- getCurrentChannel(): Promise<FDC3v1.Channel | null>;
287
+ getCurrentChannel(): Promise<FDC3v2.Channel | null>;
287
288
  /**
288
289
  * Removes the app from any User channel membership.
289
290
  * @returns { Promise<void> }
@@ -294,7 +295,7 @@ export default class Fdc3Module2 extends Base implements FDC3v2.DesktopAgent {
294
295
  * Retrieves information about the FDC3 implementation, including the supported version of the FDC3 specification, the name of the provider of the implementation, its own version number, details of whether optional API features are implemented and the metadata of the calling application according to the desktop agent.
295
296
  * fdc3HandleGetInfo must be overridden in the InteropBroker so that the ImplementationMetadata will have the appMetadata info.
296
297
  * @returns { Promise<ImplementationMetadata(2)> }
297
- * @tutorial getInfo
298
+ * @tutorial fdc3v2.getInfo
298
299
  */
299
300
  getInfo(): Promise<FDC3v2.ImplementationMetadata>;
300
301
  }