@openfin/core 33.76.31 → 33.76.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/openfin-core-33.76.36.tgz +0 -0
  2. package/package.json +1 -1
  3. package/src/OpenFin.d.ts +27 -16
  4. package/src/api/application/Factory.d.ts +148 -100
  5. package/src/api/application/Factory.js +148 -100
  6. package/src/api/application/Instance.d.ts +477 -106
  7. package/src/api/application/Instance.js +474 -106
  8. package/src/api/application/index.d.ts +9 -0
  9. package/src/api/application/index.js +9 -0
  10. package/src/api/base.d.ts +69 -0
  11. package/src/api/base.js +69 -0
  12. package/src/api/clipboard/index.d.ts +111 -31
  13. package/src/api/clipboard/index.js +111 -31
  14. package/src/api/events/application.d.ts +12 -0
  15. package/src/api/events/application.js +12 -0
  16. package/src/api/events/channel.d.ts +5 -0
  17. package/src/api/events/channel.js +5 -0
  18. package/src/api/events/externalApplication.d.ts +5 -0
  19. package/src/api/events/externalApplication.js +5 -0
  20. package/src/api/events/frame.d.ts +5 -0
  21. package/src/api/events/globalHotkey.d.ts +5 -0
  22. package/src/api/events/platform.d.ts +9 -1
  23. package/src/api/events/platform.js +8 -0
  24. package/src/api/events/system.d.ts +13 -0
  25. package/src/api/events/system.js +13 -0
  26. package/src/api/events/view.d.ts +19 -9
  27. package/src/api/events/view.js +10 -0
  28. package/src/api/events/webcontents.d.ts +21 -10
  29. package/src/api/events/webcontents.js +11 -0
  30. package/src/api/events/window.d.ts +70 -1
  31. package/src/api/events/window.js +10 -0
  32. package/src/api/external-application/Factory.d.ts +16 -9
  33. package/src/api/external-application/Factory.js +16 -9
  34. package/src/api/external-application/Instance.d.ts +40 -32
  35. package/src/api/external-application/Instance.js +40 -32
  36. package/src/api/external-application/index.d.ts +9 -0
  37. package/src/api/external-application/index.js +9 -0
  38. package/src/api/fin.d.ts +3 -0
  39. package/src/api/fin.js +3 -0
  40. package/src/api/frame/Factory.d.ts +30 -13
  41. package/src/api/frame/Factory.js +30 -13
  42. package/src/api/frame/Instance.d.ts +51 -38
  43. package/src/api/frame/Instance.js +51 -38
  44. package/src/api/frame/index.d.ts +11 -0
  45. package/src/api/frame/index.js +11 -0
  46. package/src/api/global-hotkey/index.d.ts +81 -13
  47. package/src/api/global-hotkey/index.js +81 -13
  48. package/src/api/interappbus/channel/channel.d.ts +257 -0
  49. package/src/api/interappbus/channel/channel.js +257 -0
  50. package/src/api/interappbus/channel/channels-docs.d.ts +59 -57
  51. package/src/api/interappbus/channel/channels-docs.js +71 -68
  52. package/src/api/interappbus/channel/client.d.ts +93 -0
  53. package/src/api/interappbus/channel/client.js +93 -1
  54. package/src/api/interappbus/channel/index.d.ts +164 -0
  55. package/src/api/interappbus/channel/index.js +165 -1
  56. package/src/api/interappbus/channel/provider.d.ts +172 -0
  57. package/src/api/interappbus/channel/provider.js +172 -0
  58. package/src/api/interappbus/index.d.ts +55 -20
  59. package/src/api/interappbus/index.js +55 -20
  60. package/src/api/interop/Factory.d.ts +30 -10
  61. package/src/api/interop/Factory.js +30 -10
  62. package/src/api/interop/InteropBroker.d.ts +298 -70
  63. package/src/api/interop/InteropBroker.js +298 -70
  64. package/src/api/interop/InteropClient.d.ts +286 -62
  65. package/src/api/interop/InteropClient.js +286 -62
  66. package/src/api/interop/SessionContextGroupClient.d.ts +2 -2
  67. package/src/api/interop/SessionContextGroupClient.js +2 -2
  68. package/src/api/interop/fdc3/documentationStub.d.ts +14 -0
  69. package/src/api/interop/fdc3/documentationStub.js +17 -0
  70. package/src/api/interop/fdc3/fdc3-1.2.d.ts +31 -34
  71. package/src/api/interop/fdc3/fdc3-1.2.js +31 -34
  72. package/src/api/interop/fdc3/fdc3-2.0.d.ts +48 -51
  73. package/src/api/interop/fdc3/fdc3-2.0.js +48 -51
  74. package/src/api/interop/index.d.ts +8 -0
  75. package/src/api/interop/index.js +8 -0
  76. package/src/api/platform/Factory.d.ts +121 -65
  77. package/src/api/platform/Factory.js +122 -66
  78. package/src/api/platform/Instance.d.ts +551 -48
  79. package/src/api/platform/Instance.js +551 -49
  80. package/src/api/platform/index.d.ts +9 -0
  81. package/src/api/platform/index.js +9 -0
  82. package/src/api/platform/layout/Factory.d.ts +53 -76
  83. package/src/api/platform/layout/Factory.js +53 -76
  84. package/src/api/platform/layout/Instance.d.ts +158 -23
  85. package/src/api/platform/layout/Instance.js +118 -20
  86. package/src/api/platform/layout/entities/layout-entities.d.ts +222 -30
  87. package/src/api/platform/layout/entities/layout-entities.js +222 -30
  88. package/src/api/platform/layout/index.d.ts +9 -0
  89. package/src/api/platform/layout/index.js +9 -0
  90. package/src/api/platform/provider.d.ts +398 -51
  91. package/src/api/snapshot-source/Factory.d.ts +33 -18
  92. package/src/api/snapshot-source/Factory.js +33 -18
  93. package/src/api/snapshot-source/Instance.d.ts +30 -8
  94. package/src/api/snapshot-source/Instance.js +30 -8
  95. package/src/api/snapshot-source/index.d.ts +9 -0
  96. package/src/api/snapshot-source/index.js +9 -0
  97. package/src/api/system/index.d.ts +1137 -186
  98. package/src/api/system/index.js +1142 -186
  99. package/src/api/view/Factory.d.ts +54 -16
  100. package/src/api/view/Factory.js +54 -16
  101. package/src/api/view/Instance.d.ts +330 -216
  102. package/src/api/view/Instance.js +331 -217
  103. package/src/api/view/index.d.ts +9 -0
  104. package/src/api/view/index.js +9 -0
  105. package/src/api/webcontents/main.d.ts +890 -0
  106. package/src/api/webcontents/main.js +890 -0
  107. package/src/api/window/Factory.d.ts +67 -16
  108. package/src/api/window/Factory.js +67 -16
  109. package/src/api/window/Instance.d.ts +824 -316
  110. package/src/api/window/Instance.js +822 -320
  111. package/src/api/window/index.d.ts +11 -0
  112. package/src/api/window/index.js +11 -0
  113. package/src/namespaces.d.ts +1 -0
  114. package/src/namespaces.js +3 -1
  115. package/src/shapes/protocol.d.ts +4 -0
  116. package/openfin-core-33.76.31.tgz +0 -0
