@openfin/core 29.72.12 → 29.72.14

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.
@@ -1,19 +1,171 @@
1
1
  "use strict";
2
- // THIS IS NOT PRODUCTION-READY. Until we implement the missing features: getResult, Private Channels and Instance Management we should not document this.
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  const base_1 = require("../../base");
5
4
  const utils_1 = require("../utils");
6
5
  const InteropClient_1 = require("../InteropClient");
7
6
  const fdc3_1_2_1 = require("./fdc3-1.2");
7
+ /**
8
+ * @typedef { object } AppIdentifier
9
+ * @summary Identifies an application, or instance of an application, and is used to target FDC3 API calls at specific applications.
10
+ * @property { string } appId The unique application identifier located within a specific application directory instance. An example of an appId might be 'app@sub.root'.
11
+ * @property { string } [instancedId] An optional instance identifier, indicating that this object represents a specific instance of the application described. The endpointId should be used as the instanceId. The most convenient way to get this would be to use the InteropBroker.getAllClientInfo API.
12
+ */
13
+ /**
14
+ * @typedef { Context | Channel } IntentResult
15
+ * @summary Describes results that an Intent handler may optionally return that should be communicated back to the app that raised the intent, via the IntentResolution.
16
+ */
17
+ /**
18
+ * @typedef { object } Icon
19
+ * @summary Metadata relating to a single icon image at a remote URL, used to represent an application in a user interface.
20
+ * @property { string } src The fully qualified url to the icon.
21
+ * @property { string } [size] The dimensions of the Icon formatted as <height>x<width>.
22
+ * @property { string } [type] The media type of the icon. If not provided the Desktop Agent may refer to the src file extension.
23
+ */
24
+ /**
25
+ * @typedef { object } Image
26
+ * @summary Metadata relating to a single image at a remote URL, used to represent screenshot images.
27
+ * @property { string } src The fully qualified url to the image.
28
+ * @property { string } [size] The dimensions of the image formatted as <height>x<width>.
29
+ * @property { string } [type] The media type of the image. If not provided the Desktop Agent may refer to the src file extension.
30
+ * @property { string } [label]
31
+ */
32
+ /**
33
+ * @typedef { object } AppMetadata
34
+ * @variation 2
35
+ * @summary Extends an AppIdentifier, describing an application or instance of an application, with additional descriptive metadata that is usually provided by an FDC3 App Directory that the desktop agent connects to.
36
+ * @property { string } appId The unique application identifier located within a specific application directory instance. An example of an appId might be 'app@sub.root'.
37
+ * @property { string } [instanceId] An optional instance identifier, indicating that this object represents a specific instance of the application described. The endpointId should be used as the instanceId. The most convenient way to get this would be to use the InteropBroker.getAllClientInfo API.
38
+ * @property { string } [name] The 'friendly' app name. This field was used with the `open` and `raiseIntent` calls in FDC3 <2.0, which now require an `AppIdentifier` with `appId` set. Note that for display purposes the `title` field should be used, if set, in preference to this field.
39
+ * @property { string } [version] The version of the application.
40
+ * @property { Record<string, any> } [instanceMetadata]
41
+ * @property { string } [title] A more user-friendly application title that can be used to render UI elements.
42
+ * @property { string } [tooltip] A tooltip for the application that can be used to render UI elements.
43
+ * @property { string } [description] A longer, multi-paragraph description for the application that could include mark-up.
44
+ * @property { Array<Icon> } [icons] A list of icon URLs for the application that can be used to render UI elements.
45
+ * @property { Array<Image> } [screenshots] Images representing the app in common usage scenarios that can be used to render UI elements.
46
+ * @property { string | null } [resultType] The type of result returned for any intent specified during resolution. May express a particular context type (e.g. "fdc3.instrument"), channel (e.g. "channel") or a channel that will receive a specified type (e.g. "channel<fdc3.instrument>").
47
+ */
48
+ /**
49
+ * @typedef { object } ContextMetadata
50
+ * @summary Metadata relating to a context or intent & context received through the addContextListener and addIntentListener functions. Currently identifies the app that originated the context or intent message.
51
+ * @property { AppIdentifier } source Identifier for the app instance that sent the context and/or intent.
52
+ */
53
+ /**
54
+ * @typedef { object } ImplementationMetadataOptionalFeatures
55
+ * @property { boolean } originatingAppMetadata Used to indicate whether the exposure of 'originating app metadata' for context and intent messages is supported by the Desktop Agent.
56
+ * @property { boolean } userChannelMembershipAPIs Used to indicate whether the optional `fdc3.joinUserChannel`, `fdc3.getCurrentChannel` and `fdc3.leaveCurrentChannel` are implemented by the Desktop Agent.
57
+ */
58
+ /**
59
+ * @typedef { object } ImplementationMetadata
60
+ * @variation 2
61
+ * @summary Metadata relating to the FDC3 DesktopAgent object and its provider, including the supported version of the FDC3 specification, the name of the provider of the implementation, its own version number and the metadata of the calling application according to the desktop agent.
62
+ * @property { string } fdc3Version The FDC3 version
63
+ * @property { string } provider The provider's uuid prepended with 'openfin' (e.g. 'openfin-myUuid').
64
+ * @property { string } [providerVersion] The provider runtime version
65
+ * @property { ImplementationMetadataOptionalFeatures } optionalFeatures
66
+ * @property { AppMetadata } appMetadata The calling application instance's own metadata, according to the Desktop Agent (MUST include at least the `appId` and `instanceId`).
67
+ */
68
+ /**
69
+ * @callback ContextHandler
70
+ * @variation 2
71
+ * @param { Context } context
72
+ * @param { ContextMetadata } [contextMetadata]
73
+ * @returns { void }
74
+ */
75
+ /**
76
+ * @callback IntentHandler
77
+ * @variation 2
78
+ * @param { Context } context
79
+ * @param { ContextMetadata } [contextMetadata]
80
+ * @returns { Promise<IntentResult> | void }
81
+ */
82
+ /**
83
+ * @typedef { object } IntentMetadata
84
+ * @summary The interface used to describe an intent within the platform.
85
+ * @property { string } name The unique name of the intent that can be invoked by the raiseIntent call.
86
+ * @property { string } displayName A friendly display name for the intent that should be used to render UI elements.
87
+ */
88
+ /**
89
+ * @typedef { object } AppIntent
90
+ * @variation 2
91
+ * @summary An interface that represents the binding of an intent to apps, returned as part of intent discovery. For each intent, it references the applications that support that intent.
92
+ * @property { IntentMetadata } intent Details of the intent whose relationship to resolving applications is being described
93
+ * @property { Array<AppMetadata> } apps
94
+ */
95
+ /**
96
+ * @name getResult
97
+ * @function
98
+ * @returns { Promise<IntentResult> }
99
+ */
100
+ /**
101
+ * @typedef { object } IntentResolution
102
+ * @variation 2
103
+ * @summary Provides a standard format for data returned upon resolving an intent.
104
+ * @property { AppIdentifier } source Identifier for the app instance that was selected (or started) to resolve the intent.
105
+ * @property { string } Intent Intent name
106
+ * @property { string } [version] The version number of the Intents schema being used.
107
+ * @property { Function } getResult {@link getResult Function} that returns a promise that will resolve to either `Context` data returned by the application that resolves the raised intent or a `Channel` established and returned by the app resolving the intent.
108
+ */
109
+ /**
110
+ * @class
111
+ * @alias fdc3v2
112
+ * @version 2.0
113
+ * @hideconstructor
114
+ * @desc The FDC3 Client Library provides a set APIs to be used for FDC3 compliance,
115
+ * while using our Interop API under the hood. In order to use this set of APIs
116
+ * you will need to set up your own {@link InteropBroker InteropBroker} or use a Platform application, which does the setup for you. Refer to our documentation on
117
+ * our {@link https://developers.openfin.co/of-docs/docs/enable-context-sharing Interop API}.
118
+ *
119
+ * To enable the FDC3 APIs in a {@link Window Window} or {@link View View}, add the fdc3InteropApi
120
+ * property to its options:
121
+ *
122
+ * ```js
123
+ * {
124
+ * autoShow: false,
125
+ * saveWindowState: true,
126
+ * url: 'https://openfin.co',
127
+ * fdc3InteropApi: '2.0'
128
+ * }
129
+ * ```
130
+ *
131
+ * If using a {@link Platform Platform } application, you can set this property in defaultWindowOptions and defaultViewOptions.
132
+ *
133
+ * In order to ensure that the FDC3 Api is ready before use, you can use the 'fdc3Ready' event fired on the DOM Window object:
134
+ *
135
+ * ```js
136
+ * function fdc3Action() {
137
+ * // Make some fdc3 API calls here
138
+ * }
139
+ *
140
+ * if (window.fdc3) {
141
+ * fdc3Action();
142
+ * } else {
143
+ * window.addEventListener('fdc3Ready', fdc3Action);
144
+ * }
145
+ * ```
146
+ */
8
147
  class Fdc3Module2 extends base_1.Base {
9
148
  constructor(wire) {
10
149
  super(wire);
11
150
  // we get the module for fdc 1.2 here so we can reuse it wherever we can
12
151
  this.fdc3Module = new fdc3_1_2_1.default(this.wire);
13
152
  }
153
+ /**
154
+ * Launches an app, specified via an AppIdentifier object.
155
+ * @param { AppIdentifier | TargetApp } app
156
+ * @param { Context } [context]
157
+ * @returns { Promise<AppIdentifier> }
158
+ * @tutorial fdc3.open
159
+ */
14
160
  async open(app, context) {
15
161
  return this.fdc3Module.open(app, context);
16
162
  }
163
+ /**
164
+ * Find all the available instances for a particular application.
165
+ * @param { AppIdentifier } app
166
+ * @returns { Promise<Array<AppIdentifier>> }
167
+ * @tutorial fdc3v2.findInstances
168
+ */
17
169
  async findInstances(app) {
18
170
  this.wire.sendAction('fdc3-find-instances').catch((e) => {
19
171
  // we do not want to expose this error, just continue if this analytics-only call fails
@@ -26,6 +178,12 @@ class Fdc3Module2 extends base_1.Base {
26
178
  throw new Error(errorToThrow);
27
179
  }
28
180
  }
181
+ /**
182
+ * 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.
183
+ * @param { AppIdentifier } app
184
+ * @returns { Promise<AppMetadata(2)> }
185
+ * @tutorial fdc3v2.getAppMetadata
186
+ */
29
187
  async getAppMetadata(app) {
30
188
  this.wire.sendAction('fdc3-get-app-metadata').catch((e) => {
31
189
  // we do not want to expose this error, just continue if this analytics-only call fails
@@ -38,23 +196,53 @@ class Fdc3Module2 extends base_1.Base {
38
196
  throw new Error(errorToThrow);
39
197
  }
40
198
  }
199
+ /**
200
+ * Broadcasts a context for the channel of the current entity.
201
+ * @param { Context } context - New context to set.
202
+ * @returns { Promise<void> }
203
+ * @tutorial fdc3.broadcast
204
+ */
41
205
  async broadcast(context) {
42
206
  return this.fdc3Module.broadcast(context);
43
207
  }
208
+ /**
209
+ * Add a context handler for incoming context. If an entity is part of a context group, and then sets its context handler, it will receive all of its declared contexts. If you wish to listen for all incoming contexts, pass `null` for the contextType argument.
210
+ * @param { string | null } contextType
211
+ * @param { ContextHandler(2) } handler
212
+ * @returns { Listener }
213
+ * @tutorial fdc3.addContextListener
214
+ */
44
215
  async addContextListener(contextType, handler) {
45
216
  this.wire.sendAction('fdc3-add-context-listener').catch((e) => {
46
217
  // we do not want to expose this error, just continue if this analytics-only call fails
47
218
  });
48
- let listener;
219
+ // The FDC3 ContextHandler only expects the context and optional ContextMetadata, so we wrap the handler
220
+ // here so it only gets passed these parameters
221
+ const getWrappedHandler = (handlerToWrap) => {
222
+ return (context) => {
223
+ const { contextMetadata, ...rest } = context;
224
+ const args = contextMetadata ? [{ ...rest }, contextMetadata] : [context, null];
225
+ handlerToWrap(...args);
226
+ };
227
+ };
228
+ let actualHandler = handler;
229
+ let wrappedHandler = getWrappedHandler(actualHandler);
49
230
  if (typeof contextType === 'function') {
50
231
  console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
51
- listener = await this.fin.me.interop.addContextHandler(contextType);
52
- }
53
- else {
54
- listener = await this.fin.me.interop.addContextHandler(handler, contextType === null ? undefined : contextType);
232
+ actualHandler = contextType;
233
+ wrappedHandler = getWrappedHandler(actualHandler);
234
+ return this.fin.me.interop.addContextHandler(wrappedHandler);
55
235
  }
56
- return listener;
236
+ return this.fin.me.interop.addContextHandler(wrappedHandler, contextType === null ? undefined : contextType);
57
237
  }
238
+ /**
239
+ * Find out more information about a particular intent by passing its name, and optionally its context and resultType.
240
+ * @param { string } intent Name of the Intent
241
+ * @param { Context } [context] Context
242
+ * @param { string } [resultType] The type of result returned for any intent specified during resolution.
243
+ * @returns { Promise<AppIntent(2)> }
244
+ * @tutorial fdc3.findIntent
245
+ */
58
246
  async findIntent(intent, context, resultType) {
59
247
  this.wire.sendAction('fdc3-find-intent').catch((e) => {
60
248
  // we do not want to expose this error, just continue if this analytics-only call fails
@@ -67,36 +255,74 @@ class Fdc3Module2 extends base_1.Base {
67
255
  throw new Error(errorToThrow);
68
256
  }
69
257
  }
258
+ /**
259
+ * Find all the available intents for a particular context.
260
+ * @param { Context } context
261
+ * @param { string } [resultType] The type of result returned for any intent specified during resolution.
262
+ * @returns { Promise<Array<AppIntent(2)>> }
263
+ * @tutorial fdc3v2.findIntentsByContext
264
+ */
70
265
  async findIntentsByContext(context, resultType) {
71
266
  this.wire.sendAction('fdc3-find-intents-by-context').catch((e) => {
72
267
  // we do not want to expose this error, just continue if this analytics-only call fails
73
268
  });
269
+ const payload = resultType ? { context, metadata: { resultType } } : context;
74
270
  try {
75
- return await InteropClient_1.InteropClient.ferryFdc3Call(fin.me.interop, 'fdc3v2FindIntentsByContext', {
76
- context,
77
- resultType
78
- });
271
+ return await InteropClient_1.InteropClient.ferryFdc3Call(fin.me.interop, 'fdc3v2FindIntentsByContext', payload);
79
272
  }
80
273
  catch (error) {
81
274
  const errorToThrow = error.message === utils_1.BROKER_ERRORS.getInfoForIntentsByContext ? 'ResolverUnavailable' : error;
82
275
  throw new Error(errorToThrow);
83
276
  }
84
277
  }
278
+ /**
279
+ * Raises a specific intent for resolution against apps registered with the desktop agent.
280
+ * @param { string } intent Name of the Intent
281
+ * @param { Context } context Context associated with the Intent
282
+ * @param { AppIdentifier | TargetApp } [app]
283
+ * @returns { Promise<IntentResolution(2)> }
284
+ * @tutorial fdc3.raiseIntent
285
+ */
85
286
  async raiseIntent(intent, context, app) {
86
287
  return this.fdc3Module.raiseIntent(intent, context, app);
87
288
  }
289
+ /**
290
+ * Finds and raises an intent against apps registered with the desktop agent based purely on the type of the context data.
291
+ * @param { Context } context Context associated with the Intent
292
+ * @param { AppIdentifier | TargetApp } [app]
293
+ * @returns { Promise<IntentResolution(2)> }
294
+ * @tutorial fdc3.raiseIntentForContext
295
+ */
88
296
  async raiseIntentForContext(context, app) {
89
297
  return this.fdc3Module.raiseIntentForContext(context, app);
90
298
  }
299
+ /**
300
+ * Adds a listener for incoming intents.
301
+ * @param { string } intent Name of the Intent
302
+ * @param { IntentHandler(2) } handler A callback that handles a context event and may return a promise of a Context or Channel object to be returned to the application that raised the intent.
303
+ * @returns { Promise<Listener> }
304
+ * @tutorial fdc3.addIntentListener
305
+ */
91
306
  async addIntentListener(intent, handler) {
92
307
  this.wire.sendAction('fdc3-add-intent-listener').catch((e) => {
93
308
  // we do not want to expose this error, just continue if this analytics-only call fails
94
309
  });
310
+ // The FDC3 Intenter handler only expects the context and contextMetadata to be passed to the handler,
311
+ // so we wrap it here and only pass those paramaters.
95
312
  const contextHandler = (raisedIntent) => {
96
- handler(raisedIntent.context);
313
+ const { context } = raisedIntent;
314
+ const { contextMetadata, ...rest } = context;
315
+ const args = contextMetadata ? [{ ...rest }, contextMetadata] : [context, null];
316
+ handler(...args);
97
317
  };
98
318
  return this.fin.me.interop.registerIntentHandler(contextHandler, intent, { fdc3Version: '2.0' });
99
319
  }
320
+ /**
321
+ * Returns a Channel object for the specified channel, creating it as an App Channel if it does not exist.
322
+ * @param channelId
323
+ * @returns { Promise<Channel> }
324
+ * @tutorial fdc3.getOrCreateChannel
325
+ */
100
326
  async getOrCreateChannel(channelId) {
101
327
  return this.fdc3Module.getOrCreateChannel(channelId);
102
328
  }
@@ -104,23 +330,72 @@ class Fdc3Module2 extends base_1.Base {
104
330
  async createPrivateChannel() {
105
331
  // private channels will be implemented in another PR
106
332
  }
333
+ /**
334
+ * Retrieves a list of the User Channels available for the app to join.
335
+ * @returns { Promise<Channel[]>}
336
+ * @tutorial fdc3v2.getUserChannels
337
+ */
107
338
  async getUserChannels() {
108
339
  return this.fdc3Module.getSystemChannels();
109
340
  }
341
+ /**
342
+ * Retrieves a list of the User Channels available for the app to join.
343
+ * @returns { Promise<Channel[]>}
344
+ * @deprecated Please use {@link fdc3.getUserChannels fdc3.getUserChannels} instead
345
+ * @tutorial fdc3.getSystemChannels
346
+ */
110
347
  async getSystemChannels() {
111
348
  return this.fdc3Module.getSystemChannels();
112
349
  }
350
+ /**
351
+ * Join an app to a specified User channel.
352
+ * @param { string } channelId Channel name
353
+ * @returns { Promise<void> }
354
+ * @tutorial fdc3v2.joinUserChannel
355
+ */
113
356
  async joinUserChannel(channelId) {
114
357
  return this.fdc3Module.joinChannel(channelId);
115
358
  }
359
+ /**
360
+ * Join an app to a specified User channel.
361
+ * @param { string } channelId Channel name
362
+ * @deprecated Please use {@link fdc3.joinUserChannel fdc3.joinUserChannel} instead
363
+ * @returns { Promise<void> }
364
+ * @tutorial fdc3.joinChannel
365
+ */
366
+ async joinChannel(channelId) {
367
+ return this.fdc3Module.joinChannel(channelId);
368
+ }
369
+ /**
370
+ * Returns the Channel object for the current User channel membership
371
+ * @returns { Promise<FDC3.Channel | null> }
372
+ */
116
373
  async getCurrentChannel() {
117
374
  return this.fdc3Module.getCurrentChannel();
118
375
  }
376
+ /**
377
+ * Removes the app from any User channel membership.
378
+ * @returns { Promise<void> }
379
+ * @tutorial fdc3.leaveCurrentChannel
380
+ */
119
381
  async leaveCurrentChannel() {
120
- return this.leaveCurrentChannel();
382
+ return this.fdc3Module.leaveCurrentChannel();
121
383
  }
384
+ /**
385
+ * 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.
386
+ * @returns { Promise<ImplementationMetadata(2)> }
387
+ * @tutorial fdc3v2.getInfo
388
+ */
122
389
  async getInfo() {
123
- return this.fdc3Module.getInfo();
390
+ try {
391
+ const result = await InteropClient_1.InteropClient.ferryFdc3Call(fin.me.interop, 'fdc3v2GetInfo', {});
392
+ const partialInfo = this.fdc3Module.getInfo();
393
+ return { ...partialInfo, ...result };
394
+ }
395
+ catch (error) {
396
+ const errorToThrow = error.message === utils_1.BROKER_ERRORS.fdc3GetInfo ? 'ResolverUnavailable' : error;
397
+ throw new Error(errorToThrow);
398
+ }
124
399
  }
125
400
  }
126
401
  exports.default = Fdc3Module2;
@@ -1,12 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.registerFdc3Shim = exports.versionMap = void 0;
3
+ exports.getFdc3 = exports.registerFdc3Shim = exports.versionMap = void 0;
4
+ /* eslint-disable no-console */
5
+ /* eslint-disable no-param-reassign */
6
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
4
7
  const fdc3_1_2_1 = require("./fdc3-1.2");
5
8
  const fdc3_2_0_1 = require("./fdc3-2.0");
6
9
  exports.versionMap = {
7
10
  '1.2': fdc3_1_2_1.default,
8
11
  '2.0': fdc3_2_0_1.default
9
12
  };
13
+ const latestVersion = '2.0';
10
14
  function registerFdc3Shim(version, transport) {
11
15
  if (Object.keys(exports.versionMap).includes(version)) {
12
16
  const Api = exports.versionMap[version];
@@ -18,3 +22,14 @@ function registerFdc3Shim(version, transport) {
18
22
  }
19
23
  }
20
24
  exports.registerFdc3Shim = registerFdc3Shim;
25
+ function getFdc3(transport, version = latestVersion) {
26
+ if (!(version in exports.versionMap)) {
27
+ console.warn(`FDC3 API version: ${version} is not supported. Defaulting to latest version: ${latestVersion}.`);
28
+ version = latestVersion;
29
+ }
30
+ const Fdc3Api = exports.versionMap[version];
31
+ const fdc3 = new Fdc3Api(transport);
32
+ window.dispatchEvent(new CustomEvent('fdc3Ready'));
33
+ return fdc3;
34
+ }
35
+ exports.getFdc3 = getFdc3;
@@ -12,5 +12,6 @@ export declare const BROKER_ERRORS: {
12
12
  fdc3Open: string;
13
13
  fdc3FindInstances: string;
14
14
  fdc3GetAppMetadata: string;
15
+ fdc3GetInfo: string;
15
16
  };
16
17
  export declare const wrapIntentHandler: (handler: OpenFin.IntentHandler, handlerId: string) => (intent: OpenFin.Intent) => Promise<void>;
@@ -39,7 +39,8 @@ exports.BROKER_ERRORS = {
39
39
  joinSessionContextGroupWithJoinContextGroup: 'The Context Group you have tried to join is a Session Context Group. Custom Context Groups can only be defined by the Interop Broker through code or manifest configuration. Please use joinSessionContextGroup.',
40
40
  fdc3Open: exports.generateOverrideError('fdc3.open', 'fdc3HandleOpen'),
41
41
  fdc3FindInstances: exports.generateOverrideError('fdc3.findInstances', 'fdc3HandleFindInstances'),
42
- fdc3GetAppMetadata: exports.generateOverrideError('fdc3.getAppMetadata', 'fdc3HandleGetAppMetadata')
42
+ fdc3GetAppMetadata: exports.generateOverrideError('fdc3.getAppMetadata', 'fdc3HandleGetAppMetadata'),
43
+ fdc3GetInfo: exports.generateOverrideError('fdc3.getInfo', 'fdc3HandleGetInfo')
43
44
  };
44
45
  exports.wrapIntentHandler = (handler, handlerId) => {
45
46
  return async (intent) => {
package/src/api/me.js CHANGED
@@ -116,6 +116,11 @@ function getMe(wire) {
116
116
  interop: fallbackInterop,
117
117
  isOpenFin: true
118
118
  });
119
+ case 'external connection':
120
+ return Object.assign(new window_1._Window(wire, { uuid, name }), getBaseMe(entityType, uuid, name), {
121
+ interop: fallbackInterop,
122
+ isOpenFin: false
123
+ });
119
124
  default:
120
125
  return {
121
126
  ...getBaseMe(entityType, uuid, name),
@@ -0,0 +1,10 @@
1
+ import { FinApi } from './api/fin';
2
+ import { RemoteConfig } from './transport/wire';
3
+ interface GetRemoteConnectionPayload extends RemoteConfig {
4
+ interopProviderId: string;
5
+ withInterop: boolean;
6
+ }
7
+ export declare function getRemoteConnectionPayload(fin: FinApi<OpenFin.EntityType>, uuid?: string, interopProviderId?: string): Promise<GetRemoteConnectionPayload>;
8
+ export declare function remoteConnect({ uuid, token, address, interopProviderId, withInterop }: GetRemoteConnectionPayload): Promise<FinApi<'external connection'>>;
9
+ export declare function remoteConnectInterop(fin: FinApi<OpenFin.EntityType>, interopProviderId: string): Promise<FinApi<OpenFin.EntityType>>;
10
+ export {};
package/src/browser.js ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.remoteConnectInterop = exports.remoteConnect = exports.getRemoteConnectionPayload = void 0;
4
+ const fin_1 = require("./api/fin");
5
+ const browser_1 = require("./environment/browser");
6
+ const transport_1 = require("./transport/transport");
7
+ const websocket_1 = require("./transport/websocket");
8
+ async function getRemoteConnectionPayload(fin, uuid = `browser-connection-${Math.random().toString().slice(2)}`, interopProviderId = fin.me.uuid) {
9
+ var _a;
10
+ const { token } = await fin.System.registerExternalConnection(uuid);
11
+ const { port } = await fin.System.getRuntimeInfo();
12
+ const ip = '127.0.0.1';
13
+ const address = `ws://${ip}:${port}`;
14
+ // @ts-expect-error
15
+ return { uuid, token, address, interopProviderId, withInterop: ((_a = fin === null || fin === void 0 ? void 0 : fin.__internal_) === null || _a === void 0 ? void 0 : _a.isPlatform) || false };
16
+ }
17
+ exports.getRemoteConnectionPayload = getRemoteConnectionPayload;
18
+ async function remoteConnect({ uuid, token, address, interopProviderId, withInterop }) {
19
+ const wire = new transport_1.default(websocket_1.default, new browser_1.BrowserEnvironment(), {
20
+ uuid,
21
+ name: uuid
22
+ });
23
+ await wire.connect({ uuid, address, token });
24
+ if (withInterop) {
25
+ return remoteConnectInterop(new fin_1.default(wire), interopProviderId);
26
+ }
27
+ return new fin_1.default(wire);
28
+ }
29
+ exports.remoteConnect = remoteConnect;
30
+ async function remoteConnectInterop(fin, interopProviderId) {
31
+ if (interopProviderId) {
32
+ fin.me.interop = fin.Interop.connectSync(interopProviderId, {});
33
+ }
34
+ return fin;
35
+ }
36
+ exports.remoteConnectInterop = remoteConnectInterop;
@@ -0,0 +1,25 @@
1
+ import { NewConnectConfig } from '../transport/wire';
2
+ import { ChildContentOptions, Environment } from './environment';
3
+ import EntityType = OpenFin.EntityType;
4
+ export declare class BrowserEnvironment implements Environment {
5
+ getManagerConstructor(): Promise<any>;
6
+ getProviderInitializer(): Promise<any>;
7
+ writeToken(path: string, token: string): Promise<string>;
8
+ retrievePort(config: NewConnectConfig): Promise<number>;
9
+ getNextMessageId(): string;
10
+ getRandomId: () => string;
11
+ createChildContent(options: ChildContentOptions): Promise<any>;
12
+ getWebWindow(identity: OpenFin.Identity): Window;
13
+ getCurrentEntityIdentity(): OpenFin.EntityInfo;
14
+ getCurrentEntityType(): EntityType;
15
+ raiseEvent(eventName: string, eventArgs: any): void;
16
+ childViews: boolean;
17
+ getUrl(): string;
18
+ getDefaultChannelOptions(): {
19
+ create: OpenFin.ChannelCreateOptions;
20
+ connect: OpenFin.ChannelConnectOptions;
21
+ };
22
+ getRtcPeer(): RTCPeerConnection;
23
+ getWsConstructor(): typeof WebSocket;
24
+ whenReady(): Promise<void>;
25
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BrowserEnvironment = void 0;
4
+ class BrowserEnvironment {
5
+ constructor() {
6
+ this.getRandomId = () => {
7
+ const intArray = new Uint32Array(1);
8
+ return window.crypto.getRandomValues(intArray)[0].toString(32);
9
+ };
10
+ }
11
+ getManagerConstructor() {
12
+ throw new Error('Method not implemented.');
13
+ }
14
+ getProviderInitializer() {
15
+ throw new Error('Method not implemented.');
16
+ }
17
+ writeToken(path, token) {
18
+ return Promise.resolve('');
19
+ }
20
+ retrievePort(config) {
21
+ throw new Error('Method not implemented.');
22
+ }
23
+ getNextMessageId() {
24
+ return this.getRandomId();
25
+ }
26
+ createChildContent(options) {
27
+ throw new Error('Method not implemented.');
28
+ }
29
+ getWebWindow(identity) {
30
+ throw new Error('Method not implemented.');
31
+ }
32
+ getCurrentEntityIdentity() {
33
+ throw new Error('Method not implemented.');
34
+ }
35
+ getCurrentEntityType() {
36
+ return 'external connection';
37
+ }
38
+ raiseEvent(eventName, eventArgs) {
39
+ throw new Error('Method not implemented.');
40
+ }
41
+ getUrl() {
42
+ return location.href;
43
+ }
44
+ getDefaultChannelOptions() {
45
+ return { create: {}, connect: {} };
46
+ }
47
+ getRtcPeer() {
48
+ return new RTCPeerConnection();
49
+ }
50
+ getWsConstructor() {
51
+ return WebSocket;
52
+ }
53
+ whenReady() {
54
+ return Promise.resolve();
55
+ }
56
+ }
57
+ exports.BrowserEnvironment = BrowserEnvironment;
@@ -19,6 +19,7 @@ export interface Environment {
19
19
  connect: OpenFin.ChannelConnectOptions;
20
20
  };
21
21
  getRtcPeer(): RTCPeerConnection;
22
+ getWsConstructor(): typeof WebSocket;
22
23
  whenReady(): Promise<void>;
23
24
  }
24
25
  export interface ChildContentOptions {
@@ -22,4 +22,5 @@ export default class NodeEnvironment implements Environment {
22
22
  getCurrentEntityType: () => EntityType;
23
23
  raiseEvent: (eventName: string, eventArgs: any) => void;
24
24
  getUrl: () => string;
25
+ getWsConstructor(): typeof WebSocket;
25
26
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  /* eslint-disable class-methods-use-this */
4
4
  const fs_1 = require("fs");
5
5
  const crypto_1 = require("crypto");
6
+ const WS = require("ws");
6
7
  const environment_1 = require("./environment");
7
8
  const port_discovery_1 = require("../transport/port-discovery");
8
9
  const transport_errors_1 = require("../transport/transport-errors");
@@ -60,5 +61,9 @@ class NodeEnvironment {
60
61
  createChildContent(options) {
61
62
  throw new transport_errors_1.NotImplementedError('Not Implemented');
62
63
  }
64
+ getWsConstructor() {
65
+ // @ts-expect-error
66
+ return WS;
67
+ }
63
68
  }
64
69
  exports.default = NodeEnvironment;
@@ -1,7 +1,8 @@
1
1
  import { ChildContentOptions, Environment } from './environment';
2
2
  import { NewConnectConfig } from '../transport/wire';
3
+ import { BrowserEnvironment } from './browser';
3
4
  import EntityType = OpenFin.EntityType;
4
- export default class OpenFinEnvironment implements Environment {
5
+ export default class OpenFinEnvironment extends BrowserEnvironment implements Environment {
5
6
  #private;
6
7
  private raiseEventAsync;
7
8
  childViews: boolean;
@@ -10,7 +11,6 @@ export default class OpenFinEnvironment implements Environment {
10
11
  create: OpenFin.ChannelCreateOptions;
11
12
  connect: OpenFin.ChannelConnectOptions;
12
13
  };
13
- getRtcPeer(): RTCPeerConnection;
14
14
  getManagerConstructor(): Promise<any>;
15
15
  getProviderInitializer(): Promise<any>;
16
16
  writeToken: (path: string, token: string) => Promise<string>;
@@ -18,12 +18,10 @@ export default class OpenFinEnvironment implements Environment {
18
18
  getNextMessageId: () => any;
19
19
  createChildContent: ({ options, entityType }: ChildContentOptions) => Promise<unknown>;
20
20
  private normalizeOptions;
21
- getRandomId: () => string;
22
21
  private resolveUrl;
23
22
  getWebWindow: (identity: OpenFin.Identity) => globalThis.Window;
24
23
  getCurrentEntityIdentity: () => OpenFin.EntityInfo;
25
24
  getCurrentEntityType: () => EntityType;
26
25
  raiseEvent: (eventName: string, eventArgs: any) => void;
27
- getUrl: () => string;
28
26
  whenReady(): Promise<void>;
29
27
  }