@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,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 _wire, _endpointIdentityMap;
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.ClassicInfo = exports.ClassicStrategy = void 0;
18
+ /*
19
+ This is used to abstract out ipc messaging from the channels implementation. It is only concerned with sending messages and registration with the MessageReceiver
20
+ */
21
+ class ClassicStrategy {
22
+ constructor(wire, messageReceiver, endpointId, // Provider endpointId is channelId
23
+ providerIdentity) {
24
+ this.messageReceiver = messageReceiver;
25
+ this.endpointId = endpointId;
26
+ this.providerIdentity = providerIdentity;
27
+ _wire.set(this, void 0);
28
+ // Store full endpointIdentity by endpointId of all known endpoints for this strategy instance.
29
+ // (clients will only have 1: the provider, the provider will have all clients)
30
+ _endpointIdentityMap.set(this, new Map());
31
+ this.send = async (endpointId, action, payload) => {
32
+ const to = __classPrivateFieldGet(this, _endpointIdentityMap).get(endpointId);
33
+ if (!to) {
34
+ throw new Error(`Could not locate routing info for endpoint ${endpointId}`);
35
+ }
36
+ // as casting to any because typescript complains. The following is only relevant if this is a locally set endpointId on a ClientIdentity.
37
+ // We delete these properties to not change backwards compatibility.
38
+ const cleanId = { ...to };
39
+ if (cleanId.isLocalEndpointId) {
40
+ delete cleanId.endpointId;
41
+ }
42
+ delete cleanId.isLocalEndpointId;
43
+ const raw = await __classPrivateFieldGet(this, _wire).sendAction('send-channel-message', {
44
+ ...cleanId,
45
+ providerIdentity: this.providerIdentity,
46
+ action,
47
+ payload
48
+ })
49
+ .catch((reason) => {
50
+ throw new Error(reason.message);
51
+ });
52
+ return raw.payload.data.result;
53
+ };
54
+ this.close = async () => {
55
+ this.messageReceiver.removeEndpoint(this.providerIdentity.channelId, this.endpointId);
56
+ __classPrivateFieldSet(this, _endpointIdentityMap, new Map());
57
+ };
58
+ __classPrivateFieldSet(this, _wire, wire);
59
+ }
60
+ onEndpointDisconnect(endpointId, listener) {
61
+ // Never fires for 'classic'.
62
+ }
63
+ receive(listener) {
64
+ this.messageReceiver.addEndpoint(listener, this.providerIdentity.channelId, this.endpointId);
65
+ }
66
+ async closeEndpoint(endpointId) {
67
+ __classPrivateFieldGet(this, _endpointIdentityMap).delete(endpointId);
68
+ }
69
+ isEndpointConnected(endpointId) {
70
+ return __classPrivateFieldGet(this, _endpointIdentityMap).has(endpointId);
71
+ }
72
+ addEndpoint(endpointId, payload) {
73
+ __classPrivateFieldGet(this, _endpointIdentityMap).set(endpointId, payload.endpointIdentity);
74
+ }
75
+ isValidEndpointPayload(payload) {
76
+ var _a, _b;
77
+ return (typeof ((_a = payload === null || payload === void 0 ? void 0 : payload.endpointIdentity) === null || _a === void 0 ? void 0 : _a.endpointId) === 'string' ||
78
+ typeof ((_b = payload === null || payload === void 0 ? void 0 : payload.endpointIdentity) === null || _b === void 0 ? void 0 : _b.channelId) === 'string');
79
+ }
80
+ }
81
+ exports.ClassicStrategy = ClassicStrategy;
82
+ _wire = new WeakMap(), _endpointIdentityMap = new WeakMap();
83
+ // Arbitrarily starting at 5 to leave the door open to backfilling pre endpointId etc.
84
+ exports.ClassicInfo = { version: 5, minimumVersion: 0, type: 'classic' };
@@ -0,0 +1,20 @@
1
+ import { ChannelStrategy } from '../strategy';
2
+ declare type OverlapsOnlyIfMatching<T, U> = {
3
+ [K in Extract<keyof T, keyof U>]: U[K] extends T[K] ? U[K] : T[K] extends U[K] ? T[K] : never;
4
+ };
5
+ declare type OnlyIfCompatible<A, B, D = OverlapsOnlyIfMatching<A, B>> = D extends Record<any, never> ? keyof D extends never ? A | B : never : A | B;
6
+ export default class CombinedStrategy<A, B> implements ChannelStrategy<OnlyIfCompatible<A, B>> {
7
+ private primary;
8
+ private secondary;
9
+ static combine<A, B>(a: ChannelStrategy<A>, b: ChannelStrategy<B>): OnlyIfCompatible<A, B> extends never ? never : CombinedStrategy<A, B>;
10
+ private constructor();
11
+ onEndpointDisconnect(endpointId: string, listener: () => void): void;
12
+ isValidEndpointPayload(payload: unknown): payload is OnlyIfCompatible<A, B>;
13
+ closeEndpoint(endpointId: string): Promise<void>;
14
+ isEndpointConnected(endpoint: string): boolean;
15
+ addEndpoint(endpoint: string, payload: OnlyIfCompatible<A, B>): Promise<void>;
16
+ receive(listener: (action: string, payload: any, identity: any) => Promise<any>): void;
17
+ send(endpointId: string, action: string, payload: any): Promise<any>;
18
+ close(): Promise<void>;
19
+ }
20
+ export {};
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class CombinedStrategy {
4
+ // eslint-disable-next-line no-useless-constructor
5
+ constructor(primary, secondary) {
6
+ this.primary = primary;
7
+ this.secondary = secondary;
8
+ }
9
+ // Making this a static method because the constructor can't be typed.
10
+ // Otherwise it will error when calling addEndpoint but I'd rather the whole instance be typed as never.
11
+ static combine(a, b) {
12
+ return new CombinedStrategy(a, b);
13
+ }
14
+ onEndpointDisconnect(endpointId, listener) {
15
+ this.primary.onEndpointDisconnect(endpointId, () => {
16
+ if (!this.secondary.isEndpointConnected(endpointId)) {
17
+ listener();
18
+ }
19
+ });
20
+ this.secondary.onEndpointDisconnect(endpointId, () => {
21
+ if (!this.primary.isEndpointConnected(endpointId)) {
22
+ listener();
23
+ }
24
+ });
25
+ }
26
+ isValidEndpointPayload(payload) {
27
+ return this.primary.isValidEndpointPayload(payload) || this.secondary.isValidEndpointPayload(payload);
28
+ }
29
+ async closeEndpoint(endpointId) {
30
+ await this.primary.closeEndpoint(endpointId);
31
+ await this.secondary.closeEndpoint(endpointId);
32
+ }
33
+ isEndpointConnected(endpoint) {
34
+ return this.primary.isEndpointConnected(endpoint) || this.secondary.isEndpointConnected(endpoint);
35
+ }
36
+ async addEndpoint(endpoint, payload) {
37
+ if (this.primary.isValidEndpointPayload(payload)) {
38
+ await this.primary.addEndpoint(endpoint, payload);
39
+ }
40
+ if (this.secondary.isValidEndpointPayload(payload)) {
41
+ await this.secondary.addEndpoint(endpoint, payload);
42
+ }
43
+ }
44
+ receive(listener) {
45
+ this.primary.receive(listener);
46
+ this.secondary.receive(listener);
47
+ }
48
+ send(endpointId, action, payload) {
49
+ if (this.primary.isEndpointConnected(endpointId)) {
50
+ return this.primary.send(endpointId, action, payload);
51
+ }
52
+ return this.secondary.send(endpointId, action, payload);
53
+ }
54
+ async close() {
55
+ await Promise.all([this.primary.close(), this.secondary.close()]);
56
+ }
57
+ }
58
+ exports.default = CombinedStrategy;
@@ -0,0 +1,44 @@
1
+ export interface ProtocolPacketBase {
2
+ version: number;
3
+ minimumVersion?: number;
4
+ type: string;
5
+ payload?: any;
6
+ }
7
+ export interface ClassicProtocolOffer extends ProtocolPacketBase {
8
+ type: 'classic';
9
+ }
10
+ export interface RTCProtocolOffer extends ProtocolPacketBase {
11
+ type: 'rtc';
12
+ payload: {
13
+ offer: RTCSessionDescriptionInit;
14
+ rtcConnectionId: string;
15
+ };
16
+ }
17
+ export declare type ProtocolOffer = ClassicProtocolOffer | RTCProtocolOffer;
18
+ export declare type MessagingProtocols = ProtocolOffer['type'];
19
+ export declare type LocalSupportedProtocol = {
20
+ type: MessagingProtocols;
21
+ minimumVersion: number;
22
+ version: number;
23
+ };
24
+ export interface ExternalClientOffer {
25
+ maxProtocols: number;
26
+ supportedProtocols: ProtocolPacketBase[];
27
+ }
28
+ export interface ClientOffer {
29
+ supportedProtocols: ProtocolOffer[];
30
+ maxProtocols: number;
31
+ }
32
+ export interface ClassicProtocolAnswer extends ProtocolPacketBase {
33
+ type: 'classic';
34
+ }
35
+ export interface RTCProtocolAnswer extends ProtocolPacketBase {
36
+ type: 'rtc';
37
+ payload: {
38
+ answer: RTCSessionDescriptionInit;
39
+ };
40
+ }
41
+ export declare type ProtocolAnswer = ClassicProtocolAnswer | RTCProtocolAnswer;
42
+ export interface ClientAnswer {
43
+ supportedProtocols: ProtocolAnswer[];
44
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ import { MessagingProtocols, ExternalClientOffer, ProtocolOffer, LocalSupportedProtocol } from '.';
2
+ export declare class ProtocolManager {
3
+ private ProtocolsInPreferenceOrder;
4
+ DefaultClientProtocols: ['classic'];
5
+ DefaultProviderProtocols: ['classic'];
6
+ constructor(ProtocolsInPreferenceOrder: MessagingProtocols[]);
7
+ getClientProtocols: (protocols?: string[]) => MessagingProtocols[];
8
+ getProviderProtocols: (protocols?: string[]) => ['rtc'] | ['rtc', 'classic'] | ['classic'];
9
+ getCompatibleProtocols: (providerProtocols: LocalSupportedProtocol[], clientOffer: ExternalClientOffer) => ProtocolOffer[];
10
+ }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProtocolManager = void 0;
4
+ /*
5
+ This should be agnostic of any actual openfin code to be unit testable.
6
+ Dependencies on the actual srategies should be handled in ConnectionManager
7
+ */
8
+ class ProtocolManager {
9
+ // eslint-disable-next-line no-useless-constructor
10
+ constructor(ProtocolsInPreferenceOrder) {
11
+ this.ProtocolsInPreferenceOrder = ProtocolsInPreferenceOrder;
12
+ this.DefaultClientProtocols = ['classic'];
13
+ this.DefaultProviderProtocols = ['classic'];
14
+ this.getClientProtocols = (protocols) => {
15
+ const supported = protocols
16
+ ? this.ProtocolsInPreferenceOrder.filter((x) => protocols.includes(x))
17
+ : this.DefaultClientProtocols;
18
+ if (!supported.length) {
19
+ throw new Error(`No valid protocols were passed in. Accepted values are: ${this.ProtocolsInPreferenceOrder.join(', ')}.`);
20
+ }
21
+ return supported;
22
+ };
23
+ this.getProviderProtocols = (protocols) => {
24
+ const supported = protocols
25
+ ? this.ProtocolsInPreferenceOrder.filter((x) => protocols.includes(x))
26
+ : this.DefaultProviderProtocols;
27
+ if (!supported.length) {
28
+ throw new Error(`No valid protocols were passed in. Accepted values are: ${this.ProtocolsInPreferenceOrder.join(', ')}.`);
29
+ }
30
+ return supported;
31
+ };
32
+ this.getCompatibleProtocols = (providerProtocols, clientOffer) => {
33
+ const supported = clientOffer.supportedProtocols.filter((clientProtocol) => providerProtocols.some((providerProtocol) => {
34
+ var _a;
35
+ return providerProtocol.type === clientProtocol.type &&
36
+ clientProtocol.version >= providerProtocol.minimumVersion &&
37
+ providerProtocol.version >= ((_a = clientProtocol.minimumVersion) !== null && _a !== void 0 ? _a : 0);
38
+ }));
39
+ return supported.slice(0, clientOffer.maxProtocols);
40
+ };
41
+ }
42
+ }
43
+ exports.ProtocolManager = ProtocolManager;
@@ -0,0 +1,23 @@
1
+ import ProviderIdentity = OpenFin.ProviderIdentity;
2
+ export interface RTCEndpointChannels {
3
+ request: RTCDataChannel;
4
+ response: RTCDataChannel;
5
+ }
6
+ export interface RTCPacket {
7
+ rtcClient: RTCPeerConnection;
8
+ channels: RTCEndpointChannels;
9
+ channelsOpened: Promise<void>;
10
+ }
11
+ export declare class RTCEndpoint {
12
+ #private;
13
+ private rtc;
14
+ private endpointIdentity;
15
+ private responseMap;
16
+ constructor(rtc: RTCPacket, endpointIdentity: OpenFin.ClientIdentity | ProviderIdentity);
17
+ private connectionStateChangeHandler;
18
+ onDisconnect(listener: () => void): void;
19
+ receive(listener: (action: string, payload: any, identity: OpenFin.ClientIdentity | ProviderIdentity) => Promise<any>): void;
20
+ send: (action: string, payload: any) => Promise<any>;
21
+ close: () => void;
22
+ get connected(): boolean;
23
+ }
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-unused-vars */
3
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) {
4
+ if (!privateMap.has(receiver)) {
5
+ throw new TypeError("attempted to get private field on non-instance");
6
+ }
7
+ return privateMap.get(receiver);
8
+ };
9
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) {
10
+ if (!privateMap.has(receiver)) {
11
+ throw new TypeError("attempted to set private field on non-instance");
12
+ }
13
+ privateMap.set(receiver, value);
14
+ return value;
15
+ };
16
+ var _processAction, _disconnectListener;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.RTCEndpoint = void 0;
19
+ const errors_1 = require("../../../../../util/errors");
20
+ /*
21
+ This handles sending RTC messages between RTC connections over the request and response data channels.
22
+ */
23
+ class RTCEndpoint {
24
+ constructor(rtc, endpointIdentity) {
25
+ this.rtc = rtc;
26
+ this.endpointIdentity = endpointIdentity;
27
+ this.responseMap = new Map();
28
+ _processAction.set(this, null);
29
+ _disconnectListener.set(this, void 0);
30
+ this.connectionStateChangeHandler = (event) => {
31
+ if (this.rtc.rtcClient.connectionState !== 'connected') {
32
+ this.rtc.rtcClient.removeEventListener('connectionstatechange', this.connectionStateChangeHandler);
33
+ this.close();
34
+ if (__classPrivateFieldGet(this, _disconnectListener)) {
35
+ __classPrivateFieldGet(this, _disconnectListener).call(this);
36
+ }
37
+ }
38
+ };
39
+ this.send = async (action, payload) => {
40
+ const messageId = `message-${Math.random()}`;
41
+ const promise = new Promise((resolve, reject) => {
42
+ this.responseMap.set(messageId, { resolve, reject });
43
+ });
44
+ this.rtc.channels.request.send(JSON.stringify({ action, payload, messageId }));
45
+ return promise;
46
+ };
47
+ this.close = () => {
48
+ this.responseMap.forEach((response) => response.reject('Connection has closed.'));
49
+ this.responseMap = new Map();
50
+ this.rtc.channels.request.close();
51
+ this.rtc.channels.response.close();
52
+ this.rtc.rtcClient.close();
53
+ };
54
+ this.rtc.channels.response.addEventListener('message', (e) => {
55
+ var _a;
56
+ const { messageId, payload, success, error } = JSON.parse(e.data);
57
+ const { resolve, reject } = (_a = this.responseMap.get(messageId)) !== null && _a !== void 0 ? _a : {};
58
+ if (resolve && reject) {
59
+ this.responseMap.delete(messageId);
60
+ if (success) {
61
+ resolve(payload);
62
+ }
63
+ else {
64
+ reject(error);
65
+ }
66
+ }
67
+ else {
68
+ console.log('Could not find id in responseMap.');
69
+ console.log(e);
70
+ }
71
+ });
72
+ this.rtc.channels.request.addEventListener('message', async (e) => {
73
+ const { messageId, action, payload } = JSON.parse(e.data);
74
+ if (__classPrivateFieldGet(this, _processAction)) {
75
+ try {
76
+ const res = await __classPrivateFieldGet(this, _processAction).call(this, action, payload, endpointIdentity);
77
+ this.rtc.channels.response.send(JSON.stringify({
78
+ messageId,
79
+ payload: res,
80
+ success: true
81
+ }));
82
+ }
83
+ catch (error) {
84
+ // Check if RTCDataChannel is open before sending, error gets swallowed here in the case where
85
+ // client dispatched then closed or disconnected before the dispatch resolves.
86
+ if (this.rtc.channels.response.readyState === 'open') {
87
+ this.rtc.channels.response.send(JSON.stringify({
88
+ messageId,
89
+ error: errors_1.errorToPOJO(error),
90
+ success: false
91
+ }));
92
+ }
93
+ }
94
+ // Check if RTCDataChannel is open for same reason as catch block above.
95
+ }
96
+ else if (this.rtc.channels.response.readyState === 'open') {
97
+ this.rtc.channels.response.send(JSON.stringify({
98
+ messageId,
99
+ success: false,
100
+ error: 'Connection not ready.'
101
+ }));
102
+ }
103
+ });
104
+ this.rtc.rtcClient.addEventListener('connectionstatechange', this.connectionStateChangeHandler);
105
+ // Disconnect if data channels close unexpectedly, e.g. can happen due to message size > ~255kB (RTCPeerConnection.sctp.maxMessageSizeLimit: 262144)
106
+ Object.values(this.rtc.channels).forEach((datachannel) => {
107
+ datachannel.onclose = (e) => {
108
+ [...this.responseMap.values()].forEach((promise) => promise.reject(new Error('RTCDataChannel closed unexpectedly, this is most commonly caused by message size. Note: RTC Channels have a message size limit of ~255kB.')));
109
+ this.close();
110
+ if (__classPrivateFieldGet(this, _disconnectListener)) {
111
+ __classPrivateFieldGet(this, _disconnectListener).call(this);
112
+ }
113
+ };
114
+ });
115
+ }
116
+ onDisconnect(listener) {
117
+ if (!__classPrivateFieldGet(this, _disconnectListener)) {
118
+ __classPrivateFieldSet(this, _disconnectListener, listener);
119
+ }
120
+ else {
121
+ throw new Error('RTCEndpoint disconnectListener cannot be set twice.');
122
+ }
123
+ }
124
+ receive(listener) {
125
+ if (__classPrivateFieldGet(this, _processAction)) {
126
+ throw new Error('You have already set a listener for this RTC Endpoint.');
127
+ }
128
+ __classPrivateFieldSet(this, _processAction, listener);
129
+ }
130
+ get connected() {
131
+ return this.rtc.rtcClient.connectionState === 'connected';
132
+ }
133
+ }
134
+ exports.RTCEndpoint = RTCEndpoint;
135
+ _processAction = new WeakMap(), _disconnectListener = new WeakMap();
@@ -0,0 +1,30 @@
1
+ import Transport from '../../../../../transport/transport';
2
+ import { EmitterBase } from '../../../../base';
3
+ import { RTCEndpointChannels } from './endpoint';
4
+ export declare class RTCICEManager extends EmitterBase<any> {
5
+ constructor(wire: Transport);
6
+ static createDataChannelPromise(label: string, rtcClient: RTCPeerConnection): Promise<RTCDataChannel>;
7
+ ensureChannelOpened: (channel: RTCDataChannel) => Promise<void>;
8
+ listenForProviderIce(rtcConnectionId: string, listener: any): Promise<void>;
9
+ raiseProviderIce(rtcConnectionId: string, payload: any): Promise<void>;
10
+ listenForClientIce(rtcConnectionId: string, listener: any): Promise<void>;
11
+ raiseClientIce(rtcConnectionId: string, payload: any): Promise<void>;
12
+ private cleanupIceListeners;
13
+ private createClientEventName;
14
+ private createProviderEventName;
15
+ private createRouteString;
16
+ private createRtcPeer;
17
+ startClientOffer(): Promise<{
18
+ rtcClient: RTCPeerConnection;
19
+ offer: RTCSessionDescriptionInit;
20
+ channels: RTCEndpointChannels;
21
+ rtcConnectionId: string;
22
+ channelsOpened: Promise<void>;
23
+ }>;
24
+ finishClientOffer(rtcClient: RTCPeerConnection, answer: RTCSessionDescriptionInit, providerReady: Promise<void>): Promise<boolean>;
25
+ createProviderAnswer(rtcConnectionId: string, offer: RTCSessionDescriptionInit): Promise<{
26
+ rtcClient: RTCPeerConnection;
27
+ answer: RTCSessionDescriptionInit;
28
+ channels: Promise<RTCEndpointChannels>;
29
+ }>;
30
+ }
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ /* eslint-disable class-methods-use-this */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.RTCICEManager = void 0;
5
+ const base_1 = require("../../../../base");
6
+ /*
7
+ Singleton that facilitates Offer and Answer exchange required for establishing RTC connections.
8
+ */
9
+ class RTCICEManager extends base_1.EmitterBase {
10
+ constructor(wire) {
11
+ super(wire, 'channel');
12
+ this.ensureChannelOpened = (channel) => {
13
+ return new Promise((resolve, reject) => {
14
+ if (channel.readyState === 'open') {
15
+ resolve();
16
+ }
17
+ else if (channel.readyState === 'connecting') {
18
+ const listener = () => {
19
+ channel.removeEventListener('open', listener);
20
+ resolve();
21
+ };
22
+ channel.addEventListener('open', listener);
23
+ }
24
+ else {
25
+ reject(new Error('This Channel has already closed'));
26
+ }
27
+ });
28
+ };
29
+ }
30
+ static createDataChannelPromise(label, rtcClient) {
31
+ let resolver;
32
+ const promise = new Promise((resolve) => {
33
+ resolver = resolve;
34
+ });
35
+ const listener = (e) => {
36
+ const openListener = () => {
37
+ e.channel.removeEventListener('open', openListener);
38
+ resolver(e.channel);
39
+ };
40
+ if (e.channel.label === label) {
41
+ e.channel.addEventListener('open', openListener);
42
+ rtcClient.removeEventListener('datachannel', listener);
43
+ }
44
+ };
45
+ rtcClient.addEventListener('datachannel', listener);
46
+ return promise;
47
+ }
48
+ async listenForProviderIce(rtcConnectionId, listener) {
49
+ await this.on(this.createProviderEventName(rtcConnectionId), listener, { timestamp: Date.now() });
50
+ }
51
+ async raiseProviderIce(rtcConnectionId, payload) {
52
+ await this.wire.environment.raiseEvent(this.createRouteString(this.createProviderEventName(rtcConnectionId)), payload);
53
+ }
54
+ async listenForClientIce(rtcConnectionId, listener) {
55
+ await this.on(this.createClientEventName(rtcConnectionId), listener, { timestamp: Date.now() });
56
+ }
57
+ async raiseClientIce(rtcConnectionId, payload) {
58
+ await this.wire.environment.raiseEvent(this.createRouteString(this.createClientEventName(rtcConnectionId)), payload);
59
+ }
60
+ cleanupIceListeners(rtcConnectionId) {
61
+ this.removeAllListeners(this.createClientEventName(rtcConnectionId));
62
+ this.removeAllListeners(this.createProviderEventName(rtcConnectionId));
63
+ }
64
+ createClientEventName(rtcConnectionId) {
65
+ return `ice-client-${rtcConnectionId}`;
66
+ }
67
+ createProviderEventName(rtcConnectionId) {
68
+ return `ice-provider-${rtcConnectionId}`;
69
+ }
70
+ createRouteString(name) {
71
+ return `channel/${name}`;
72
+ }
73
+ createRtcPeer() {
74
+ return this.wire.environment.getRtcPeer();
75
+ }
76
+ async startClientOffer() {
77
+ // TODO replace with real guid.
78
+ const rtcConnectionId = Math.random().toString();
79
+ const rtcClient = this.createRtcPeer();
80
+ rtcClient.addEventListener('icecandidate', async (e) => {
81
+ var _a;
82
+ if (e.candidate) {
83
+ await this.raiseClientIce(rtcConnectionId, { candidate: (_a = e.candidate) === null || _a === void 0 ? void 0 : _a.toJSON() });
84
+ }
85
+ });
86
+ await this.listenForProviderIce(rtcConnectionId, async (payload) => {
87
+ await rtcClient.addIceCandidate(payload.candidate);
88
+ });
89
+ const channels = {
90
+ request: rtcClient.createDataChannel('request'),
91
+ response: rtcClient.createDataChannel('response')
92
+ };
93
+ const offer = await rtcClient.createOffer();
94
+ await rtcClient.setLocalDescription(offer);
95
+ const channelsOpened = Promise.all([channels.request, channels.response].map(this.ensureChannelOpened)).then(() => undefined);
96
+ return { rtcClient, channels, offer, rtcConnectionId, channelsOpened };
97
+ }
98
+ async finishClientOffer(rtcClient, answer, providerReady) {
99
+ await rtcClient.setRemoteDescription(answer);
100
+ await providerReady;
101
+ return true;
102
+ }
103
+ async createProviderAnswer(rtcConnectionId, offer) {
104
+ const rtcClient = this.createRtcPeer();
105
+ const requestChannelPromise = RTCICEManager.createDataChannelPromise('request', rtcClient);
106
+ const responseChannelPromise = RTCICEManager.createDataChannelPromise('response', rtcClient);
107
+ rtcClient.addEventListener('icecandidate', async (e) => {
108
+ var _a;
109
+ if (e.candidate) {
110
+ await this.raiseProviderIce(rtcConnectionId, { candidate: (_a = e.candidate) === null || _a === void 0 ? void 0 : _a.toJSON() });
111
+ }
112
+ });
113
+ await this.listenForClientIce(rtcConnectionId, async (payload) => {
114
+ await rtcClient.addIceCandidate(payload.candidate);
115
+ });
116
+ await rtcClient.setRemoteDescription(offer);
117
+ const answer = await rtcClient.createAnswer();
118
+ await rtcClient.setLocalDescription(answer);
119
+ const channels = Promise.all([requestChannelPromise, responseChannelPromise]).then(([request, response]) => {
120
+ // Clean up ice events.
121
+ this.cleanupIceListeners(rtcConnectionId);
122
+ return { request, response };
123
+ });
124
+ return {
125
+ rtcClient,
126
+ answer,
127
+ channels
128
+ };
129
+ }
130
+ }
131
+ exports.RTCICEManager = RTCICEManager;
@@ -0,0 +1,22 @@
1
+ import { ChannelStrategy } from '../strategy';
2
+ import { RTCPacket } from './endpoint';
3
+ import { LocalSupportedProtocol } from '..';
4
+ import ProviderIdentity = OpenFin.ProviderIdentity;
5
+ export interface RTCStrategyEndpointPayload {
6
+ endpointIdentity: OpenFin.ClientIdentity | ProviderIdentity;
7
+ rtc: RTCPacket;
8
+ }
9
+ export declare class RTCStrategy implements ChannelStrategy<RTCStrategyEndpointPayload> {
10
+ #private;
11
+ onEndpointDisconnect(endpointId: string, listener: () => void): void;
12
+ receive(listener: (action: string, payload: any, identity: OpenFin.ClientIdentity | OpenFin.ClientIdentityMultiRuntime | ProviderIdentity) => Promise<any>): void;
13
+ send: (endpointId: string, action: string, payload: any) => Promise<any>;
14
+ close: () => Promise<void>;
15
+ private getEndpointById;
16
+ get connected(): boolean;
17
+ isEndpointConnected(endpointId: string): boolean;
18
+ addEndpoint(endpointId: string, payload: RTCStrategyEndpointPayload): void;
19
+ closeEndpoint(endpointId: string): Promise<void>;
20
+ isValidEndpointPayload(payload: any): payload is RTCStrategyEndpointPayload;
21
+ }
22
+ export declare const RTCInfo: LocalSupportedProtocol;