@@ -12,14 +12,178 @@ export interface ChannelMessage extends Message<any> {
12
12
  providerIdentity: ProviderIdentity;
13
13
  connectAction: boolean;
14
14
  }
15
+ /**
16
+ * The Channel API allows an OpenFin application to create a channel as a {@link ChannelProvider ChannelProvider},
17
+ * or connect to a channel as a {@link ChannelClient ChannelClient}.
18
+ * @remarks The "handshake" between the communication partners is
19
+ * simplified when using a channel. A request to connect to a channel as a client will return a promise that resolves if/when the channel has been created. Both the
20
+ * provider and client can dispatch actions that have been registered on their opposites, and dispatch returns a promise that resolves with a payload from the other
21
+ * communication participant. There can be only one provider per channel, but many clients. Version `9.61.35.*` or later is required for both communication partners.
22
+ *
23
+ * Asynchronous Methods:
24
+ * * {@link Channel.create create(channelName, options)}
25
+ * * {@link Channel.connect connect(channelName, options)}
26
+ * * {@link Channel.onChannelConnect onChannelConnect(listener)}
27
+ * * {@link Channel.onChannelDisconnect onChannelDisconnect(listener)}
28
+ */
15
29
  export declare class Channel extends EmitterBase<ChannelEvent> {
16
30
  #private;
31
+ /**
32
+ * @internal
33
+ */
17
34
  constructor(wire: Transport);
35
+ /**
36
+ *
37
+ * @internal
38
+ */
18
39
  getAllChannels(): Promise<ProviderIdentity[]>;
40
+ /**
41
+ * Listens for channel connections.
42
+ *
43
+ * @param listener - callback to execute.
44
+ *
45
+ * @example
46
+ *
47
+ * ```js
48
+ * const listener = (channelPayload) => console.log(channelPayload); // see return value below
49
+ *
50
+ * fin.InterApplicationBus.Channel.onChannelConnect(listener);
51
+ *
52
+ * // example shape
53
+ * {
54
+ * "topic": "channel",
55
+ * "type": "connected",
56
+ * "uuid": "OpenfinPOC",
57
+ * "name": "OpenfinPOC",
58
+ * "channelName": "counter",
59
+ * "channelId": "OpenfinPOC/OpenfinPOC/counter"
60
+ * }
61
+ *
62
+ * ```
63
+ */
19
64
  onChannelConnect(listener: (...args: any[]) => void): Promise<void>;
65
+ /**
66
+ * Listen for channel disconnections.
67
+ *
68
+ * @param listener - callback to execute.
69
+ *
70
+ * @example
71
+ *
72
+ * ```js
73
+ * const listener = (channelPayload) => console.log(channelPayload); // see return value below
74
+ *
75
+ * fin.InterApplicationBus.Channel.onChannelDisconnect(listener);
76
+ *
77
+ * // example shape
78
+ * {
79
+ * "topic": "channel",
80
+ * "type": "disconnected",
81
+ * "uuid": "OpenfinPOC",
82
+ * "name": "OpenfinPOC",
83
+ * "channelName": "counter",
84
+ * "channelId": "OpenfinPOC/OpenfinPOC/counter"
85
+ * }
86
+ *
87
+ * ```
88
+ */
20
89
  onChannelDisconnect(listener: (...args: any[]) => void): Promise<void>;
21
90
  private safeConnect;
91
+ /**
92
+ * Connect to a channel. If you wish to send a payload to the provider, add a payload property to the options argument.
93
+ * EXPERIMENTAL: pass { protocols: ['rtc'] } as options to opt-in to High Throughput Channels.
94
+ *
95
+ * @param channelName - Name of the target channel.
96
+ * @param options - Connection options.
97
+ * @returns Returns a promise that resolves with an instance of {@link ChannelClient ChannelClient}.
98
+ *
99
+ * @remarks The connection request will be routed to the channelProvider if/when the channel is created. If the connect
100
+ * request is sent prior to creation, the promise will not resolve or reject until the channel is created by a channelProvider
101
+ * (whether or not to wait for creation is configurable in the connectOptions).
102
+ *
103
+ * The connect call returns a promise that will resolve with a channelClient bus if accepted by the channelProvider, or reject if
104
+ * the channelProvider throws an error to reject the connection. This bus can communicate with the Provider, but not to other
105
+ * clients on the channel. Using the bus, the channelClient can register actions and middleware. Channel lifecycle can also be
106
+ * handled with an onDisconnection listener.
107
+ *
108
+ * @example
109
+ *
110
+ * ```js
111
+ * async function makeClient(channelName) {
112
+ * // A payload can be sent along with channel connection requests to help with authentication
113
+ * const connectPayload = { payload: 'token' };
114
+ *
115
+ * // If the channel has been created this request will be sent to the provider. If not, the
116
+ * // promise will not be resolved or rejected until the channel has been created.
117
+ * const clientBus = await fin.InterApplicationBus.Channel.connect(channelName, connectPayload);
118
+ *
119
+ * clientBus.onDisconnection(channelInfo => {
120
+ * // handle the channel lifecycle here - we can connect again which will return a promise
121
+ * // that will resolve if/when the channel is re-created.
122
+ * makeClient(channelInfo.channelName);
123
+ * })
124
+ *
125
+ * clientBus.register('topic', (payload, identity) => {
126
+ * // register a callback for a topic to which the channel provider can dispatch an action
127
+ * console.log('Action dispatched by provider: ', JSON.stringify(identity));
128
+ * console.log('Payload sent in dispatch: ', JSON.stringify(payload));
129
+ * return {
130
+ * echo: payload
131
+ * };
132
+ * });
133
+ * }
134
+ *
135
+ * makeClient('channelName')
136
+ * .then(() => console.log('Connected'))
137
+ * .catch(console.error);
138
+ * ```
139
+ */
22
140
  connect(channelName: string, options?: OpenFin.ChannelConnectOptions): Promise<ChannelClient>;
141
+ /**
142
+ * Create a new channel.
143
+ * You must provide a unique channelName. If a channelName is not provided, or it is not unique, the creation will fail.
144
+ * EXPERIMENTAL: pass { protocols: ['rtc'] } as options to opt-in to High Throughput Channels.
145
+ *
146
+ * @param channelName - Name of the channel to be created.
147
+ * @param options - Creation options.
148
+ * @returns Returns a promise that resolves with an instance of {@link ChannelProvider ChannelProvider}.
149
+ *
150
+ * @remarks If successful, the create method returns a promise that resolves to an instance of the channelProvider bus. The caller
151
+ * then becomes the “channel provider” and can use the channelProvider bus to register actions and middleware.
152
+ *
153
+ * The caller can also set an onConnection and/or onDisconnection listener that will execute on any new channel
154
+ * connection/disconnection attempt from a channel client. To reject a connection, simply throw an error in the
155
+ * onConnection listener. The default behavior is to accept all new connections.
156
+ *
157
+ * A map of client connections is updated automatically on client connection and disconnection and saved in the
158
+ * [read-only] `connections` property on the channelProvider bus. The channel will exist until the provider
159
+ * destroys it or disconnects by closing or destroying the context (navigating or reloading). To setup a channel
160
+ * as a channelProvider, call `Channel.create` with a unique channel name. A map of client connections is updated
161
+ * automatically on client connection and disconnection.
162
+ *
163
+ * @example
164
+ *
165
+ * ```js
166
+ * (async ()=> {
167
+ * // entity creates a channel and becomes the channelProvider
168
+ * const providerBus = await fin.InterApplicationBus.Channel.create('channelName');
169
+ *
170
+ * providerBus.onConnection((identity, payload) => {
171
+ * // can reject a connection here by throwing an error
172
+ * console.log('Client connection request identity: ', JSON.stringify(identity));
173
+ * console.log('Client connection request payload: ', JSON.stringify(payload));
174
+ * });
175
+ *
176
+ * providerBus.register('topic', (payload, identity) => {
177
+ * // register a callback for a 'topic' to which clients can dispatch an action
178
+ * console.log('Action dispatched by client: ', JSON.stringify(identity));
179
+ * console.log('Payload sent in dispatch: ', JSON.stringify(payload));
180
+ * return {
181
+ * echo: payload
182
+ * };
183
+ * });
184
+ * })();
185
+ * ```
186
+ */
23
187
  create(channelName: string, options?: OpenFin.ChannelCreateOptions): Promise<ChannelProvider>;
24
188
  }
