@openfin/core 32.75.23 → 32.76.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfin/core",
3
- "version": "32.75.23",
3
+ "version": "32.76.1",
4
4
  "license": "SEE LICENSE IN LICENSE.MD",
5
5
  "main": "./src/mock.js",
6
6
  "types": "./src/mock.d.ts",
package/src/OpenFin.d.ts CHANGED
@@ -48,17 +48,18 @@ export type ClientIdentity = Identity & {
48
48
  */
49
49
  export type ClientInfo = Omit<ClientIdentity, 'isLocalEndpointId'> & {
50
50
  /**
51
- * Indicates if the client belongs to a Window or View
51
+ * Indicates if the client belongs to a Window, View or IFrame
52
52
  */
53
53
  entityType: EntityType;
54
54
  /**
55
- * URL of the View or Window at the time of connection to the Channel Provider.
55
+ * URL of the Window, View or IFrame at the time of connection to the Channel Provider.
56
56
  */
57
57
  connectionUrl: string;
58
58
  };
59
59
  export type ClientIdentityMultiRuntime = ClientIdentity & {
60
60
  runtimeUuid: string;
61
61
  };
62
+ export type ClientConnectionPayload = ClientIdentity & ClientInfo;
62
63
  export type EntityInfo = {
63
64
  uuid: string;
64
65
  name: string;
@@ -434,6 +435,11 @@ export type ViewVisibilityOptions = {
434
435
  * Visibility state of a window.
435
436
  */
436
437
  export type WindowState = 'maximized' | 'minimized' | 'normal';
438
+ /**
439
+ * Autoplay policy to apply to content in the window, can be
440
+ * `no-user-gesture-required`, `user-gesture-required`,
441
+ * `document-user-activation-required`. Defaults to `no-user-gesture-required`.
442
+ */
437
443
  export type AutoplayPolicyOptions = 'no-user-gesture-required' | 'user-gesture-required' | 'document-user-activation-required';
438
444
  /**
439
445
  * Window options that cannot be changed after creation.
@@ -451,6 +457,11 @@ export type ConstWindowOptions = {
451
457
  * @deprecated use `icon` instead.
452
458
  */
453
459
  applicationIcon: string;
460
+ /**
461
+ * Autoplay policy to apply to content in the window, can be
462
+ * `no-user-gesture-required`, `user-gesture-required`,
463
+ * `document-user-activation-required`. Defaults to `no-user-gesture-required`.
464
+ */
454
465
  autoplayPolicy: AutoplayPolicyOptions;
455
466
  /**
456
467
  * Automatically show the window when it is created.
@@ -1267,6 +1278,11 @@ export type ConstViewOptions = {
1267
1278
  * Enable keyboard shortcuts for devtools, zoom, reload, and reload ignoring cache.
1268
1279
  */
1269
1280
  accelerator?: Partial<Accelerator>;
1281
+ /**
1282
+ * Autoplay policy to apply to content in the window, can be
1283
+ * `no-user-gesture-required`, `user-gesture-required`,
1284
+ * `document-user-activation-required`. Defaults to `no-user-gesture-required`.
1285
+ */
1270
1286
  autoplayPolicy: AutoplayPolicyOptions;
1271
1287
  };
1272
1288
  export type ViewState = ViewCreationOptions & {
@@ -67,10 +67,6 @@ export type FoundInPageEvent = NamedEvent & {
67
67
  } & {
68
68
  result: OpenFin.FindInPageResult;
69
69
  };
70
- /**
71
- * A WebContents event that does not propagate to (republish on) parent topics.
72
- */
73
- export type NonPropagatedWebContentsEvent = FoundInPageEvent | CertificateErrorEvent;
74
70
  export type BlurredEvent = NamedEvent & {
75
71
  type: 'blurred';
76
72
  };
@@ -89,9 +85,62 @@ export type ChildContentOpenedInBrowserEvent = NamedEvent & {
89
85
  export type ChildViewCreatedEvent = NamedEvent & {
90
86
  type: 'child-view-created';
91
87
  };
88
+ export type FileDownloadEvent = NamedEvent & {
89
+ state: 'started' | 'progressing' | 'cancelled' | 'interrupted' | 'completed';
90
+ /**
91
+ * The url from which the file is being downloaded.
92
+ */
93
+ url: string;
94
+ mimeType: string;
95
+ /**
96
+ * Name used to save the file locally.
97
+ */
98
+ fileName: string;
99
+ /**
100
+ * Original name of the file.
101
+ */
102
+ originalFileName: string;
103
+ totalBytes: number;
104
+ /**
105
+ * The number of seconds since the UNIX epoch when the download was started.
106
+ */
107
+ startTime: number;
108
+ /**
109
+ * The value of the Content-Disposition field from the response header.
110
+ */
111
+ contentDisposition: string;
112
+ /**
113
+ * The value of the Last-Modified header.
114
+ */
115
+ lastModifiedTime: Date;
116
+ /**
117
+ * The value of the ETag header.
118
+ */
119
+ eTag: string;
120
+ /**
121
+ * The number of bytes of the item that have already been downloaded.
122
+ */
123
+ downloadedBytes: number;
124
+ };
125
+ export type FileDownloadStartedEvent = FileDownloadEvent & {
126
+ type: 'file-download-started';
127
+ state: 'started';
128
+ };
129
+ export type FileDownloadProgressEvent = FileDownloadEvent & {
130
+ type: 'file-download-progress';
131
+ state: 'progressing' | 'interrupted';
132
+ };
133
+ export type FileDownloadCompletedEvent = FileDownloadEvent & {
134
+ type: 'file-download-completed';
135
+ state: 'completed' | 'interrupted' | 'cancelled';
136
+ };
92
137
  /**
93
138
  * A WebContents event that does propagate to (republish on) parent topics.
94
139
  */
95
- export type WillPropagateWebContentsEvent = BlurredEvent | CertificateSelectionShownEvent | CrashedEvent | DidChangeThemeColorEvent | FocusedEvent | NavigationRejectedEvent | UrlChangedEvent | DidFailLoadEvent | DidFinishLoadEvent | FaviconUpdatedEvent | PageTitleUpdatedEvent | ResourceLoadFailedEvent | ResourceResponseReceivedEvent | ChildContentBlockedEvent | ChildContentOpenedInBrowserEvent | ChildViewCreatedEvent;
140
+ export type WillPropagateWebContentsEvent = BlurredEvent | CertificateSelectionShownEvent | CrashedEvent | DidChangeThemeColorEvent | FocusedEvent | NavigationRejectedEvent | UrlChangedEvent | DidFailLoadEvent | DidFinishLoadEvent | FaviconUpdatedEvent | PageTitleUpdatedEvent | ResourceLoadFailedEvent | ResourceResponseReceivedEvent | ChildContentBlockedEvent | ChildContentOpenedInBrowserEvent | ChildViewCreatedEvent | FileDownloadStartedEvent | FileDownloadProgressEvent | FileDownloadCompletedEvent;
141
+ /**
142
+ * A WebContents event that does not propagate to (republish on) parent topics.
143
+ */
144
+ export type NonPropagatedWebContentsEvent = FoundInPageEvent | CertificateErrorEvent;
96
145
  export type WebContentsEvent = NonPropagatedWebContentsEvent | WillPropagateWebContentsEvent;
97
146
  export {};
@@ -4,9 +4,9 @@ import { Transport } from '../../../transport/transport';
4
4
  import { AnyStrategy } from './protocols/strategy-types';
5
5
  type ProviderIdentity = OpenFin.ProviderIdentity;
6
6
  type DisconnectionListener = (providerIdentity: ProviderIdentity) => any;
7
- interface RoutingInfo extends ProviderIdentity {
7
+ export type RoutingInfo = ProviderIdentity & {
8
8
  endpointId: string;
9
- }
9
+ };
10
10
  export default class ChannelClient extends ChannelBase {
11
11
  #private;
12
12
  private disconnectListener;
@@ -1,9 +1,9 @@
1
1
  import type * as OpenFin from '../../../OpenFin';
2
- import ChannelClient from './client';
3
- import { ChannelProvider } from './provider';
2
+ import { Message, Transport } from '../../../transport/transport';
4
3
  import { EmitterBase } from '../../base';
5
- import { Transport, Message } from '../../../transport/transport';
6
4
  import { ChannelEvent } from '../../events/channel';
5
+ import ChannelClient from './client';
6
+ import { ChannelProvider } from './provider';
7
7
  type ProviderIdentity = OpenFin.ProviderIdentity;
8
8
  type Identity = OpenFin.Identity;
9
9
  export interface ChannelMessage extends Message<any> {
@@ -15,10 +15,10 @@ export interface ChannelMessage extends Message<any> {
15
15
  export declare class Channel extends EmitterBase<ChannelEvent> {
16
16
  #private;
17
17
  constructor(wire: Transport);
18
- private channelExists;
19
18
  getAllChannels(): Promise<ProviderIdentity[]>;
20
19
  onChannelConnect(listener: (...args: any[]) => void): Promise<void>;
21
20
  onChannelDisconnect(listener: (...args: any[]) => void): Promise<void>;
21
+ private safeConnect;
22
22
  connect(channelName: string, options?: OpenFin.ChannelConnectOptions): Promise<ChannelClient>;
23
23
  create(channelName: string, options?: OpenFin.ChannelCreateOptions): Promise<ChannelProvider>;
24
24
  }
@@ -14,12 +14,25 @@ var _Channel_connectionManager, _Channel_internalEmitter, _Channel_readyToConnec
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.Channel = void 0;
16
16
  /* eslint-disable no-console */
17
- const client_1 = require("./client");
18
- const provider_1 = require("./provider");
19
- const base_1 = require("../../base");
20
- const connection_manager_1 = require("./connection-manager");
21
17
  const events_1 = require("events");
22
18
  const lazy_1 = require("../../../util/lazy");
19
+ const base_1 = require("../../base");
20
+ const client_1 = require("./client");
21
+ const connection_manager_1 = require("./connection-manager");
22
+ const provider_1 = require("./provider");
23
+ function retryDelay(count) {
24
+ const interval = 500; // base delay
25
+ const steps = 10; // How many retries to do before incrementing the delay
26
+ const base = 2; // How much to multiply the previous delay by
27
+ const max = 30000; // max delay
28
+ const step = Math.floor(count / steps);
29
+ const delay = Math.min(max, interval * base ** step);
30
+ return new Promise(resolve => {
31
+ setTimeout(() => {
32
+ resolve(false);
33
+ }, delay);
34
+ });
35
+ }
23
36
  class Channel extends base_1.EmitterBase {
24
37
  constructor(wire) {
25
38
  super(wire, 'channel');
@@ -38,10 +51,6 @@ class Channel extends base_1.EmitterBase {
38
51
  }));
39
52
  __classPrivateFieldSet(this, _Channel_connectionManager, new connection_manager_1.ConnectionManager(wire), "f");
40
53
  }
41
- async channelExists(channelName) {
42
- const channels = await this.getAllChannels();
43
- return channels.some((providerIdentity) => providerIdentity.channelName === channelName);
44
- }
45
54
  async getAllChannels() {
46
55
  return this.wire.sendAction('get-all-channels').then(({ payload }) => payload.data);
47
56
  }
@@ -51,6 +60,57 @@ class Channel extends base_1.EmitterBase {
51
60
  async onChannelDisconnect(listener) {
52
61
  await this.on('disconnected', listener);
53
62
  }
63
+ async safeConnect(channelName, shouldWait, connectPayload) {
64
+ const retryInfo = { count: 0 };
65
+ /* eslint-disable no-await-in-loop, no-constant-condition */
66
+ do {
67
+ // setup a listener and a connected promise to await in case we connect before the channel is ready
68
+ let connectedListener = () => undefined;
69
+ const connectedPromise = new Promise((resolve) => {
70
+ connectedListener = (payload) => {
71
+ if (channelName === payload.channelName) {
72
+ resolve(true);
73
+ }
74
+ };
75
+ __classPrivateFieldGet(this, _Channel_internalEmitter, "f").on('connected', connectedListener);
76
+ });
77
+ try {
78
+ if (retryInfo.count > 0) {
79
+ // Wait before retrying
80
+ // Delay returns false connectedPromise returns true so we can know if a retry is due to connected event
81
+ retryInfo.gotConnectedEvent = await Promise.race([retryDelay(retryInfo.count), connectedPromise]);
82
+ const result = await this.wire.sendAction('connect-to-channel', { ...connectPayload, retryInfo });
83
+ // log only if there was a retry
84
+ console.log(`Successfully connected to channelName: ${channelName}`);
85
+ return result.payload.data;
86
+ }
87
+ // Send retryInfo to the core for debug log inclusion
88
+ const sentMessagePromise = this.wire.sendAction('connect-to-channel', connectPayload);
89
+ // Save messageId from the first connection attempt
90
+ retryInfo.originalMessageId = sentMessagePromise.messageId;
91
+ const result = await sentMessagePromise;
92
+ return result.payload.data;
93
+ }
94
+ catch (error) {
95
+ if (!error.message.includes('internal-nack')) {
96
+ // Not an internal nack, break the loop
97
+ throw error;
98
+ }
99
+ if (shouldWait && retryInfo.count === 0) {
100
+ // start waiting on the next iteration, warn the user
101
+ console.warn(`No channel found for channelName: ${channelName}. Waiting for connection...`);
102
+ }
103
+ }
104
+ finally {
105
+ retryInfo.count += 1;
106
+ // in case of other errors, remove our listener
107
+ __classPrivateFieldGet(this, _Channel_internalEmitter, "f").removeListener('connected', connectedListener);
108
+ }
109
+ } while (shouldWait); // If we're waiting we retry the above loop
110
+ // Should wait was false, no channel was found.
111
+ throw new Error(`No channel found for channelName: ${channelName}.`);
112
+ /* eslint-enable no-await-in-loop, no-constant-condition */
113
+ }
54
114
  async connect(channelName, options = {}) {
55
115
  // Make sure we don't connect before listeners are set up
56
116
  // This also errors if we're not in OpenFin, ensuring we don't run unnecessary code
@@ -59,61 +119,35 @@ class Channel extends base_1.EmitterBase {
59
119
  throw new Error('Please provide a channelName string to connect to a channel.');
60
120
  }
61
121
  const opts = { wait: true, ...this.wire.environment.getDefaultChannelOptions().connect, ...options };
62
- const shouldWait = opts.wait;
63
- if (shouldWait) {
64
- const channelExists = await this.channelExists(channelName);
65
- if (!channelExists) {
66
- console.warn(`Channel not found for channelName: ${channelName}, waiting for channel connection.`);
67
- await new Promise((resolve) => {
68
- const connectedListener = (payload) => {
69
- if (channelName === payload.channelName) {
70
- __classPrivateFieldGet(this, _Channel_internalEmitter, "f").removeListener('connected', connectedListener);
71
- resolve();
72
- }
73
- };
74
- __classPrivateFieldGet(this, _Channel_internalEmitter, "f").on('connected', connectedListener);
75
- });
76
- }
122
+ const { offer, rtc: rtcPacket } = await __classPrivateFieldGet(this, _Channel_connectionManager, "f").createClientOffer(opts);
123
+ let connectionUrl;
124
+ if (this.fin.me.isFrame || this.fin.me.isView || this.fin.me.isWindow) {
125
+ connectionUrl = (await this.fin.me.getInfo()).url;
77
126
  }
78
- try {
79
- const { offer, rtc: rtcPacket } = await __classPrivateFieldGet(this, _Channel_connectionManager, "f").createClientOffer(opts);
80
- let connectionUrl;
81
- if (this.fin.me.isFrame || this.fin.me.isView || this.fin.me.isWindow) {
82
- connectionUrl = (await this.fin.me.getInfo()).url;
127
+ const connectPayload = {
128
+ channelName,
129
+ ...opts,
130
+ offer,
131
+ connectionUrl
132
+ };
133
+ const routingInfo = await this.safeConnect(channelName, opts.wait, connectPayload);
134
+ const strategy = await __classPrivateFieldGet(this, _Channel_connectionManager, "f").createClientStrategy(rtcPacket, routingInfo);
135
+ const channel = new client_1.default(routingInfo, this.wire, strategy);
136
+ // It is the client's responsibility to handle endpoint disconnection to the provider.
137
+ // If the endpoint dies, the client will force a disconnection through the core.
138
+ // The provider does not care about endpoint disconnection.
139
+ strategy.onEndpointDisconnect(routingInfo.channelId, async () => {
140
+ try {
141
+ await channel.sendDisconnectAction();
83
142
  }
84
- const { payload: { data: routingInfo } } = await this.wire.sendAction('connect-to-channel', {
85
- channelName,
86
- ...opts,
87
- offer,
88
- connectionUrl
89
- });
90
- const strategy = await __classPrivateFieldGet(this, _Channel_connectionManager, "f").createClientStrategy(rtcPacket, routingInfo);
91
- const channel = new client_1.default(routingInfo, this.wire, strategy);
92
- // It is the client's responsibility to handle endpoint disconnection to the provider.
93
- // If the endpoint dies, the client will force a disconnection through the core.
94
- // The provider does not care about endpoint disconnection.
95
- strategy.onEndpointDisconnect(routingInfo.channelId, async () => {
96
- try {
97
- await channel.sendDisconnectAction();
98
- }
99
- catch (error) {
100
- console.warn(`Something went wrong during disconnect for client with uuid: ${routingInfo.uuid} / name: ${routingInfo.name} / endpointId: ${routingInfo.endpointId}.`);
101
- }
102
- finally {
103
- client_1.default.handleProviderDisconnect(routingInfo);
104
- }
105
- });
106
- return channel;
107
- }
108
- catch (error) {
109
- const internalNackMessage = 'internal-nack';
110
- if (error.message.includes(internalNackMessage)) {
111
- throw new Error(`No channel found for channelName: ${channelName}.`);
143
+ catch (error) {
144
+ console.warn(`Something went wrong during disconnect for client with uuid: ${routingInfo.uuid} / name: ${routingInfo.name} / endpointId: ${routingInfo.endpointId}.`);
112
145
  }
113
- else {
114
- throw new Error(error);
146
+ finally {
147
+ client_1.default.handleProviderDisconnect(routingInfo);
115
148
  }
116
- }
149
+ });
150
+ return channel;
117
151
  }
118
152
  async create(channelName, options) {
119
153
  if (!channelName) {
@@ -6,19 +6,18 @@ type ProviderIdentity = OpenFin.ProviderIdentity;
6
6
  type ClientIdentity = OpenFin.ClientIdentity;
7
7
  export type ConnectionListener = (identity: ClientIdentity, connectionMessage?: any) => Promise<any> | any;
8
8
  export type DisconnectionListener = (identity: ClientIdentity) => any;
9
- type ClientConnectionPayload = OpenFin.ClientIdentity & OpenFin.ClientInfo;
10
9
  export declare class ChannelProvider extends ChannelBase {
11
10
  #private;
12
11
  private static removalMap;
13
12
  private connectListener;
14
13
  private disconnectListener;
15
- get connections(): ClientConnectionPayload[];
14
+ get connections(): OpenFin.ClientConnectionPayload[];
16
15
  static handleClientDisconnection(channel: ChannelProvider, payload: any): void;
17
16
  static setProviderRemoval(provider: ChannelProvider, remove: Function): void;
18
17
  constructor(providerIdentity: ProviderIdentity, wire: Transport, strategy: AnyStrategy);
19
18
  dispatch(to: OpenFin.ClientIdentity | OpenFin.Identity, action: string, payload?: any): Promise<any>;
20
19
  protected processAction: (action: string, payload: any, senderIdentity: OpenFin.ClientIdentity | OpenFin.ClientIdentityMultiRuntime) => Promise<any>;
21
- processConnection(senderId: ClientConnectionPayload, payload: any): Promise<any>;
20
+ processConnection(senderId: OpenFin.ClientConnectionPayload, payload: any): Promise<any>;
22
21
  publish(action: string, payload: any): Promise<any>[];
23
22
  onConnection(listener: ConnectionListener): void;
24
23
  onDisconnection(listener: DisconnectionListener): void;
@@ -55,6 +55,11 @@ type ViewEvent = OpenFin.ViewEvent;
55
55
  * @property {boolean} [api.iframe.crossOriginInjection=false] Controls if the `fin` API object is present for cross origin iframes.
56
56
  * @property {boolean} [api.iframe.sameOriginInjection=true] Controls if the `fin` API object is present for same origin iframes.
57
57
  *
58
+ * @property {string} [autoplayPolicy="no-user-gesture-required"]
59
+ * Autoplay policy to apply to content in the window, can be
60
+ * `no-user-gesture-required`, `user-gesture-required`,
61
+ * `document-user-activation-required`. Defaults to `no-user-gesture-required`.
62
+ *
58
63
  * @property {object} [autoResize] AutoResize options
59
64
  *
60
65
  * @property {object} [bounds] initial bounds given relative to the window.
@@ -65,6 +65,11 @@ const window_1 = require("../window");
65
65
  * @property {boolean} [api.iframe.crossOriginInjection=false] Controls if the `fin` API object is present for cross origin iframes.
66
66
  * @property {boolean} [api.iframe.sameOriginInjection=true] Controls if the `fin` API object is present for same origin iframes.
67
67
  *
68
+ * @property {string} [autoplayPolicy="no-user-gesture-required"]
69
+ * Autoplay policy to apply to content in the window, can be
70
+ * `no-user-gesture-required`, `user-gesture-required`,
71
+ * `document-user-activation-required`. Defaults to `no-user-gesture-required`.
72
+ *
68
73
  * @property {object} [autoResize] AutoResize options
69
74
  *
70
75
  * @property {object} [bounds] initial bounds given relative to the window.
@@ -134,6 +134,11 @@ import { WebContents } from '../webcontents/main';
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
  *
@@ -141,6 +141,11 @@ const view_1 = require("../view");
141
141
  * The aspect ratio of width to height to enforce for the window. If this value is equal to or less than zero,
142
142
  * an aspect ratio will not be enforced.
143
143
  *
144
+ * @property {string} [autoplayPolicy="no-user-gesture-required"]
145
+ * Autoplay policy to apply to content in the window, can be
146
+ * `no-user-gesture-required`, `user-gesture-required`,
147
+ * `document-user-activation-required`. Defaults to `no-user-gesture-required`.
148
+ *
144
149
  * @property {boolean} [autoShow=true]
145
150
  * A flag to automatically show the window when it is created.
146
151
  *
@@ -15,8 +15,9 @@ type SendActionResponse<T extends keyof ProtocolMap> = Message<{
15
15
  data: ProtocolMap[T]['response'];
16
16
  } & ProtocolMap[T]['specialResponse']>;
17
17
  export type MessageHandler = (data: any) => boolean;
18
- export type CancellablePromise<T> = Promise<T> & {
18
+ export type SentMessage<Value> = Promise<Value> & {
19
19
  cancel: (reason?: any) => void;
20
+ messageId: ReturnType<Environment['getNextMessageId']>;
20
21
  };
21
22
  type NackHandler = (payloadOrMessage: RuntimeErrorPayload | string) => void;
22
23
  export declare class Transport<MeType extends EntityType = EntityType> extends EventEmitter {
@@ -42,7 +43,7 @@ export declare class Transport<MeType extends EntityType = EntityType> extends E
42
43
  private connectRemote;
43
44
  connectByPort(config: ExistingConnectConfig): Promise<void>;
44
45
  private authorize;
45
- sendAction<T extends keyof ProtocolMap = string>(action: T, payload?: ProtocolMap[T]['request'], uncorrelated?: boolean): CancellablePromise<SendActionResponse<T>>;
46
+ sendAction<T extends keyof ProtocolMap = string>(action: T, payload?: ProtocolMap[T]['request'], uncorrelated?: boolean): SentMessage<SendActionResponse<T>>;
46
47
  protected nackHandler(payloadOrMessage: RuntimeErrorPayload | string, reject: Function, callSites?: NodeJS.CallSite[]): void;
47
48
  ferryAction(origData: any): Promise<Message<any>>;
48
49
  registerMessageHandler(handler: MessageHandler): void;
@@ -115,9 +115,9 @@ class Transport extends events_1.EventEmitter {
115
115
  let cancel = () => { };
116
116
  // We want the callsite from the caller of this function, not from here.
117
117
  const callSites = transport_errors_1.RuntimeError.getCallSite(1);
118
+ const messageId = this.environment.getNextMessageId();
118
119
  const prom = new Promise((resolve, reject) => {
119
120
  cancel = reject;
120
- const messageId = this.environment.getNextMessageId();
121
121
  const msg = {
122
122
  action,
123
123
  payload,
@@ -127,7 +127,7 @@ class Transport extends events_1.EventEmitter {
127
127
  this.addWireListener(messageId, resolve, (payload) => this.nackHandler(payload, reject, callSites), uncorrelated);
128
128
  return wire.send(msg).catch(reject);
129
129
  });
130
- return Object.assign(prom, { cancel });
130
+ return Object.assign(prom, { cancel, messageId });
131
131
  }
132
132
  nackHandler(payloadOrMessage, reject, callSites) {
133
133
  if (typeof payloadOrMessage === 'string') {
@@ -1,31 +0,0 @@
1
- import type * as OpenFin from '../OpenFin';
2
- import { Transport } from '../transport/transport';
3
- import { NewConnectConfig } from '../transport/wire';
4
- import { BrowserEnvironment } from './browser';
5
- import { ChildContentOptions, Environment } from './environment';
6
- type EntityType = OpenFin.EntityType;
7
- export default class OpenFinEnvironment extends BrowserEnvironment implements Environment {
8
- #private;
9
- private raiseEventAsync;
10
- childViews: boolean;
11
- constructor();
12
- getDefaultChannelOptions(): {
13
- create: OpenFin.ChannelCreateOptions;
14
- connect: OpenFin.ChannelConnectOptions;
15
- };
16
- initLayout(_fin: OpenFin.Fin<OpenFin.EntityType>, wire: Transport, options: OpenFin.InitLayoutOptions): Promise<OpenFin.Layout>;
17
- initPlatform(_fin: OpenFin.Fin<OpenFin.EntityType>, options?: OpenFin.InitPlatformOptions): ReturnType<OpenFin.Fin['Platform']['init']>;
18
- observeBounds(element: Element, onChange: (bounds: DOMRect) => void | Promise<void>): () => void;
19
- writeToken: (path: string, token: string) => Promise<string>;
20
- retrievePort: (config: NewConnectConfig) => Promise<number>;
21
- getNextMessageId: () => any;
22
- createChildContent: ({ options, entityType }: ChildContentOptions) => Promise<unknown>;
23
- private normalizeOptions;
24
- private resolveUrl;
25
- getWebWindow: (identity: OpenFin.Identity) => globalThis.Window;
26
- getCurrentEntityIdentity: () => OpenFin.EntityInfo;
27
- getCurrentEntityType: () => EntityType;
28
- raiseEvent: (eventName: string, eventArgs: any) => void;
29
- whenReady(): Promise<void>;
30
- }
31
- export {};
@@ -1,100 +0,0 @@
1
- "use strict";
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
- if (kind === "m") throw new TypeError("Private method is not writable");
4
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
- };
8
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
- };
13
- var _OpenFinEnvironment_ready;
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const transport_errors_1 = require("../transport/transport-errors");
16
- const browser_1 = require("./browser");
17
- const bounds_observer_1 = require("../api/platform/renderer/utils/bounds-observer");
18
- // Inherits the following BrowserEnvironment methods: getRtcPeer, getRandomId, getUrl, getWsConstructor.
19
- class OpenFinEnvironment extends browser_1.BrowserEnvironment {
20
- constructor() {
21
- super();
22
- _OpenFinEnvironment_ready.set(this, void 0);
23
- this.writeToken = (path, token) => {
24
- throw new transport_errors_1.NotImplementedError('Not Implemented');
25
- };
26
- this.retrievePort = (config) => {
27
- throw new transport_errors_1.NotImplementedError('Not Implemented');
28
- };
29
- this.getNextMessageId = () => {
30
- return fin.desktop.getUuid();
31
- };
32
- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
33
- this.createChildContent = async ({ options, entityType }) => {
34
- const opts = this.normalizeOptions(options);
35
- return new Promise((y, n) => fin.__internal_.createChildContent({ entityType, options: opts }, y, n));
36
- };
37
- this.normalizeOptions = (options) => {
38
- const { uuid: parentUuid } = fin.__internal_.initialOptions;
39
- const opts = JSON.parse(JSON.stringify(options));
40
- const ABOUT_BLANK = 'about:blank';
41
- opts.uuid = opts.uuid || parentUuid;
42
- opts.url = opts.url || ABOUT_BLANK;
43
- if (opts.url !== ABOUT_BLANK) {
44
- opts.url = this.resolveUrl(opts.url);
45
- }
46
- return opts;
47
- };
48
- this.getWebWindow = (identity) => {
49
- return fin.__internal_.getWebWindow(identity.name);
50
- };
51
- this.getCurrentEntityIdentity = () => {
52
- return fin.__internal_.entityInfo;
53
- };
54
- this.getCurrentEntityType = () => {
55
- return this.getCurrentEntityIdentity().entityType || 'unknown';
56
- };
57
- this.raiseEvent = (eventName, eventArgs) => {
58
- this.raiseEventAsync(eventName, eventArgs);
59
- };
60
- this.raiseEventAsync = fin.__internal_.raiseEventAsync;
61
- delete fin.__internal_.raiseEventAsync;
62
- this.childViews = fin.__internal_.childViews;
63
- __classPrivateFieldSet(this, _OpenFinEnvironment_ready, new Promise((resolve) => {
64
- fin.desktop.main(resolve);
65
- }), "f");
66
- }
67
- getDefaultChannelOptions() {
68
- var _a, _b;
69
- return {
70
- create: {},
71
- connect: {},
72
- ...((_b = (_a = fin.__internal_.initialOptions.experimental) === null || _a === void 0 ? void 0 : _a.defaultChannelOptions) !== null && _b !== void 0 ? _b : {})
73
- };
74
- }
75
- async initLayout(_fin, wire, options) {
76
- const { initLayout } = await Promise.resolve().then(() => require(
77
- /* webpackChunkName: 'layout' */
78
- '../api/platform/renderer/init-layout'));
79
- return initLayout(_fin, wire, options);
80
- }
81
- async initPlatform(_fin, options) {
82
- const { initPlatformProvider } = await Promise.resolve().then(() => require(
83
- /* webpackChunkName: 'provider' */
84
- '../api/platform/renderer/init-platform-provider'));
85
- return initPlatformProvider(this, _fin, options);
86
- }
87
- observeBounds(element, onChange) {
88
- return (0, bounds_observer_1.observeBounds)(element, onChange);
89
- }
90
- // eslint-disable-next-line class-methods-use-this
91
- resolveUrl(url) {
92
- const newUrl = new URL(url, location.href);
93
- return newUrl.href;
94
- }
95
- whenReady() {
96
- return __classPrivateFieldGet(this, _OpenFinEnvironment_ready, "f");
97
- }
98
- }
99
- exports.default = OpenFinEnvironment;
100
- _OpenFinEnvironment_ready = new WeakMap();