@openfin/core 29.73.13 → 29.73.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfin/core",
3
- "version": "29.73.13",
3
+ "version": "29.73.15",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./src/mock.js",
6
6
  "types": "./src/mock.d.ts",
@@ -5,6 +5,7 @@ const base_1 = require("../base");
5
5
  const SessionContextGroupBroker_1 = require("./SessionContextGroupBroker");
6
6
  const utils_1 = require("./utils");
7
7
  const lodash_1 = require("lodash");
8
+ const PrivateChannelProvider_1 = require("./fdc3/PrivateChannelProvider");
8
9
  let contextGroups = [
9
10
  {
10
11
  id: 'green',
@@ -1043,6 +1044,11 @@ class InteropBroker extends base_1.Base {
1043
1044
  channel.register('fdc3v2GetInfo', async (payload, clientIdentity) => {
1044
1045
  return this.fdc3HandleGetInfo.bind(this)(payload, clientIdentity);
1045
1046
  });
1047
+ channel.register('createPrivateChannelProvider', async (payload) => {
1048
+ const { channelId } = payload;
1049
+ const channelProvider = await this.fin.InterApplicationBus.Channel.create(channelId);
1050
+ PrivateChannelProvider_1.PrivateChannelProvider.init(channelProvider, channelId);
1051
+ });
1046
1052
  }
1047
1053
  /**
1048
1054
  * Can be used to completely prevent a connection. Return false to prevent connections. Allows all connections by default.
@@ -13,6 +13,7 @@ export declare class PrivateChannelClient {
13
13
  onAddContextListener(handler: (contextType?: string) => void): Listener;
14
14
  onDisconnect(handler: () => void): Listener;
15
15
  onUnsubscribe(handler: (contextType?: string) => void): Listener;
16
+ cleanUpAllSubs(): Promise<void>;
16
17
  disconnect(): Promise<void>;
17
18
  }
18
19
  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,5 +1,14 @@
1
1
  import { ChannelProvider } from '../../interappbus/channel/provider';
2
2
  declare type HandlerId = string;
3
+ declare type ContextType = string;
4
+ interface PrivateChannelClientState {
5
+ clientIdentity: OpenFin.ClientIdentity;
6
+ handlerIdsByContextTypes: Map<ContextType, HandlerId[]>;
7
+ globalHandler: HandlerId | undefined;
8
+ onAddContextListenerHandlerId: HandlerId | undefined;
9
+ onUnsubscribeHandlerId: HandlerId | undefined;
10
+ onDisconnectHandlerId: HandlerId | undefined;
11
+ }
3
12
  export declare class PrivateChannelProvider {
4
13
  id: string;
5
14
  private provider;
@@ -34,7 +43,12 @@ export declare class PrivateChannelProvider {
34
43
  onUnsubscribeHandlerAdded(payload: {
35
44
  handlerId: HandlerId;
36
45
  }, id: OpenFin.ClientIdentity): void;
37
- clientDisconnecting(payload: {}, disconnectingClientIdentity: OpenFin.ClientIdentity): Promise<void>;
46
+ removeClient(disconnectingClientIdentity: OpenFin.ClientIdentity): void;
47
+ fireOnDisconnectForOtherClients(disconnectingClientIdentity: OpenFin.ClientIdentity): Promise<void>;
48
+ unsubscribeAll(clientIdentity: OpenFin.ClientIdentity): Promise<void>;
49
+ handleClientDisconnecting(disconnectingClientIdentity: OpenFin.ClientIdentity): Promise<void>;
38
50
  registerNewClient(clientIdentity: OpenFin.ClientIdentity): void;
51
+ getConnectedClients(): Promise<PrivateChannelClientState[]>;
52
+ static init(channelProvider: OpenFin.ChannelProvider, id: string): PrivateChannelProvider;
39
53
  }
40
54
  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;
@@ -169,11 +169,15 @@ class Fdc3Module extends base_1.Base {
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
  /**
@@ -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.
@@ -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,6 +282,7 @@ 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
287
  getCurrentChannel(): Promise<FDC3v2.Channel | null>;
287
288
  /**
@@ -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
  }
@@ -6,7 +6,6 @@ const InteropClient_1 = require("../InteropClient");
6
6
  const utils_2 = require("./utils");
7
7
  const fdc3_1_2_1 = require("./fdc3-1.2");
8
8
  const PrivateChannelClient_1 = require("./PrivateChannelClient");
9
- const PrivateChannelProvider_1 = require("./PrivateChannelProvider");
10
9
  /**
11
10
  * @typedef { object } AppIdentifier
12
11
  * @summary Identifies an application, or instance of an application, and is used to target FDC3 API calls at specific applications.
@@ -181,7 +180,7 @@ class Fdc3Module2 extends base_1.Base {
181
180
  * Find all the available instances for a particular application.
182
181
  * @param { AppIdentifier } app
183
182
  * @returns { Promise<Array<AppIdentifier>> }
184
- * @tutorial findInstances
183
+ * @tutorial fdc3v2.findInstances
185
184
  */
186
185
  async findInstances(app) {
187
186
  this.wire.sendAction('fdc3-find-instances').catch((e) => {
@@ -199,7 +198,7 @@ class Fdc3Module2 extends base_1.Base {
199
198
  * 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.
200
199
  * @param { AppIdentifier } app
201
200
  * @returns { Promise<AppMetadata(2)> }
202
- * @tutorial getAppMetadata
201
+ * @tutorial fdc3v2.getAppMetadata
203
202
  */
204
203
  async getAppMetadata(app) {
205
204
  this.wire.sendAction('fdc3-get-app-metadata').catch((e) => {
@@ -277,7 +276,7 @@ class Fdc3Module2 extends base_1.Base {
277
276
  * @param { Context } context
278
277
  * @param { string } [resultType] The type of result returned for any intent specified during resolution.
279
278
  * @returns { Promise<Array<AppIntent(2)>> }
280
- * @tutorial findIntentsByContext
279
+ * @tutorial fdc3v2.findIntentsByContext
281
280
  */
282
281
  async findIntentsByContext(context, resultType) {
283
282
  this.wire.sendAction('fdc3-find-intents-by-context').catch((e) => {
@@ -298,7 +297,7 @@ class Fdc3Module2 extends base_1.Base {
298
297
  * @param { Context } context Context associated with the Intent
299
298
  * @param { AppIdentifier | TargetApp } [app]
300
299
  * @returns { Promise<IntentResolution(2)> }
301
- * @tutorial raiseIntent
300
+ * @tutorial fdc3v2.raiseIntent
302
301
  */
303
302
  async raiseIntent(intent, context, app) {
304
303
  this.wire.sendAction('fdc3-raise-intent').catch((e) => {
@@ -317,7 +316,7 @@ class Fdc3Module2 extends base_1.Base {
317
316
  * @param { Context } context Context associated with the Intent
318
317
  * @param { AppIdentifier | TargetApp } [app]
319
318
  * @returns { Promise<IntentResolution(2)> }
320
- * @tutorial raiseIntentForContext
319
+ * @tutorial fdc3v2.raiseIntentForContext
321
320
  */
322
321
  async raiseIntentForContext(context, app) {
323
322
  // TODO: We have to do the same thing we do for raiseIntent here as well.
@@ -349,27 +348,27 @@ class Fdc3Module2 extends base_1.Base {
349
348
  // The FDC3 Intenter handler only expects the context and contextMetadata to be passed to the handler,
350
349
  // so we wrap it here and only pass those paramaters.
351
350
  const contextHandler = async (raisedIntent) => {
351
+ let intentResult;
352
+ let intentResultToSend;
352
353
  const { context, metadata: intentMetadata } = raisedIntent;
353
354
  const { contextMetadata, metadata, ...rest } = context;
354
- let intentResult;
355
+ const intentResolutionResultId = (intentMetadata === null || intentMetadata === void 0 ? void 0 : intentMetadata.intentResolutionResultId) || (metadata === null || metadata === void 0 ? void 0 : metadata.intentResolutionResultId);
355
356
  try {
356
357
  const newContext = metadata ? { metadata, ...rest } : { ...rest };
357
358
  intentResult = await handler(newContext, contextMetadata);
359
+ intentResultToSend = intentResult;
358
360
  }
359
361
  catch (error) {
360
362
  intentResult = error;
363
+ intentResultToSend = { error: true };
361
364
  }
362
- const intentResolutionResultId = (intentMetadata === null || intentMetadata === void 0 ? void 0 : intentMetadata.intentResolutionResultId) || (metadata === null || metadata === void 0 ? void 0 : metadata.intentResolutionResultId);
363
365
  if (intentResolutionResultId) {
364
- // Send whatever the result is.
365
- fin.InterApplicationBus.publish(intentResolutionResultId, intentResult);
366
+ this.fin.InterApplicationBus.publish(intentResolutionResultId, intentResultToSend);
366
367
  }
367
368
  if (intentResult instanceof Error) {
368
369
  throw new Error(intentResult.message);
369
370
  }
370
- else {
371
- return intentResult;
372
- }
371
+ return intentResult;
373
372
  };
374
373
  return this.fin.me.interop.registerIntentHandler(contextHandler, intent, { fdc3Version: '2.0' });
375
374
  }
@@ -385,12 +384,11 @@ class Fdc3Module2 extends base_1.Base {
385
384
  /**
386
385
  * 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.
387
386
  * @returns { Promise<PrivateChannel> }
388
- * @tutorial createPrivateChannel
387
+ * @tutorial fdc3v2.createPrivateChannel
389
388
  */
390
389
  async createPrivateChannel() {
391
390
  const channelId = (0, utils_1.generateId)();
392
- const channelProvider = await this.fin.InterApplicationBus.Channel.create(channelId);
393
- const newPrivateChannelProvider = new PrivateChannelProvider_1.PrivateChannelProvider(channelProvider, channelId);
391
+ await InteropClient_1.InteropClient.ferryFdc3Call(this.fin.me.interop, 'createPrivateChannelProvider', { channelId });
394
392
  const channelClient = await this.fin.InterApplicationBus.Channel.connect(channelId);
395
393
  const newPrivateChannelClient = new PrivateChannelClient_1.PrivateChannelClient(channelClient, channelId);
396
394
  return (0, utils_2.buildPrivateChannelObject)(newPrivateChannelClient);
@@ -398,7 +396,7 @@ class Fdc3Module2 extends base_1.Base {
398
396
  /**
399
397
  * Retrieves a list of the User Channels available for the app to join.
400
398
  * @returns { Promise<Channel[]>}
401
- * @tutorial getUserChannels
399
+ * @tutorial fdc3v2.getUserChannels
402
400
  */
403
401
  async getUserChannels() {
404
402
  const channels = await this.fin.me.interop.getContextGroups();
@@ -422,7 +420,7 @@ class Fdc3Module2 extends base_1.Base {
422
420
  * Join an app to a specified User channel.
423
421
  * @param { string } channelId Channel name
424
422
  * @returns { Promise<void> }
425
- * @tutorial joinUserChannel
423
+ * @tutorial fdc3v2.joinUserChannel
426
424
  */
427
425
  async joinUserChannel(channelId) {
428
426
  return this.fdc3Module.joinChannel(channelId);
@@ -441,6 +439,7 @@ class Fdc3Module2 extends base_1.Base {
441
439
  /**
442
440
  * Returns the Channel object for the current User channel membership
443
441
  * @returns { Promise<FDC3.Channel | null> }
442
+ * @tutorial fdc3.getCurrentChannel
444
443
  */
445
444
  async getCurrentChannel() {
446
445
  const currentChannel = await this.fdc3Module.getCurrentChannel();
@@ -465,7 +464,7 @@ class Fdc3Module2 extends base_1.Base {
465
464
  * 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.
466
465
  * fdc3HandleGetInfo must be overridden in the InteropBroker so that the ImplementationMetadata will have the appMetadata info.
467
466
  * @returns { Promise<ImplementationMetadata(2)> }
468
- * @tutorial getInfo
467
+ * @tutorial fdc3v2.getInfo
469
468
  */
470
469
  async getInfo() {
471
470
  return InteropClient_1.InteropClient.ferryFdc3Call(fin.me.interop, 'fdc3v2GetInfo', { fdc3Version: '2.0' });
@@ -63,7 +63,7 @@ export interface DesktopAgent {
63
63
  addContextListener(contextType: string | null, handler: ContextHandler): Promise<Listener>;
64
64
  getUserChannels(): Promise<Array<SystemChannel>>;
65
65
  joinUserChannel(channelId: string): Promise<void>;
66
- getOrCreateChannel(channelId: string): Promise<ChannelV1>;
66
+ getOrCreateChannel(channelId: string): Promise<Channel>;
67
67
  createPrivateChannel(): Promise<PrivateChannel>;
68
68
  getCurrentChannel(): Promise<ChannelV1 | null>;
69
69
  leaveCurrentChannel(): Promise<void>;
@@ -20,8 +20,25 @@ export declare enum ResultError {
20
20
  */
21
21
  IntentHandlerRejected = "IntentHandlerRejected"
22
22
  }
23
+ export declare enum ChannelError {
24
+ /** Returned if the specified channel is not found when attempting to join a
25
+ * channel via the `joinUserChannel` function of the DesktopAgent (`fdc3`).
26
+ */
27
+ NoChannelFound = "NoChannelFound",
28
+ /** SHOULD be returned when a request to join a user channel or to a retrieve
29
+ * a Channel object via the `joinUserChannel` or `getOrCreateChannel` methods
30
+ * of the DesktopAgent (`fdc3`) object is denied.
31
+ */
32
+ AccessDenied = "AccessDenied",
33
+ /** SHOULD be returned when a channel cannot be created or retrieved via the
34
+ * `getOrCreateChannel` method of the DesktopAgent (`fdc3`).
35
+ */
36
+ CreationFailed = "CreationFailed"
37
+ }
23
38
  export declare const buildPrivateChannelObject: (privateChannelClient: PrivateChannelClient) => PrivateChannel;
24
39
  export declare const buildAppChannelObject: (sessionContextGroup: OpenFin.SessionContextGroup) => Channel;
25
40
  export declare const connectPrivateChannel: (channelId: string) => Promise<PrivateChannel>;
41
+ export declare const isContext: (context: unknown) => context is Context;
42
+ export declare const isChannel: (channel: unknown) => channel is Channel;
26
43
  export declare const getIntentResolution: (interopModule: OpenFin.InteropClient, context: Context, app?: AppIdentifier | TargetApp, intent?: string) => Promise<IntentResolution>;
27
44
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getIntentResolution = exports.connectPrivateChannel = exports.buildAppChannelObject = exports.buildPrivateChannelObject = exports.ResultError = exports.UnsupportedChannelApiError = exports.getUnsupportedChannelApis = void 0;
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
6
  const getUnsupportedChannelApis = (channelType) => {
@@ -35,6 +35,22 @@ var ResultError;
35
35
  */
36
36
  ResultError["IntentHandlerRejected"] = "IntentHandlerRejected";
37
37
  })(ResultError = exports.ResultError || (exports.ResultError = {}));
38
+ var ChannelError;
39
+ (function (ChannelError) {
40
+ /** Returned if the specified channel is not found when attempting to join a
41
+ * channel via the `joinUserChannel` function of the DesktopAgent (`fdc3`).
42
+ */
43
+ ChannelError["NoChannelFound"] = "NoChannelFound";
44
+ /** SHOULD be returned when a request to join a user channel or to a retrieve
45
+ * a Channel object via the `joinUserChannel` or `getOrCreateChannel` methods
46
+ * of the DesktopAgent (`fdc3`) object is denied.
47
+ */
48
+ ChannelError["AccessDenied"] = "AccessDenied";
49
+ /** SHOULD be returned when a channel cannot be created or retrieved via the
50
+ * `getOrCreateChannel` method of the DesktopAgent (`fdc3`).
51
+ */
52
+ ChannelError["CreationFailed"] = "CreationFailed";
53
+ })(ChannelError = exports.ChannelError || (exports.ChannelError = {}));
38
54
  const buildPrivateChannelObject = (privateChannelClient) => {
39
55
  let clientDisconnected = false;
40
56
  const checkIfClientDisconnected = () => {
@@ -122,6 +138,22 @@ const connectPrivateChannel = async (channelId) => {
122
138
  }
123
139
  };
124
140
  exports.connectPrivateChannel = connectPrivateChannel;
141
+ const isContext = (context) => {
142
+ if (context && typeof context === 'object' && 'type' in context) {
143
+ const { type } = context;
144
+ return typeof type === 'string';
145
+ }
146
+ return false;
147
+ };
148
+ exports.isContext = isContext;
149
+ const isChannel = (channel) => {
150
+ if (channel && typeof channel === 'object' && 'type' in channel && 'id' in channel) {
151
+ const { type, id } = channel;
152
+ return typeof type === 'string' && typeof id === 'string' && (type === 'app' || type === 'private');
153
+ }
154
+ return false;
155
+ };
156
+ exports.isChannel = isChannel;
125
157
  const getIntentResolution = async (interopModule, context, app, intent) => {
126
158
  // Generate an ID to make a session context group with. We will pass that ID to the Broker.
127
159
  // The broker will then setContext on that session context group later with our Intent Result,
@@ -138,31 +170,33 @@ const getIntentResolution = async (interopModule, context, app, intent) => {
138
170
  // Set up the getResult call.
139
171
  const getResult = async () => {
140
172
  let intentResult = await getResultPromise;
141
- if (!intentResult) {
173
+ if (!intentResult || typeof intentResult !== 'object') {
142
174
  throw new Error(ResultError.NoResultReturned);
143
175
  }
144
- if (intentResult instanceof Error) {
176
+ const { error } = intentResult;
177
+ if (error) {
145
178
  throw new Error(ResultError.IntentHandlerRejected);
146
179
  }
147
- if (typeof intentResult === 'object') {
180
+ if ((0, exports.isChannel)(intentResult)) {
148
181
  const { id, type } = intentResult;
149
- if (type && id && typeof id === 'string') {
150
- switch (type) {
151
- case 'private': {
152
- intentResult = await (0, exports.connectPrivateChannel)(id);
153
- break;
154
- }
155
- case 'app': {
156
- const sessionContextGroup = await interopModule.joinSessionContextGroup(id);
157
- intentResult = (0, exports.buildAppChannelObject)(sessionContextGroup);
158
- break;
159
- }
160
- default: {
161
- break;
162
- }
182
+ switch (type) {
183
+ case 'private': {
184
+ intentResult = await (0, exports.connectPrivateChannel)(id);
185
+ break;
186
+ }
187
+ case 'app': {
188
+ const sessionContextGroup = await interopModule.joinSessionContextGroup(id);
189
+ intentResult = (0, exports.buildAppChannelObject)(sessionContextGroup);
190
+ break;
191
+ }
192
+ default: {
193
+ break;
163
194
  }
164
195
  }
165
196
  }
197
+ else if (!(0, exports.isContext)(intentResult)) {
198
+ throw new Error(ResultError.NoResultReturned);
199
+ }
166
200
  return intentResult;
167
201
  };
168
202
  // Finally fire the intent.
@@ -54,6 +54,11 @@ import UpdatableViewOptions = OpenFin.UpdatableViewOptions;
54
54
  * @property {boolean} [api.iframe.crossOriginInjection=false] Controls if the `fin` API object is present for cross origin iframes.
55
55
  * @property {boolean} [api.iframe.sameOriginInjection=true] Controls if the `fin` API object is present for same origin iframes.
56
56
  *
57
+ * @property {string} [autoplayPolicy="no-user-gesture-required"]
58
+ * Autoplay policy to apply to content in the window, can be
59
+ * `no-user-gesture-required`, `user-gesture-required`,
60
+ * `document-user-activation-required`. Defaults to `no-user-gesture-required`.
61
+ *
57
62
  * @property {object} [autoResize] AutoResize options
58
63
  *
59
64
  * @property {object} [bounds] initial bounds given relative to the window.
@@ -455,6 +460,10 @@ export declare class View extends WebContents<ViewEvents> {
455
460
  * **NOTE**: Internal use only.
456
461
  * Attaches this view to an HTML element in the current context. The view will resize responsively when the element bounds change.
457
462
  *
463
+ * **Known issue**: View.bindToElement does not track position changes, if the element has fixed px width and height values it is possible for the view to not update responsively.
464
+ *
465
+ * **Known issue**: When View.bindToElement is used on a element that takes up the entire page in a platform window, the bound view will not respond responsively when the window is resized to be smaller.
466
+ *
458
467
  * @param {HTMLElement} element - HTML element to attach the view to.
459
468
  * @return {Function} - Cleanup function that will disconnect the element resize observer.
460
469
  * @internal
@@ -58,6 +58,11 @@ const bounds_observer_1 = require("../platform/layout/utils/bounds-observer");
58
58
  * @property {boolean} [api.iframe.crossOriginInjection=false] Controls if the `fin` API object is present for cross origin iframes.
59
59
  * @property {boolean} [api.iframe.sameOriginInjection=true] Controls if the `fin` API object is present for same origin iframes.
60
60
  *
61
+ * @property {string} [autoplayPolicy="no-user-gesture-required"]
62
+ * Autoplay policy to apply to content in the window, can be
63
+ * `no-user-gesture-required`, `user-gesture-required`,
64
+ * `document-user-activation-required`. Defaults to `no-user-gesture-required`.
65
+ *
61
66
  * @property {object} [autoResize] AutoResize options
62
67
  *
63
68
  * @property {object} [bounds] initial bounds given relative to the window.
@@ -460,6 +465,10 @@ class View extends main_1.WebContents {
460
465
  * **NOTE**: Internal use only.
461
466
  * Attaches this view to an HTML element in the current context. The view will resize responsively when the element bounds change.
462
467
  *
468
+ * **Known issue**: View.bindToElement does not track position changes, if the element has fixed px width and height values it is possible for the view to not update responsively.
469
+ *
470
+ * **Known issue**: When View.bindToElement is used on a element that takes up the entire page in a platform window, the bound view will not respond responsively when the window is resized to be smaller.
471
+ *
463
472
  * @param {HTMLElement} element - HTML element to attach the view to.
464
473
  * @return {Function} - Cleanup function that will disconnect the element resize observer.
465
474
  * @internal
@@ -127,6 +127,11 @@ import WindowEvents = OpenFin.WindowEvents;
127
127
  * The aspect ratio of width to height to enforce for the window. If this value is equal to or less than zero,
128
128
  * an aspect ratio will not be enforced.
129
129
  *
130
+ * @property {string} [autoplayPolicy="no-user-gesture-required"]
131
+ * Autoplay policy to apply to content in the window, can be
132
+ * `no-user-gesture-required`, `user-gesture-required`,
133
+ * `document-user-activation-required`. Defaults to `no-user-gesture-required`.
134
+ *
130
135
  * @property {boolean} [autoShow=true]
131
136
  * A flag to automatically show the window when it is created.
132
137
  *
@@ -134,6 +134,11 @@ const view_1 = require("../view");
134
134
  * The aspect ratio of width to height to enforce for the window. If this value is equal to or less than zero,
135
135
  * an aspect ratio will not be enforced.
136
136
  *
137
+ * @property {string} [autoplayPolicy="no-user-gesture-required"]
138
+ * Autoplay policy to apply to content in the window, can be
139
+ * `no-user-gesture-required`, `user-gesture-required`,
140
+ * `document-user-activation-required`. Defaults to `no-user-gesture-required`.
141
+ *
137
142
  * @property {boolean} [autoShow=true]
138
143
  * A flag to automatically show the window when it is created.
139
144
  *