25
189
  export {};
@@ -27,13 +27,30 @@ function retryDelay(count) {
27
27
  const max = 30000; // max delay
28
28
  const step = Math.floor(count / steps);
29
29
  const delay = Math.min(max, interval * base ** step);
30
- return new Promise(resolve => {
30
+ return new Promise((resolve) => {
31
31
  setTimeout(() => {
32
32
  resolve(false);
33
33
  }, delay);
34
34
  });
35
35
  }
36
+ /**
37
+ * The Channel API allows an OpenFin application to create a channel as a {@link ChannelProvider ChannelProvider},
38
+ * or connect to a channel as a {@link ChannelClient ChannelClient}.
39
+ * @remarks The "handshake" between the communication partners is
40
+ * simplified when using a channel. A request to connect to a channel as a client will return a promise that resolves if/when the channel has been created. Both the
41
+ * provider and client can dispatch actions that have been registered on their opposites, and dispatch returns a promise that resolves with a payload from the other
42
+ * communication participant. There can be only one provider per channel, but many clients. Version `9.61.35.*` or later is required for both communication partners.
43
+ *
44
+ * Asynchronous Methods:
45
+ * * {@link Channel.create create(channelName, options)}
46
+ * * {@link Channel.connect connect(channelName, options)}
47
+ * * {@link Channel.onChannelConnect onChannelConnect(listener)}
48
+ * * {@link Channel.onChannelDisconnect onChannelDisconnect(listener)}
49
+ */
36
50
  class Channel extends base_1.EmitterBase {
51
+ /**
52
+ * @internal
53
+ */
37
54
  constructor(wire) {
38
55
  super(wire, 'channel');
39
56
  _Channel_connectionManager.set(this, void 0);
@@ -51,12 +68,64 @@ class Channel extends base_1.EmitterBase {
51
68
  }));
52
69
  __classPrivateFieldSet(this, _Channel_connectionManager, new connection_manager_1.ConnectionManager(wire), "f");
53
70
  }
71
+ /**
72
+ *
73
+ * @internal
74
+ */
54
75
  async getAllChannels() {
55
76
  return this.wire.sendAction('get-all-channels').then(({ payload }) => payload.data);
56
77
  }
78
+ /**
79
+ * Listens for channel connections.
80
+ *
81
+ * @param listener - callback to execute.
82
+ *
83
+ * @example
84
+ *
85
+ * ```js
86
+ * const listener = (channelPayload) => console.log(channelPayload); // see return value below
87
+ *
88
+ * fin.InterApplicationBus.Channel.onChannelConnect(listener);
89
+ *
90
+ * // example shape
91
+ * {
92
+ * "topic": "channel",
93
+ * "type": "connected",
94
+ * "uuid": "OpenfinPOC",
95
+ * "name": "OpenfinPOC",
96
+ * "channelName": "counter",
97
+ * "channelId": "OpenfinPOC/OpenfinPOC/counter"
98
+ * }
99
+ *
100
+ * ```
101
+ */
57
102
  async onChannelConnect(listener) {
58
103
  await this.on('connected', listener);
59
104
  }
105
+ /**
106
+ * Listen for channel disconnections.
107
+ *
108
+ * @param listener - callback to execute.
109
+ *
110
+ * @example
111
+ *
112
+ * ```js
113
+ * const listener = (channelPayload) => console.log(channelPayload); // see return value below
114
+ *
115
+ * fin.InterApplicationBus.Channel.onChannelDisconnect(listener);
116
+ *
117
+ * // example shape
118
+ * {
119
+ * "topic": "channel",
120
+ * "type": "disconnected",
121
+ * "uuid": "OpenfinPOC",
122
+ * "name": "OpenfinPOC",
123
+ * "channelName": "counter",
124
+ * "channelId": "OpenfinPOC/OpenfinPOC/counter"
125
+ * }
126
+ *
127
+ * ```
128
+ */
60
129
  async onChannelDisconnect(listener) {
61
130
  await this.on('disconnected', listener);
62
131
  }
@@ -111,6 +180,55 @@ class Channel extends base_1.EmitterBase {
111
180
  throw new Error(`No channel found for channelName: ${channelName}.`);
112
181
  /* eslint-enable no-await-in-loop, no-constant-condition */
113
182
  }
183
+ /**
184
+ * Connect to a channel. If you wish to send a payload to the provider, add a payload property to the options argument.
185
+ * EXPERIMENTAL: pass { protocols: ['rtc'] } as options to opt-in to High Throughput Channels.
186
+ *
187
+ * @param channelName - Name of the target channel.
188
+ * @param options - Connection options.
189
+ * @returns Returns a promise that resolves with an instance of {@link ChannelClient ChannelClient}.
190
+ *
191
+ * @remarks The connection request will be routed to the channelProvider if/when the channel is created. If the connect
192
+ * request is sent prior to creation, the promise will not resolve or reject until the channel is created by a channelProvider
193
+ * (whether or not to wait for creation is configurable in the connectOptions).
194
+ *
195
+ * The connect call returns a promise that will resolve with a channelClient bus if accepted by the channelProvider, or reject if
196
+ * the channelProvider throws an error to reject the connection. This bus can communicate with the Provider, but not to other
197
+ * clients on the channel. Using the bus, the channelClient can register actions and middleware. Channel lifecycle can also be
198
+ * handled with an onDisconnection listener.
199
+ *
200
+ * @example
201
+ *
202
+ * ```js
203
+ * async function makeClient(channelName) {
204
+ * // A payload can be sent along with channel connection requests to help with authentication
205
+ * const connectPayload = { payload: 'token' };
206
+ *
207
+ * // If the channel has been created this request will be sent to the provider. If not, the
208
+ * // promise will not be resolved or rejected until the channel has been created.
209
+ * const clientBus = await fin.InterApplicationBus.Channel.connect(channelName, connectPayload);
210
+ *
211
+ * clientBus.onDisconnection(channelInfo => {
212
+ * // handle the channel lifecycle here - we can connect again which will return a promise
213
+ * // that will resolve if/when the channel is re-created.
214
+ * makeClient(channelInfo.channelName);
215
+ * })
216
+ *
217
+ * clientBus.register('topic', (payload, identity) => {
218
+ * // register a callback for a topic to which the channel provider can dispatch an action
219
+ * console.log('Action dispatched by provider: ', JSON.stringify(identity));
220
+ * console.log('Payload sent in dispatch: ', JSON.stringify(payload));
221
+ * return {
222
+ * echo: payload
223
+ * };
224
+ * });
225
+ * }
226
+ *
227
+ * makeClient('channelName')
228
+ * .then(() => console.log('Connected'))
229
+ * .catch(console.error);
230
+ * ```
231
+ */
114
232
  async connect(channelName, options = {}) {
115
233
  // Make sure we don't connect before listeners are set up
116
234
  // This also errors if we're not in OpenFin, ensuring we don't run unnecessary code
@@ -149,6 +267,52 @@ class Channel extends base_1.EmitterBase {
149
267
  });
150
268
  return channel;
151
269
  }
