@openfin/core 25.68.26

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 (227) hide show
  1. package/LICENSE +13 -0
  2. package/NOTICE +16 -0
  3. package/OpenFin.d.ts +1340 -0
  4. package/README.md +41 -0
  5. package/docs.README(OLD).md +82 -0
  6. package/fin.d.ts +4 -0
  7. package/package.json +33 -0
  8. package/resources/win/OpenFinRVM.exe +0 -0
  9. package/src/api/application/Factory.d.ts +145 -0
  10. package/src/api/application/Factory.js +229 -0
  11. package/src/api/application/Instance.d.ts +302 -0
  12. package/src/api/application/Instance.js +412 -0
  13. package/src/api/application/index.d.ts +3 -0
  14. package/src/api/application/index.js +15 -0
  15. package/src/api/base.d.ts +43 -0
  16. package/src/api/base.js +177 -0
  17. package/src/api/clipboard/index.d.ts +69 -0
  18. package/src/api/clipboard/index.js +88 -0
  19. package/src/api/events/application.d.ts +69 -0
  20. package/src/api/events/application.js +2 -0
  21. package/src/api/events/base.d.ts +17 -0
  22. package/src/api/events/base.js +2 -0
  23. package/src/api/events/channel.d.ts +10 -0
  24. package/src/api/events/channel.js +2 -0
  25. package/src/api/events/emitterMap.d.ts +11 -0
  26. package/src/api/events/emitterMap.js +35 -0
  27. package/src/api/events/eventAggregator.d.ts +5 -0
  28. package/src/api/events/eventAggregator.js +43 -0
  29. package/src/api/events/externalApplication.d.ts +5 -0
  30. package/src/api/events/externalApplication.js +2 -0
  31. package/src/api/events/frame.d.ts +9 -0
  32. package/src/api/events/frame.js +2 -0
  33. package/src/api/events/globalHotkey.d.ts +10 -0
  34. package/src/api/events/globalHotkey.js +2 -0
  35. package/src/api/events/platform.d.ts +18 -0
  36. package/src/api/events/platform.js +2 -0
  37. package/src/api/events/system.d.ts +22 -0
  38. package/src/api/events/system.js +2 -0
  39. package/src/api/events/view.d.ts +56 -0
  40. package/src/api/events/view.js +2 -0
  41. package/src/api/events/webcontents.d.ts +48 -0
  42. package/src/api/events/webcontents.js +2 -0
  43. package/src/api/events/window.d.ts +169 -0
  44. package/src/api/events/window.js +2 -0
  45. package/src/api/external-application/Factory.d.ts +26 -0
  46. package/src/api/external-application/Factory.js +40 -0
  47. package/src/api/external-application/Instance.d.ts +102 -0
  48. package/src/api/external-application/Instance.js +109 -0
  49. package/src/api/external-application/index.d.ts +3 -0
  50. package/src/api/external-application/index.js +15 -0
  51. package/src/api/fin.d.ts +49 -0
  52. package/src/api/fin.js +43 -0
  53. package/src/api/frame/Factory.d.ts +36 -0
  54. package/src/api/frame/Factory.js +69 -0
  55. package/src/api/frame/Instance.d.ts +121 -0
  56. package/src/api/frame/Instance.js +130 -0
  57. package/src/api/frame/index.d.ts +3 -0
  58. package/src/api/frame/index.js +15 -0
  59. package/src/api/global-hotkey/index.d.ts +38 -0
  60. package/src/api/global-hotkey/index.js +58 -0
  61. package/src/api/interappbus/channel/channel.d.ts +26 -0
  62. package/src/api/interappbus/channel/channel.js +77 -0
  63. package/src/api/interappbus/channel/channels-docs.d.ts +318 -0
  64. package/src/api/interappbus/channel/channels-docs.js +376 -0
  65. package/src/api/interappbus/channel/client.d.ts +22 -0
  66. package/src/api/interappbus/channel/client.js +84 -0
  67. package/src/api/interappbus/channel/connection-manager.d.ts +28 -0
  68. package/src/api/interappbus/channel/connection-manager.js +244 -0
  69. package/src/api/interappbus/channel/index.d.ts +22 -0
  70. package/src/api/interappbus/channel/index.js +121 -0
  71. package/src/api/interappbus/channel/protocols/classic/message-receiver.d.ts +13 -0
  72. package/src/api/interappbus/channel/protocols/classic/message-receiver.js +73 -0
  73. package/src/api/interappbus/channel/protocols/classic/strategy.d.ts +22 -0
  74. package/src/api/interappbus/channel/protocols/classic/strategy.js +84 -0
  75. package/src/api/interappbus/channel/protocols/combined/strategy.d.ts +20 -0
  76. package/src/api/interappbus/channel/protocols/combined/strategy.js +58 -0
  77. package/src/api/interappbus/channel/protocols/index.d.ts +44 -0
  78. package/src/api/interappbus/channel/protocols/index.js +2 -0
  79. package/src/api/interappbus/channel/protocols/protocol-manager.d.ts +10 -0
  80. package/src/api/interappbus/channel/protocols/protocol-manager.js +43 -0
  81. package/src/api/interappbus/channel/protocols/rtc/endpoint.d.ts +23 -0
  82. package/src/api/interappbus/channel/protocols/rtc/endpoint.js +135 -0
  83. package/src/api/interappbus/channel/protocols/rtc/ice-manager.d.ts +30 -0
  84. package/src/api/interappbus/channel/protocols/rtc/ice-manager.js +131 -0
  85. package/src/api/interappbus/channel/protocols/rtc/strategy.d.ts +22 -0
  86. package/src/api/interappbus/channel/protocols/rtc/strategy.js +87 -0
  87. package/src/api/interappbus/channel/protocols/strategy-types.d.ts +13 -0
  88. package/src/api/interappbus/channel/protocols/strategy-types.js +2 -0
  89. package/src/api/interappbus/channel/protocols/strategy.d.ts +15 -0
  90. package/src/api/interappbus/channel/protocols/strategy.js +2 -0
  91. package/src/api/interappbus/channel/provider.d.ts +31 -0
  92. package/src/api/interappbus/channel/provider.js +165 -0
  93. package/src/api/interappbus/index.d.ts +85 -0
  94. package/src/api/interappbus/index.js +175 -0
  95. package/src/api/interop/Factory.d.ts +37 -0
  96. package/src/api/interop/Factory.js +54 -0
  97. package/src/api/interop/InteropBroker.d.ts +363 -0
  98. package/src/api/interop/InteropBroker.js +914 -0
  99. package/src/api/interop/InteropClient.d.ts +268 -0
  100. package/src/api/interop/InteropClient.js +450 -0
  101. package/src/api/interop/SessionContextGroupBroker.d.ts +26 -0
  102. package/src/api/interop/SessionContextGroupBroker.js +107 -0
  103. package/src/api/interop/SessionContextGroupClient.d.ts +20 -0
  104. package/src/api/interop/SessionContextGroupClient.js +85 -0
  105. package/src/api/interop/fdc3/fdc3-1.2.d.ts +187 -0
  106. package/src/api/interop/fdc3/fdc3-1.2.js +385 -0
  107. package/src/api/interop/fdc3/fdc3.js +17 -0
  108. package/src/api/interop/fdc3/utils.d.ts +6 -0
  109. package/src/api/interop/fdc3/utils.js +17 -0
  110. package/src/api/interop/index.d.ts +4 -0
  111. package/src/api/interop/index.js +16 -0
  112. package/src/api/interop/utils.d.ts +11 -0
  113. package/src/api/interop/utils.js +36 -0
  114. package/src/api/me.d.ts +35 -0
  115. package/src/api/me.js +60 -0
  116. package/src/api/platform/Factory.d.ts +109 -0
  117. package/src/api/platform/Factory.js +188 -0
  118. package/src/api/platform/Instance.d.ts +122 -0
  119. package/src/api/platform/Instance.js +299 -0
  120. package/src/api/platform/common-utils.d.ts +6 -0
  121. package/src/api/platform/common-utils.js +16 -0
  122. package/src/api/platform/index.d.ts +3 -0
  123. package/src/api/platform/index.js +15 -0
  124. package/src/api/platform/layout/Factory.d.ts +108 -0
  125. package/src/api/platform/layout/Factory.js +189 -0
  126. package/src/api/platform/layout/Instance.d.ts +48 -0
  127. package/src/api/platform/layout/Instance.js +99 -0
  128. package/src/api/platform/layout/index.d.ts +3 -0
  129. package/src/api/platform/layout/index.js +15 -0
  130. package/src/api/platform/layout/shapes.d.ts +11 -0
  131. package/src/api/platform/layout/shapes.js +2 -0
  132. package/src/api/snapshot-source/Factory.d.ts +36 -0
  133. package/src/api/snapshot-source/Factory.js +65 -0
  134. package/src/api/snapshot-source/Instance.d.ts +30 -0
  135. package/src/api/snapshot-source/Instance.js +134 -0
  136. package/src/api/snapshot-source/index.d.ts +3 -0
  137. package/src/api/snapshot-source/index.js +15 -0
  138. package/src/api/snapshot-source/utils.d.ts +1 -0
  139. package/src/api/snapshot-source/utils.js +5 -0
  140. package/src/api/system/application.d.ts +6 -0
  141. package/src/api/system/application.js +2 -0
  142. package/src/api/system/entity.d.ts +11 -0
  143. package/src/api/system/entity.js +2 -0
  144. package/src/api/system/index.d.ts +957 -0
  145. package/src/api/system/index.js +1241 -0
  146. package/src/api/system/installedApps.d.ts +6 -0
  147. package/src/api/system/installedApps.js +2 -0
  148. package/src/api/system/log.d.ts +11 -0
  149. package/src/api/system/log.js +2 -0
  150. package/src/api/system/process.d.ts +15 -0
  151. package/src/api/system/process.js +2 -0
  152. package/src/api/system/proxy.d.ts +15 -0
  153. package/src/api/system/proxy.js +2 -0
  154. package/src/api/system/queryPermissionTypes.d.ts +1 -0
  155. package/src/api/system/queryPermissionTypes.js +2 -0
  156. package/src/api/system/registry-info.d.ts +7 -0
  157. package/src/api/system/registry-info.js +2 -0
  158. package/src/api/system/window.d.ts +16 -0
  159. package/src/api/system/window.js +2 -0
  160. package/src/api/view/Factory.d.ts +49 -0
  161. package/src/api/view/Factory.js +103 -0
  162. package/src/api/view/Instance.d.ts +379 -0
  163. package/src/api/view/Instance.js +415 -0
  164. package/src/api/view/index.d.ts +3 -0
  165. package/src/api/view/index.js +15 -0
  166. package/src/api/webcontents/main.d.ts +36 -0
  167. package/src/api/webcontents/main.js +82 -0
  168. package/src/api/window/Factory.d.ts +44 -0
  169. package/src/api/window/Factory.js +91 -0
  170. package/src/api/window/Instance.d.ts +966 -0
  171. package/src/api/window/Instance.js +1202 -0
  172. package/src/api/window/bounds-changed.d.ts +10 -0
  173. package/src/api/window/bounds-changed.js +6 -0
  174. package/src/api/window/index.d.ts +5 -0
  175. package/src/api/window/index.js +17 -0
  176. package/src/api/window/shapes.d.ts +13 -0
  177. package/src/api/window/shapes.js +2 -0
  178. package/src/environment/environment.d.ts +28 -0
  179. package/src/environment/environment.js +4 -0
  180. package/src/environment/node-env.d.ts +25 -0
  181. package/src/environment/node-env.js +64 -0
  182. package/src/environment/openfin-env.d.ts +29 -0
  183. package/src/environment/openfin-env.js +105 -0
  184. package/src/mock.d.ts +4 -0
  185. package/src/mock.js +91 -0
  186. package/src/shapes/ERROR_BOX_TYPES.d.ts +6 -0
  187. package/src/shapes/ERROR_BOX_TYPES.js +10 -0
  188. package/src/shapes/EntityType.d.ts +1 -0
  189. package/src/shapes/EntityType.js +2 -0
  190. package/src/shapes/LayoutPresetType.d.ts +1 -0
  191. package/src/shapes/LayoutPresetType.js +2 -0
  192. package/src/shapes/Platform.d.ts +112 -0
  193. package/src/shapes/Platform.js +16 -0
  194. package/src/shapes/WebOptions.d.ts +12 -0
  195. package/src/shapes/WebOptions.js +2 -0
  196. package/src/shapes/WindowOptions.d.ts +42 -0
  197. package/src/shapes/WindowOptions.js +2 -0
  198. package/src/shapes/protocol.d.ts +178 -0
  199. package/src/shapes/protocol.js +2 -0
  200. package/src/transport/fin_store.d.ts +4 -0
  201. package/src/transport/fin_store.js +16 -0
  202. package/src/transport/transport-errors.d.ts +17 -0
  203. package/src/transport/transport-errors.js +39 -0
  204. package/src/transport/transport.d.ts +57 -0
  205. package/src/transport/transport.js +195 -0
  206. package/src/transport/wire.d.ts +76 -0
  207. package/src/transport/wire.js +39 -0
  208. package/src/util/asyncFilter.d.ts +1 -0
  209. package/src/util/asyncFilter.js +7 -0
  210. package/src/util/errors.d.ts +9 -0
  211. package/src/util/errors.js +14 -0
  212. package/src/util/exhaustive.d.ts +1 -0
  213. package/src/util/exhaustive.js +7 -0
  214. package/src/util/http.d.ts +11 -0
  215. package/src/util/http.js +83 -0
  216. package/src/util/normalize-config.d.ts +3 -0
  217. package/src/util/normalize-config.js +47 -0
  218. package/src/util/promises.d.ts +5 -0
  219. package/src/util/promises.js +27 -0
  220. package/src/util/ref-counter.d.ts +7 -0
  221. package/src/util/ref-counter.js +51 -0
  222. package/src/util/runtimeVersioning.d.ts +3 -0
  223. package/src/util/runtimeVersioning.js +25 -0
  224. package/src/util/utilTypes.d.ts +8 -0
  225. package/src/util/utilTypes.js +2 -0
  226. package/src/util/validate.d.ts +3 -0
  227. package/src/util/validate.js +11 -0
@@ -0,0 +1,22 @@
1
+ import { ChannelBase } from './channel';
2
+ import Transport from '../../../transport/transport';
3
+ import { AnyStrategy } from './protocols/strategy-types';
4
+ import ProviderIdentity = OpenFin.ProviderIdentity;
5
+ declare type DisconnectionListener = (providerIdentity: ProviderIdentity) => any;
6
+ interface RoutingInfo extends ProviderIdentity {
7
+ endpointId: string;
8
+ }
9
+ export default class ChannelClient extends ChannelBase {
10
+ #private;
11
+ private disconnectListener;
12
+ private endpointId;
13
+ static closeChannelByEndpointId(id: string): void;
14
+ static handleProviderDisconnect(channel: ChannelClient, eventPayload: ProviderIdentity): void;
15
+ constructor(routingInfo: RoutingInfo, wire: Transport, strategy: AnyStrategy);
16
+ protected processAction: (action: string, payload: any, senderIdentity: ProviderIdentity | OpenFin.ClientIdentity) => Promise<any>;
17
+ get providerIdentity(): ProviderIdentity;
18
+ dispatch(action: string, payload?: any): Promise<any>;
19
+ onDisconnection(listener: DisconnectionListener): void;
20
+ disconnect(): Promise<void>;
21
+ }
22
+ export {};
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) {
3
+ if (!privateMap.has(receiver)) {
4
+ throw new TypeError("attempted to set private field on non-instance");
5
+ }
6
+ privateMap.set(receiver, value);
7
+ return value;
8
+ };
9
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) {
10
+ if (!privateMap.has(receiver)) {
11
+ throw new TypeError("attempted to get private field on non-instance");
12
+ }
13
+ return privateMap.get(receiver);
14
+ };
15
+ var _protectedObj, _strategy, _close;
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ const channel_1 = require("./channel");
18
+ const channelClientsByEndpointId = new Map();
19
+ class ChannelClient extends channel_1.ChannelBase {
20
+ constructor(routingInfo, wire, strategy) {
21
+ super();
22
+ _protectedObj.set(this, void 0);
23
+ _strategy.set(this, void 0);
24
+ // needs to be bound;
25
+ this.processAction = (action, payload, senderIdentity) => super.processAction(action, payload, senderIdentity);
26
+ _close.set(this, () => {
27
+ channelClientsByEndpointId.delete(this.endpointId);
28
+ __classPrivateFieldGet(this, _strategy).close();
29
+ });
30
+ __classPrivateFieldSet(this, _protectedObj, new channel_1.ProtectedItems(routingInfo, wire));
31
+ this.disconnectListener = () => undefined;
32
+ this.endpointId = routingInfo.endpointId;
33
+ __classPrivateFieldSet(this, _strategy, strategy);
34
+ channelClientsByEndpointId.set(this.endpointId, this);
35
+ strategy.receive(this.processAction);
36
+ }
37
+ static closeChannelByEndpointId(id) {
38
+ const channel = channelClientsByEndpointId.get(id);
39
+ if (channel) {
40
+ __classPrivateFieldGet(channel, _close).call(channel);
41
+ }
42
+ }
43
+ // closes the channel and invokes the disconnect listener if an event payload is passed.
44
+ static handleProviderDisconnect(channel, eventPayload) {
45
+ channel.disconnectListener(eventPayload);
46
+ __classPrivateFieldGet(channel, _close).call(channel);
47
+ }
48
+ get providerIdentity() {
49
+ const protectedObj = __classPrivateFieldGet(this, _protectedObj);
50
+ return protectedObj.providerIdentity;
51
+ }
52
+ async dispatch(action, payload) {
53
+ if (__classPrivateFieldGet(this, _strategy).isEndpointConnected(this.providerIdentity.channelId)) {
54
+ return __classPrivateFieldGet(this, _strategy).send(this.providerIdentity.channelId, action, payload);
55
+ }
56
+ throw new Error('The client you are trying to dispatch from is disconnected from the target provider.');
57
+ }
58
+ onDisconnection(listener) {
59
+ this.disconnectListener = (payload) => {
60
+ try {
61
+ listener(payload);
62
+ }
63
+ catch (err) {
64
+ throw new Error(`Error while calling the onDisconnection callback: ${err.message}`);
65
+ }
66
+ finally {
67
+ this.disconnectListener = () => undefined;
68
+ }
69
+ };
70
+ }
71
+ async disconnect() {
72
+ const protectedObj = __classPrivateFieldGet(this, _protectedObj);
73
+ const { channelName, uuid, name } = protectedObj.providerIdentity;
74
+ await protectedObj.wire.sendAction('disconnect-from-channel', {
75
+ channelName,
76
+ uuid,
77
+ name,
78
+ endpointId: this.endpointId
79
+ });
80
+ __classPrivateFieldGet(this, _close).call(this);
81
+ }
82
+ }
83
+ exports.default = ChannelClient;
84
+ _protectedObj = new WeakMap(), _strategy = new WeakMap(), _close = new WeakMap();
@@ -0,0 +1,28 @@
1
+ import { ChannelMessage } from '.';
2
+ import Transport from '../../../transport/transport';
3
+ import { Base } from '../../base';
4
+ import { ClientOffer, LocalSupportedProtocol } from './protocols/index';
5
+ import { RTCPacket } from './protocols/rtc/endpoint';
6
+ import { ChannelProvider } from './provider';
7
+ import { AnyStrategy } from './protocols/strategy-types';
8
+ export declare type ProviderEntry = {
9
+ provider: ChannelProvider;
10
+ strategy: AnyStrategy;
11
+ supportedProtocols: LocalSupportedProtocol[];
12
+ };
13
+ export declare class ConnectionManager extends Base {
14
+ #private;
15
+ private protocolManager;
16
+ private providerMap;
17
+ private static getProtocolOptionsFromStrings;
18
+ constructor(wire: Transport);
19
+ createProvider(options: OpenFin.ChannelCreateOptions | undefined, providerIdentity: any): ChannelProvider;
20
+ createClientOffer(options?: OpenFin.ChannelConnectOptions): Promise<{
21
+ offer: ClientOffer;
22
+ rtc?: RTCPacket;
23
+ }>;
24
+ createClientStrategy(rtcPacket: RTCPacket | undefined, routingInfo: any): Promise<AnyStrategy>;
25
+ removeChannelFromProviderMap: (channelId: string) => void;
26
+ onmessage: (msg: ChannelMessage) => boolean;
27
+ private processChannelConnection;
28
+ }
@@ -0,0 +1,244 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) {
3
+ if (!privateMap.has(receiver)) {
4
+ throw new TypeError("attempted to set private field on non-instance");
5
+ }
6
+ privateMap.set(receiver, value);
7
+ return value;
8
+ };
9
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) {
10
+ if (!privateMap.has(receiver)) {
11
+ throw new TypeError("attempted to get private field on non-instance");
12
+ }
13
+ return privateMap.get(receiver);
14
+ };
15
+ var _messageReceiver, _rtcConnectionManager;
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.ConnectionManager = void 0;
18
+ const exhaustive_1 = require("../../../util/exhaustive");
19
+ const base_1 = require("../../base");
20
+ const strategy_1 = require("./protocols/classic/strategy");
21
+ const strategy_2 = require("./protocols/rtc/strategy");
22
+ const ice_manager_1 = require("./protocols/rtc/ice-manager");
23
+ const provider_1 = require("./provider");
24
+ const message_receiver_1 = require("./protocols/classic/message-receiver");
25
+ const protocol_manager_1 = require("./protocols/protocol-manager");
26
+ const strategy_3 = require("./protocols/combined/strategy");
27
+ class ConnectionManager extends base_1.Base {
28
+ constructor(wire) {
29
+ super(wire);
30
+ _messageReceiver.set(this, void 0);
31
+ _rtcConnectionManager.set(this, void 0);
32
+ this.removeChannelFromProviderMap = (channelId) => {
33
+ this.providerMap.delete(channelId);
34
+ };
35
+ this.onmessage = (msg) => {
36
+ if (msg.action === 'process-channel-connection') {
37
+ this.processChannelConnection(msg);
38
+ return true;
39
+ }
40
+ return false;
41
+ };
42
+ this.providerMap = new Map();
43
+ this.protocolManager = new protocol_manager_1.ProtocolManager(this.isNodeEnvironment() ? ['classic'] : ['rtc', 'classic']);
44
+ __classPrivateFieldSet(this, _messageReceiver, new message_receiver_1.MessageReceiver(wire));
45
+ __classPrivateFieldSet(this, _rtcConnectionManager, new ice_manager_1.RTCICEManager(wire));
46
+ wire.registerMessageHandler(this.onmessage.bind(this));
47
+ }
48
+ static getProtocolOptionsFromStrings(protocols) {
49
+ return protocols.map(protocol => {
50
+ switch (protocol) {
51
+ case 'rtc':
52
+ return strategy_2.RTCInfo;
53
+ case 'classic':
54
+ return strategy_1.ClassicInfo;
55
+ default:
56
+ return exhaustive_1.exhaustiveCheck(protocol, ['rtc', 'classic']);
57
+ }
58
+ });
59
+ }
60
+ createProvider(options, providerIdentity) {
61
+ const opts = Object.assign(this.wire.environment.getDefaultChannelOptions().create, options || {});
62
+ const protocols = this.protocolManager.getProviderProtocols(opts === null || opts === void 0 ? void 0 : opts.protocols);
63
+ const createSingleStrategy = (stratType) => {
64
+ switch (stratType) {
65
+ case 'rtc':
66
+ return new strategy_2.RTCStrategy();
67
+ case 'classic':
68
+ return new strategy_1.ClassicStrategy(this.wire, __classPrivateFieldGet(this, _messageReceiver),
69
+ // Providers do not have an endpointId, use channelId as endpointId in the strategy.
70
+ providerIdentity.channelId, providerIdentity);
71
+ default:
72
+ return exhaustive_1.exhaustiveCheck(stratType, ['rtc', 'classic']);
73
+ }
74
+ };
75
+ const strategies = protocols.map(createSingleStrategy);
76
+ let strategy;
77
+ if (strategies.length === 2) {
78
+ const [a, b] = strategies;
79
+ strategy = strategy_3.default.combine(a, b);
80
+ }
81
+ else if (strategies.length === 1) {
82
+ [strategy] = strategies;
83
+ }
84
+ else {
85
+ // Should be impossible.
86
+ throw new Error('failed to combine strategies');
87
+ }
88
+ const channel = new provider_1.ChannelProvider(providerIdentity, this.wire, strategy);
89
+ const key = providerIdentity.channelId;
90
+ this.providerMap.set(key, { provider: channel, strategy, supportedProtocols: ConnectionManager.getProtocolOptionsFromStrings(protocols) });
91
+ provider_1.ChannelProvider.setProviderRemoval(channel, this.removeChannelFromProviderMap.bind(this));
92
+ return channel;
93
+ }
94
+ async createClientOffer(options) {
95
+ const protocols = this.protocolManager.getClientProtocols(options === null || options === void 0 ? void 0 : options.protocols);
96
+ let rtcPacket;
97
+ const supportedProtocols = await Promise.all(protocols.map(async (type) => {
98
+ switch (type) {
99
+ case 'rtc': {
100
+ const { rtcClient, channels, offer, rtcConnectionId, channelsOpened } = await __classPrivateFieldGet(this, _rtcConnectionManager).startClientOffer();
101
+ rtcPacket = { rtcClient, channels, channelsOpened };
102
+ return {
103
+ type: 'rtc',
104
+ version: strategy_2.RTCInfo.version,
105
+ payload: { offer, rtcConnectionId }
106
+ };
107
+ }
108
+ case 'classic':
109
+ return { type: 'classic', version: strategy_1.ClassicInfo.version };
110
+ default:
111
+ return exhaustive_1.exhaustiveCheck(type, ['rtc', 'classic']);
112
+ }
113
+ }));
114
+ return {
115
+ offer: {
116
+ supportedProtocols,
117
+ maxProtocols: 2
118
+ },
119
+ rtc: rtcPacket
120
+ };
121
+ }
122
+ async createClientStrategy(rtcPacket, routingInfo) {
123
+ var _a;
124
+ if (!routingInfo.endpointId) {
125
+ routingInfo.endpointId = this.wire.environment.getNextMessageId();
126
+ // For New Clients connecting to Old Providers. To prevent multi-dispatching and publishing, we delete previously-connected
127
+ // clients that are in the same context as the newly-connected client.
128
+ __classPrivateFieldGet(this, _messageReceiver).checkForPreviousClientConnection(routingInfo.channelId);
129
+ }
130
+ const answer = (_a = routingInfo.answer) !== null && _a !== void 0 ? _a : {
131
+ supportedProtocols: [{ type: 'classic', version: 1 }]
132
+ };
133
+ const createStrategyFromAnswer = async (protocol) => {
134
+ if (protocol.type === 'rtc' && rtcPacket) {
135
+ await __classPrivateFieldGet(this, _rtcConnectionManager).finishClientOffer(rtcPacket.rtcClient, protocol.payload.answer, rtcPacket.channelsOpened);
136
+ return new strategy_2.RTCStrategy();
137
+ }
138
+ if (protocol.type === 'classic') {
139
+ return new strategy_1.ClassicStrategy(this.wire, __classPrivateFieldGet(this, _messageReceiver), routingInfo.endpointId, routingInfo);
140
+ }
141
+ return null;
142
+ };
143
+ const allProtocols = (await Promise.all(answer.supportedProtocols.map(createStrategyFromAnswer))).filter((x) => x !== null);
144
+ // Clean up logic if provider didn't support rtc.
145
+ if (rtcPacket && !allProtocols.some((x) => x instanceof strategy_2.RTCStrategy)) {
146
+ if (rtcPacket) {
147
+ rtcPacket.rtcClient.close();
148
+ }
149
+ }
150
+ let strategy;
151
+ if (allProtocols.length >= 2) {
152
+ strategy = strategy_3.default.combine(allProtocols[0], allProtocols[1]);
153
+ }
154
+ else if (allProtocols.length) {
155
+ [strategy] = allProtocols;
156
+ }
157
+ else {
158
+ // Should be impossible.
159
+ throw new Error('No compatible protocols');
160
+ }
161
+ // as casting rtcPacket because we won't have an rtcStrategy if rtcPacket is undefined;
162
+ const endpointPayload = { endpointIdentity: routingInfo, rtc: rtcPacket };
163
+ strategy.addEndpoint(routingInfo.channelId, endpointPayload);
164
+ return strategy;
165
+ }
166
+ async processChannelConnection(msg) {
167
+ const { clientIdentity, providerIdentity, ackToSender, payload, offer: clientOffer } = msg.payload;
168
+ if (!clientIdentity.endpointId) {
169
+ // Should be polyfilled by core but not in cases of node connecting to an old runtime.
170
+ clientIdentity.endpointId = this.wire.environment.getNextMessageId();
171
+ clientIdentity.isLocalEndpointId = true;
172
+ }
173
+ else {
174
+ clientIdentity.isLocalEndpointId = false;
175
+ }
176
+ const key = providerIdentity.channelId;
177
+ const bus = this.providerMap.get(key);
178
+ if (!bus) {
179
+ ackToSender.payload.success = false;
180
+ ackToSender.payload.reason = `Channel "${providerIdentity.channelName}" has been destroyed.`;
181
+ return this.wire.sendRaw(ackToSender);
182
+ }
183
+ const { provider, strategy, supportedProtocols } = bus;
184
+ try {
185
+ if (!(provider instanceof provider_1.ChannelProvider)) {
186
+ throw Error('Cannot connect to a channel client');
187
+ }
188
+ const offer = clientOffer !== null && clientOffer !== void 0 ? clientOffer : {
189
+ supportedProtocols: [{ type: 'classic', version: 1 }],
190
+ maxProtocols: 1
191
+ };
192
+ const overlappingProtocols = this.protocolManager.getCompatibleProtocols(supportedProtocols, offer);
193
+ if (!overlappingProtocols.length) {
194
+ throw new Error('This provider does not support any of the offered protocols.');
195
+ }
196
+ const res = await provider.processConnection(clientIdentity, payload);
197
+ ackToSender.payload.payload = ackToSender.payload.payload || {};
198
+ // Loop through all supported protocols and accumulate them into the answer
199
+ // addEndpoint is tricky but we need to wait for channel resolution before adding the endpoint.
200
+ let clientAnswer = {
201
+ supportedProtocols: [],
202
+ endpointPayloadPromise: Promise.resolve({ endpointIdentity: clientIdentity })
203
+ };
204
+ clientAnswer = await overlappingProtocols.reduce(async (accumP, protocolToUse) => {
205
+ const answer = await accumP;
206
+ if (protocolToUse.type === 'rtc') {
207
+ const { answer: rtcAnswer, rtcClient, channels } = await __classPrivateFieldGet(this, _rtcConnectionManager).createProviderAnswer(protocolToUse.payload.rtcConnectionId, protocolToUse.payload.offer);
208
+ answer.supportedProtocols.push({
209
+ type: 'rtc',
210
+ version: strategy_2.RTCInfo.version,
211
+ payload: {
212
+ answer: rtcAnswer
213
+ }
214
+ });
215
+ answer.endpointPayloadPromise = answer.endpointPayloadPromise.then((endpointPayload) => channels.then((resolvedChannels) => {
216
+ return {
217
+ ...endpointPayload,
218
+ rtc: {
219
+ rtcClient,
220
+ channels: resolvedChannels
221
+ }
222
+ };
223
+ }));
224
+ }
225
+ else {
226
+ answer.supportedProtocols.push({ type: 'classic', version: strategy_1.ClassicInfo.version });
227
+ }
228
+ return answer;
229
+ }, Promise.resolve(clientAnswer));
230
+ // Need to as cast here.
231
+ clientAnswer.endpointPayloadPromise.then((endpointPayload) => strategy.addEndpoint(clientIdentity.endpointId, endpointPayload));
232
+ ackToSender.payload.payload.result = res;
233
+ ackToSender.payload.payload.answer = clientAnswer;
234
+ return this.wire.sendRaw(ackToSender);
235
+ }
236
+ catch (e) {
237
+ ackToSender.payload.success = false;
238
+ ackToSender.payload.reason = e.message;
239
+ return this.wire.sendRaw(ackToSender);
240
+ }
241
+ }
242
+ }
243
+ exports.ConnectionManager = ConnectionManager;
244
+ _messageReceiver = new WeakMap(), _rtcConnectionManager = new WeakMap();
@@ -0,0 +1,22 @@
1
+ import ChannelClient from './client';
2
+ import { ChannelProvider } from './provider';
3
+ import { EmitterBase } from '../../base';
4
+ import Transport, { Message } from '../../../transport/transport';
5
+ import { ChannelEvents } from '../../events/channel';
6
+ import ProviderIdentity = OpenFin.ProviderIdentity;
7
+ import Identity = OpenFin.Identity;
8
+ export interface ChannelMessage extends Message<any> {
9
+ senderIdentity: Identity;
10
+ ackToSender: any;
11
+ providerIdentity: ProviderIdentity;
12
+ connectAction: boolean;
13
+ }
14
+ export declare class Channel extends EmitterBase<ChannelEvents> {
15
+ #private;
16
+ constructor(wire: Transport);
17
+ getAllChannels(): Promise<ProviderIdentity[]>;
18
+ onChannelConnect(listener: (...args: any[]) => void): Promise<void>;
19
+ onChannelDisconnect(listener: (...args: any[]) => void): Promise<void>;
20
+ connect(channelName: string, options?: OpenFin.ChannelConnectOptions): Promise<ChannelClient>;
21
+ create(channelName: string, options?: OpenFin.ChannelCreateOptions): Promise<ChannelProvider>;
22
+ }
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) {
3
+ if (!privateMap.has(receiver)) {
4
+ throw new TypeError("attempted to set private field on non-instance");
5
+ }
6
+ privateMap.set(receiver, value);
7
+ return value;
8
+ };
9
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) {
10
+ if (!privateMap.has(receiver)) {
11
+ throw new TypeError("attempted to get private field on non-instance");
12
+ }
13
+ return privateMap.get(receiver);
14
+ };
15
+ var _connectionManager;
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.Channel = void 0;
18
+ /* eslint-disable no-console */
19
+ const client_1 = require("./client");
20
+ const provider_1 = require("./provider");
21
+ const base_1 = require("../../base");
22
+ const connection_manager_1 = require("./connection-manager");
23
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
24
+ const noop = () => { };
25
+ class Channel extends base_1.EmitterBase {
26
+ constructor(wire) {
27
+ super(wire, 'channel');
28
+ _connectionManager.set(this, void 0);
29
+ __classPrivateFieldSet(this, _connectionManager, new connection_manager_1.ConnectionManager(wire));
30
+ }
31
+ async getAllChannels() {
32
+ return this.wire.sendAction('get-all-channels').then(({ payload }) => payload.data);
33
+ }
34
+ async onChannelConnect(listener) {
35
+ await this.on('connected', listener);
36
+ }
37
+ async onChannelDisconnect(listener) {
38
+ await this.on('disconnected', listener);
39
+ }
40
+ async connect(channelName, options) {
41
+ if (!channelName || typeof channelName !== 'string') {
42
+ throw new Error('Please provide a channelName string to connect to a channel.');
43
+ }
44
+ const opts = Object.assign(this.wire.environment.getDefaultChannelOptions().connect, options || {});
45
+ let resolver = noop;
46
+ let listener = noop;
47
+ const waitResponse = new Promise((resolve) => {
48
+ resolver = resolve;
49
+ listener = (payload) => {
50
+ if (channelName === payload.channelName) {
51
+ this.removeListener('connected', listener);
52
+ this.connect(channelName, opts).then((response) => {
53
+ resolve(response);
54
+ });
55
+ }
56
+ };
57
+ this.on('connected', listener);
58
+ });
59
+ try {
60
+ const { offer, rtc: rtcPacket } = await __classPrivateFieldGet(this, _connectionManager).createClientOffer(opts);
61
+ const res = await this.wire.sendAction('connect-to-channel', { channelName, ...opts, offer });
62
+ const { payload: { data: routingInfo } } = res;
63
+ // If there isn't a matching channel, the above sendAction call will error out and go to catch, skipping the logic below.
64
+ if (resolver) {
65
+ resolver();
66
+ }
67
+ this.removeListener('connected', listener);
68
+ const strategy = await __classPrivateFieldGet(this, _connectionManager).createClientStrategy(rtcPacket, routingInfo);
69
+ const channel = new client_1.default(routingInfo, this.wire, strategy);
70
+ // It is the client's responsibility to handle endpoint disconnection to the provider.
71
+ // If the endpoint dies, the client will force a disconnection through the core.
72
+ // The provider does not care about endpoint disconnection.
73
+ strategy.onEndpointDisconnect(routingInfo.channelId, async () => {
74
+ try {
75
+ await channel.disconnect();
76
+ }
77
+ catch (error) {
78
+ console.warn(`Something went wrong during disconnect for client with uuid: ${routingInfo.uuid} / name: ${routingInfo.name} / endpointId: ${routingInfo.endpointId}.`);
79
+ }
80
+ finally {
81
+ client_1.default.handleProviderDisconnect(channel, routingInfo);
82
+ }
83
+ });
84
+ this.on('disconnected', (eventPayload) => {
85
+ if (eventPayload.channelName === channelName) {
86
+ client_1.default.handleProviderDisconnect(channel, eventPayload);
87
+ }
88
+ });
89
+ return channel;
90
+ }
91
+ catch (e) {
92
+ const shouldWait = { wait: true, ...opts }.wait;
93
+ const internalNackMessage = 'internal-nack';
94
+ if (shouldWait && e.message && e.message.includes(internalNackMessage)) {
95
+ console.warn(`Channel not found for channelName: ${channelName}, waiting for channel connection.`);
96
+ return waitResponse;
97
+ }
98
+ if (e.message === internalNackMessage) {
99
+ throw new Error(`No channel found for channelName: ${channelName}`);
100
+ }
101
+ else {
102
+ throw new Error(e);
103
+ }
104
+ }
105
+ }
106
+ async create(channelName, options) {
107
+ if (!channelName) {
108
+ throw new Error('Please provide a channelName to create a channel');
109
+ }
110
+ const { payload: { data: providerIdentity } } = await this.wire.sendAction('create-channel', { channelName });
111
+ const channel = __classPrivateFieldGet(this, _connectionManager).createProvider(options, providerIdentity);
112
+ this.on('client-disconnected', (eventPayload) => {
113
+ if (eventPayload.channelName === channelName) {
114
+ provider_1.ChannelProvider.handleClientDisconnection(channel, eventPayload);
115
+ }
116
+ });
117
+ return channel;
118
+ }
119
+ }
120
+ exports.Channel = Channel;
121
+ _connectionManager = new WeakMap();
@@ -0,0 +1,13 @@
1
+ import Transport from '../../../../../transport/transport';
2
+ import { Base } from '../../../../base';
3
+ import { ChannelBase } from '../../channel';
4
+ export declare class MessageReceiver extends Base {
5
+ private endpointMap;
6
+ private latestEndpointIdByChannelId;
7
+ constructor(wire: Transport);
8
+ private processChannelMessage;
9
+ private onmessage;
10
+ addEndpoint(handler: ChannelBase['processAction'], channelId: string, endpointId: string): void;
11
+ removeEndpoint(channelId: string, endpointId: string): void;
12
+ checkForPreviousClientConnection(channelId: string): void;
13
+ }
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MessageReceiver = void 0;
4
+ const client_1 = require("../../client");
5
+ const base_1 = require("../../../../base");
6
+ /*
7
+ This is a singleton (per fin object) tasked with routing messages coming off the ipc to the correct endpoint.
8
+ It needs to be a singleton because there can only be one per wire. It tracks both clients and providers' processAction passed in via the strategy.
9
+ If functionality is not about receiving messages, it does not belong here.
10
+ */
11
+ class MessageReceiver extends base_1.Base {
12
+ constructor(wire) {
13
+ super(wire);
14
+ this.onmessage = (msg) => {
15
+ if (msg.action === 'process-channel-message') {
16
+ this.processChannelMessage(msg);
17
+ return true;
18
+ }
19
+ return false;
20
+ };
21
+ this.endpointMap = new Map();
22
+ this.latestEndpointIdByChannelId = new Map();
23
+ wire.registerMessageHandler(this.onmessage.bind(this));
24
+ }
25
+ async processChannelMessage(msg) {
26
+ var _a, _b;
27
+ const { senderIdentity, providerIdentity, action, ackToSender, payload, intendedTargetIdentity } = msg.payload;
28
+ const key = (_b = (_a = intendedTargetIdentity.channelId) !== null && _a !== void 0 ? _a : intendedTargetIdentity.endpointId) !== null && _b !== void 0 ? _b : this.latestEndpointIdByChannelId.get(providerIdentity.channelId); // No endpointId was passed, make best attempt
29
+ const handler = this.endpointMap.get(key);
30
+ if (!handler) {
31
+ ackToSender.payload.success = false;
32
+ ackToSender.payload.reason = `Client connection with identity uuid: ${this.wire.me.uuid} / name: ${this.wire.me.name} / endpointId: ${key} no longer connected.`;
33
+ return this.wire.sendRaw(ackToSender);
34
+ }
35
+ try {
36
+ const res = await handler(action, payload, senderIdentity);
37
+ ackToSender.payload.payload = ackToSender.payload.payload || {};
38
+ ackToSender.payload.payload.result = res;
39
+ return this.wire.sendRaw(ackToSender);
40
+ }
41
+ catch (e) {
42
+ ackToSender.payload.success = false;
43
+ ackToSender.payload.reason = e.message;
44
+ return this.wire.sendRaw(ackToSender);
45
+ }
46
+ }
47
+ addEndpoint(handler, channelId, endpointId) {
48
+ this.endpointMap.set(endpointId, handler);
49
+ // Providers have the same endpointId and channelId.
50
+ // This is only used when clients are receiving messages from providers, so we shouldn't save provider endpointId here.
51
+ if (channelId !== endpointId) {
52
+ this.latestEndpointIdByChannelId.set(channelId, endpointId);
53
+ }
54
+ }
55
+ removeEndpoint(channelId, endpointId) {
56
+ this.endpointMap.delete(endpointId);
57
+ if (this.latestEndpointIdByChannelId.get(channelId) === endpointId) {
58
+ this.latestEndpointIdByChannelId.delete(channelId);
59
+ }
60
+ }
61
+ checkForPreviousClientConnection(channelId) {
62
+ const endpointIdFromPreviousConnection = this.latestEndpointIdByChannelId.get(channelId);
63
+ if (endpointIdFromPreviousConnection) {
64
+ // Not convinced by this way of doing things, but pushing up for now.
65
+ client_1.default.closeChannelByEndpointId(endpointIdFromPreviousConnection);
66
+ // eslint-disable-next-line no-console
67
+ console.warn('You have created a second connection to an older provider. First connection has been removed from the clientMap');
68
+ // eslint-disable-next-line no-console
69
+ console.warn('If the provider calls publish(), you may receive multiple messages.');
70
+ }
71
+ }
72
+ }
73
+ exports.MessageReceiver = MessageReceiver;
@@ -0,0 +1,22 @@
1
+ import Transport from '../../../../../transport/transport';
2
+ import { MessageReceiver } from './message-receiver';
3
+ import { ChannelStrategy, EndpointPayload } from '../strategy';
4
+ import { LocalSupportedProtocol } from '..';
5
+ import ProviderIdentity = OpenFin.ProviderIdentity;
6
+ export declare class ClassicStrategy implements ChannelStrategy<EndpointPayload> {
7
+ #private;
8
+ private messageReceiver;
9
+ private endpointId;
10
+ private providerIdentity;
11
+ constructor(wire: Transport, messageReceiver: MessageReceiver, endpointId: string, // Provider endpointId is channelId
12
+ providerIdentity: ProviderIdentity);
13
+ onEndpointDisconnect(endpointId: string, listener: () => void): void;
14
+ receive(listener: (action: string, payload: any, identity: OpenFin.ClientIdentity | OpenFin.ClientIdentityMultiRuntime | ProviderIdentity) => Promise<any>): void;
15
+ send: (endpointId: string, action: string, payload: any) => Promise<any>;
16
+ close: () => Promise<void>;
17
+ closeEndpoint(endpointId: string): Promise<void>;
18
+ isEndpointConnected(endpointId: string): boolean;
19
+ addEndpoint(endpointId: string, payload: EndpointPayload): void;
20
+ isValidEndpointPayload(payload: any): payload is EndpointPayload;
21
+ }
22
+ export declare const ClassicInfo: LocalSupportedProtocol;