270
+ /**
271
+ * Create a new channel.
272
+ * You must provide a unique channelName. If a channelName is not provided, or it is not unique, the creation will fail.
273
+ * EXPERIMENTAL: pass { protocols: ['rtc'] } as options to opt-in to High Throughput Channels.
274
+ *
275
+ * @param channelName - Name of the channel to be created.
276
+ * @param options - Creation options.
277
+ * @returns Returns a promise that resolves with an instance of {@link ChannelProvider ChannelProvider}.
278
+ *
279
+ * @remarks If successful, the create method returns a promise that resolves to an instance of the channelProvider bus. The caller
280
+ * then becomes the “channel provider” and can use the channelProvider bus to register actions and middleware.
281
+ *
282
+ * The caller can also set an onConnection and/or onDisconnection listener that will execute on any new channel
283
+ * connection/disconnection attempt from a channel client. To reject a connection, simply throw an error in the
284
+ * onConnection listener. The default behavior is to accept all new connections.
285
+ *
286
+ * A map of client connections is updated automatically on client connection and disconnection and saved in the
287
+ * [read-only] `connections` property on the channelProvider bus. The channel will exist until the provider
288
+ * destroys it or disconnects by closing or destroying the context (navigating or reloading). To setup a channel
289
+ * as a channelProvider, call `Channel.create` with a unique channel name. A map of client connections is updated
290
+ * automatically on client connection and disconnection.
291
+ *
292
+ * @example
293
+ *
294
+ * ```js
295
+ * (async ()=> {
296
+ * // entity creates a channel and becomes the channelProvider
297
+ * const providerBus = await fin.InterApplicationBus.Channel.create('channelName');
298
+ *
299
+ * providerBus.onConnection((identity, payload) => {
300
+ * // can reject a connection here by throwing an error
301
+ * console.log('Client connection request identity: ', JSON.stringify(identity));
302
+ * console.log('Client connection request payload: ', JSON.stringify(payload));
303
+ * });
304
+ *
305
+ * providerBus.register('topic', (payload, identity) => {
306
+ * // register a callback for a 'topic' to which clients can dispatch an action
307
+ * console.log('Action dispatched by client: ', JSON.stringify(identity));
308
+ * console.log('Payload sent in dispatch: ', JSON.stringify(payload));
309
+ * return {
310
+ * echo: payload
311
+ * };
312
+ * });
313
+ * })();
314
+ * ```
315
+ */
152
316
  async create(channelName, options) {
153
317
  if (!channelName) {
154
318
  throw new Error('Please provide a channelName to create a channel');
@@ -6,22 +6,194 @@ 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
+ /**
10
+ * Instance created to enable use of a channel as a provider. Allows for communication with the {@link ChannelClient ChannelClients} by invoking an action on
11
+ * a single client via {@link ChannelProvider#dispatch dispatch} or all clients via {@link ChannelProvider#publish publish}
12
+ * and to listen for communication from clients by registering an action via {@link ChannelProvider#register register}.
13
+ *
14
+ * Synchronous Methods:
15
+ * * {@link ChannelProvider#onConnection onConnection(listener)}
16
+ * * {@link ChannelProvider#onDisconnection onDisconnection(listener)}
17
+ * * {@link ChannelProvider#publish publish(action, payload)}
18
+ * * {@link ChannelProvider#register register(action, listener)}
19
+ * * {@link ChannelProvider#remove remove(action)}
20
+ *
21
+ * Asynchronous Methods:
22
+ * * {@link ChannelProvider#destroy destroy()}
23
+ * * {@link ChannelProvider#dispatch dispatch(to, action, payload)}
24
+ * * {@link ChannelProvider#getAllClientInfo getAllClientInfo()}
25
+ *
26
+ * Middleware:
27
+ * <br>Middleware functions receive the following arguments: (action, payload, senderId).
28
+ * The return value of the middleware function will be passed on as the payload from beforeAction, to the action listener, to afterAction
29
+ * unless it is undefined, in which case the most recently defined payload is used. Middleware can be used for side effects.
30
+ * * {@link ChannelProvider#setDefaultAction setDefaultAction(middleware)}
31
+ * * {@link ChannelProvider#onError onError(middleware)}
32
+ * * {@link ChannelProvider#beforeAction beforeAction(middleware)}
33
+ * * {@link ChannelProvider#afterAction afterAction(middleware)}
34
+ */
9
35
  export declare class ChannelProvider extends ChannelBase {
10
36
  #private;
11
37
  private static removalMap;
12
38
  private connectListener;
13
39
  private disconnectListener;
40
+ /**
41
+ * a read-only array containing all the identities of connecting clients.
42
+ */
14
43
  get connections(): OpenFin.ClientConnectionPayload[];
15
44
  static handleClientDisconnection(channel: ChannelProvider, payload: any): void;
16
45
  static setProviderRemoval(provider: ChannelProvider, remove: Function): void;
46
+ /**
47
+ * @internal
48
+ */
17
49
  constructor(providerIdentity: ProviderIdentity, wire: Transport, strategy: AnyStrategy);
50
+ /**
51
+ * Dispatch an action to a specified client. Returns a promise for the result of executing that action on the client side.
52
+ *
53
+ * @param to - Identity of the target client.
54
+ * @param action - Name of the action to be invoked by the client.
55
+ * @param payload - Payload to be sent along with the action.
56
+ *
57
+ * @remarks
58
+ *
59
+ * Because multiple clients can share the same `name` and `uuid`, when dispatching from a provider to a client,
60
+ * the `identity` you provide must include the client's unique `endpointId` property. This `endpointId` is
61
+ * passed to the provider in both the `Provider.onConnection` callback and in any registered action callbacks.
62
+ *
63
+ * @example
64
+ *
65
+ * ```js
66
+ * (async ()=> {
67
+ * const provider = await fin.InterApplicationBus.Channel.create('channelName');
68
+ *
69
+ * await provider.register('provider-action', async (payload, identity) => {
70
+ * console.log(payload, identity);
71
+ * return await provider.dispatch(identity, 'client-action', 'Hello, World!');
72
+ * });
73
+ * })();
74
+ * ```
75
+ */
18
76
  dispatch(to: OpenFin.ClientIdentity | OpenFin.Identity, action: string, payload?: any): Promise<any>;
19
77
  protected processAction: (action: string, payload: any, senderIdentity: OpenFin.ClientIdentity | OpenFin.ClientIdentityMultiRuntime) => Promise<any>;
20
78
  processConnection(senderId: OpenFin.ClientConnectionPayload, payload: any): Promise<any>;
79
+ /**
80
+ * Publish an action and payload to every connected client.
81
+ * Synchronously returns an array of promises for each action (see dispatch).
82
+ *
83
+ * @param action
84
+ * @param payload
85
+ *
86
+ * @example
87
+ * ```js
88
+ * (async ()=> {
89
+ * const provider = await fin.InterApplicationBus.Channel.create('channelName');
90
+ *
91
+ * await provider.register('provider-action', async (payload, identity) => {
92
+ * console.log(payload, identity);
93
+ * return await Promise.all(provider.publish('client-action', { message: 'Broadcast from provider'}));
94
+ * });
95
+ * })();
96
+ * ```
97
+ */
21
98
  publish(action: string, payload: any): Promise<any>[];
99
+ /**
100
+ * Register a listener that is called on every new client connection.
101
+ *
102
+ * @remarks It is passed the identity of the connecting client and a payload if it was provided to Channel.connect.
103
+ * If you wish to reject the connection, throw an error. Be sure to synchronously provide an onConnection upon receipt of
104
+ * the channelProvider to ensure all potential client connections are caught by the listener.
105
+ *
106
+ * Because multiple clients can exist at the same `name` and `uuid`, in order to distinguish between individual clients,
107
+ * the `identity` argument in a provider's `onConnection` callback contains an `endpointId` property. When dispatching from a
108
+ * provider to a client, the `endpointId` property must be provided in order to send an action to a specific client.
109
+ *
110
+ * @example
111
+ * ```js
112
+ * (async ()=> {
113
+ * const provider = await fin.InterApplicationBus.Channel.create('channelName');
114
+ *
115
+ * provider.onConnection(identity => {
116
+ * console.log('Client connected', identity);
117
+ * });
118
+ * })();
119
+ * ```
120
+ *
121
+ * Reject connection:
122
+ * ```js
123
+ * (async ()=> {
124
+ * const provider = await fin.InterApplicationBus.Channel.create('channelName');
125
+ *
126
+ * provider.onConnection(identity => {
127
+ * throw new Error('Connection Rejected');
128
+ * });
129
+ * })();
130
+ * ```
131
+ * @param listener
132
+ */
22
133
  onConnection(listener: ConnectionListener): void;
134
+ /**
135
+ * Register a listener that is called on client disconnection. It is passed the disconnection event of the disconnecting
136
+ * client.
137
+ *
138
+ * @param listener
139
+ *
140
+ * @example
141
+ *
142
+ * ```js
143
+ * (async ()=> {
144
+ * const provider = await fin.InterApplicationBus.Channel.create('channelName');
145
+ *
146
+ * await provider.onDisconnection(evt => {
147
+ * console.log('Client disconnected', `uuid: ${evt.uuid}, name: ${evt.name}`);
148
+ * });
149
+ * })();
150
+ * ```
151
+ */
23
152
  onDisconnection(listener: DisconnectionListener): void;
153
+ /**
154
+ * Destroy the channel, raises `disconnected` events on all connected channel clients.
155
+ *
156
+ * @example
157
+ *
158
+ * ```js
159
+ * (async ()=> {
160
+ * const provider = await fin.InterApplicationBus.Channel.create('channelName');
161
+ *
162
+ * await provider.destroy();
163
+ * })();
164
+ * ```
165
+ */
24
166
  destroy(): Promise<void>;
167
+ /**
168
+ * Returns an array with info on every Client connected to the Provider
169
+ *
170
+ * @example
171
+ *
172
+ * ```js
173
+ * const provider = await fin.InterApplicationBus.Channel.create('openfin');
174
+ * const client = await fin.InterApplicationBus.Channel.connect('openfin');
175
+ * const clientInfo = await provider.getAllClientInfo();
176
+ *
177
+ * console.log(clientInfo);
178
+ *
179
+ * // [
180
+ * // {
181
+ * // "uuid": "openfin",
182
+ * // "name": "openfin-view",
183
+ * // "endpointId": "6d4c7ca8-4a74-4634-87f8-760558229613",
184
+ * // "entityType": "view",
185
+ * // "url": "https://openfin.co"
186
+ * // },
187
+ * // {
188
+ * // "uuid": "openfin2",
189
+ * // "name": "openfin-view2",
190
+ * // "endpointId": "4z5d8ab9-2b81-3691-91ex-142179382511",
191
+ * // "entityType": "view",
192
+ * // "url": "https://example.com"
193
+ * // }
194
+ * //]
195
+ * ```
196
+ */
25
197
  getAllClientInfo(): Promise<Array<OpenFin.ClientInfo>>;
26
198
  private checkForClientConnection;
27
199
  private isClientConnected;