@ibm-aspera/sdk 0.2.29 → 0.2.30

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 (112) hide show
  1. package/dist/commonjs/app/core.d.ts +191 -0
  2. package/dist/commonjs/app/core.js +682 -0
  3. package/dist/commonjs/app/installer.d.ts +9 -0
  4. package/dist/commonjs/app/installer.js +50 -0
  5. package/dist/commonjs/connect/core.d.ts +11 -0
  6. package/dist/commonjs/connect/core.js +73 -0
  7. package/dist/commonjs/constants/constants.d.ts +8 -0
  8. package/dist/commonjs/constants/constants.js +11 -0
  9. package/dist/commonjs/constants/messages.d.ts +35 -0
  10. package/dist/commonjs/constants/messages.js +38 -0
  11. package/dist/commonjs/helpers/client/client.d.ts +5 -0
  12. package/dist/commonjs/helpers/client/client.js +7 -0
  13. package/dist/commonjs/helpers/client/http-client.d.ts +42 -0
  14. package/dist/commonjs/helpers/client/http-client.js +84 -0
  15. package/dist/commonjs/helpers/client/safari-client.d.ts +101 -0
  16. package/dist/commonjs/helpers/client/safari-client.js +264 -0
  17. package/dist/commonjs/helpers/helpers.d.ts +109 -0
  18. package/dist/commonjs/helpers/helpers.js +249 -0
  19. package/dist/commonjs/helpers/http.d.ts +16 -0
  20. package/dist/commonjs/helpers/http.js +42 -0
  21. package/dist/commonjs/helpers/ws.d.ts +62 -0
  22. package/dist/commonjs/helpers/ws.js +161 -0
  23. package/dist/commonjs/http-gateway/core.d.ts +76 -0
  24. package/dist/commonjs/http-gateway/core.js +254 -0
  25. package/dist/commonjs/http-gateway/download.d.ts +14 -0
  26. package/dist/commonjs/http-gateway/download.js +187 -0
  27. package/dist/commonjs/http-gateway/index.d.ts +11 -0
  28. package/dist/commonjs/http-gateway/index.js +11 -0
  29. package/dist/commonjs/http-gateway/models.d.ts +16 -0
  30. package/dist/commonjs/http-gateway/models.js +2 -0
  31. package/dist/commonjs/http-gateway/upload.d.ts +14 -0
  32. package/dist/commonjs/http-gateway/upload.js +124 -0
  33. package/dist/commonjs/index.d.ts +8 -0
  34. package/dist/commonjs/index.js +100 -0
  35. package/dist/commonjs/models/aspera-sdk.model.d.ts +245 -0
  36. package/dist/commonjs/models/aspera-sdk.model.js +345 -0
  37. package/dist/commonjs/models/models.d.ts +712 -0
  38. package/dist/commonjs/models/models.js +2 -0
  39. package/dist/js/aspera-sdk.js +3 -0
  40. package/dist/js/aspera-sdk.js.LICENSE.txt +15 -0
  41. package/dist/js/aspera-sdk.js.map +1 -0
  42. package/package.json +5 -1
  43. package/.editorconfig +0 -13
  44. package/.github/CODEOWNERS +0 -1
  45. package/.github/CODE_OF_CONDUCT.md +0 -128
  46. package/.github/CONTRIBUTING.md +0 -147
  47. package/.github/dependabot.yml +0 -10
  48. package/.github/workflows/ci.yml +0 -39
  49. package/.github/workflows/documentation.yml +0 -44
  50. package/.github/workflows/publish.yml +0 -23
  51. package/.github/workflows/version.yml +0 -32
  52. package/.whitesource +0 -3
  53. package/CHANGELOG.md +0 -204
  54. package/docs/DEVELOPMENT.md +0 -38
  55. package/eslint.config.js +0 -104
  56. package/example/README.md +0 -7
  57. package/example/index.html +0 -14
  58. package/example/package-lock.json +0 -2989
  59. package/example/package.json +0 -30
  60. package/example/public/404.html +0 -5
  61. package/example/public/sdk-code.js +0 -326
  62. package/example/src/App/App.scss +0 -40
  63. package/example/src/App/index.tsx +0 -196
  64. package/example/src/Views/AllTogether.tsx +0 -26
  65. package/example/src/Views/DragDrop.tsx +0 -23
  66. package/example/src/Views/Home.tsx +0 -10
  67. package/example/src/Views/Initialize.tsx +0 -31
  68. package/example/src/Views/Installer.tsx +0 -154
  69. package/example/src/Views/MonitorTransfers.tsx +0 -88
  70. package/example/src/Views/Other.tsx +0 -24
  71. package/example/src/Views/SelectItems.tsx +0 -46
  72. package/example/src/Views/StartTransfer.tsx +0 -37
  73. package/example/src/Views/Test.tsx +0 -20
  74. package/example/src/Views/Views.scss +0 -111
  75. package/example/src/helpers/index.ts +0 -19
  76. package/example/src/index.scss +0 -47
  77. package/example/src/main.tsx +0 -17
  78. package/example/src/vite-env.d.ts +0 -2
  79. package/example/tsconfig.json +0 -30
  80. package/example/vite.config.ts +0 -23
  81. package/jest.config.js +0 -19
  82. package/jest.setup.js +0 -0
  83. package/renovate.json +0 -12
  84. package/src/app/core.ts +0 -765
  85. package/src/app/installer.ts +0 -53
  86. package/src/connect/core.ts +0 -83
  87. package/src/constants/constants.ts +0 -19
  88. package/src/constants/messages.ts +0 -35
  89. package/src/helpers/client/client.ts +0 -11
  90. package/src/helpers/client/http-client.ts +0 -92
  91. package/src/helpers/client/safari-client.ts +0 -334
  92. package/src/helpers/helpers.ts +0 -253
  93. package/src/helpers/http.ts +0 -39
  94. package/src/helpers/ws.ts +0 -191
  95. package/src/http-gateway/core.ts +0 -273
  96. package/src/http-gateway/download.ts +0 -217
  97. package/src/http-gateway/index.ts +0 -19
  98. package/src/http-gateway/models.ts +0 -20
  99. package/src/http-gateway/upload.ts +0 -148
  100. package/src/index.ts +0 -72
  101. package/src/models/aspera-sdk.model.ts +0 -446
  102. package/src/models/models.ts +0 -740
  103. package/tests/client.spec.ts +0 -52
  104. package/tests/core.spec.ts +0 -13
  105. package/tests/helpers.spec.ts +0 -127
  106. package/tests/http.spec.ts +0 -14
  107. package/tests/installer.spec.ts +0 -135
  108. package/tests/mocks.ts +0 -11
  109. package/tsconfig.json +0 -14
  110. package/tsconfig.module.json +0 -16
  111. package/typedoc.js +0 -7
  112. package/webpack.config.js +0 -35
@@ -0,0 +1,245 @@
1
+ import { CustomBrandingOptions, DataTransferResponse, AsperaSdkSpec, AsperaSdkTransfer, FileDialogOptions, FolderDialogOptions, InitOptions, InstallerInfoResponse, InstallerOptions, ModifyTransferOptions, ResumeTransferOptions, SafariExtensionEvent, TransferSpec, WebsocketEvent, InstallerUrlInfo } from './models';
2
+ import { HttpGatewayInfo } from '../http-gateway/models';
3
+ import * as ConnectTypes from '@ibm-aspera/connect-sdk-js/dist/esm/core/types';
4
+ import { Connect, ConnectInstaller } from '@ibm-aspera/connect-sdk-js';
5
+ declare class AsperaSdkGlobals {
6
+ /** The URL of the IBM Aspera HTTP server to use with the SDK */
7
+ asperaAppUrl: string;
8
+ /** The URL of the IBM Aspera Desktop HTTP server to use with the SDK */
9
+ rpcPort: number;
10
+ /** The default URL to check for latest Aspera installers */
11
+ installerUrl: string;
12
+ /** Aspera SDK info */
13
+ asperaSdkInfo: AsperaSdkClientInfo;
14
+ /** Indicate that the server has been verified as working */
15
+ asperaAppVerified: boolean;
16
+ /** The unique ID for the website */
17
+ appId: string;
18
+ /** Indicate if multiple session is supported */
19
+ supportMultipleUsers: boolean;
20
+ /** The session ID for the current user */
21
+ sessionId?: string;
22
+ /** Map of drop zones created by querySelector */
23
+ dropZonesCreated: Map<string, {
24
+ event: string;
25
+ callback: (event: any) => void;
26
+ }[]>;
27
+ /** HTTP Gateway URL after successful passing */
28
+ httpGatewayUrl?: string;
29
+ /** Indicate that the HTTP Gateway has been verified as working */
30
+ httpGatewayVerified: boolean;
31
+ /** HTTP Gateway info */
32
+ httpGatewayInfo?: HttpGatewayInfo;
33
+ /** Http Gateway IFRAME container */
34
+ httpGatewayIframeContainer?: HTMLDivElement;
35
+ /** Connect raw AW4 objects */
36
+ connectAW4?: {
37
+ Connect: typeof Connect;
38
+ ConnectInstaller: typeof ConnectInstaller;
39
+ };
40
+ /** Connect instance */
41
+ connect?: ConnectTypes.ConnectClientType;
42
+ /** Connect installer instance */
43
+ connectInstaller?: ConnectTypes.ConnectInstallerClientType;
44
+ /** Connect status */
45
+ connectStatus: ConnectTypes.ConnectStatusStrings;
46
+ backupLaunchMethod(url: string): void;
47
+ /**
48
+ * Launch the IBM Aspera App via protocol url. By default, a hidden IFRAME attempts to
49
+ * open the app but if that fails a fallback of opening a new window happens.
50
+ */
51
+ launch(): void;
52
+ get sdkResponseData(): AsperaSdkInfo;
53
+ }
54
+ export interface AsperaSdkClientInfo {
55
+ /** The version of IBM Aspera SDK */
56
+ version: string;
57
+ /** The public key corresponding to the SSH private key generated by IBM Aspera */
58
+ client_pubkey?: string;
59
+ }
60
+ export type AsperaSdkInfo = AsperaSdkClientInfo & {
61
+ verified: boolean;
62
+ httpGateway: {
63
+ verified: boolean;
64
+ url?: string;
65
+ info?: HttpGatewayInfo;
66
+ };
67
+ connect: {
68
+ active: boolean;
69
+ status: ConnectTypes.ConnectStatusStrings;
70
+ };
71
+ };
72
+ export interface TransferResponse {
73
+ transfers: AsperaSdkTransfer[];
74
+ }
75
+ export type ActivityMessageTypes = 'transferUpdated' | 'transferRemoved';
76
+ export interface ActivityMessage {
77
+ type: ActivityMessageTypes;
78
+ data: unknown;
79
+ }
80
+ export declare class ActivityTracking {
81
+ /** Map of callbacks that receive transfer update events */
82
+ private activity_callbacks;
83
+ /** Map of callbacks that receive connection events */
84
+ private event_callbacks;
85
+ /** Keep track of the last WebSocket event **/
86
+ private lastWebSocketEvent;
87
+ /** Keep track of the last notified WebSocket event **/
88
+ private lastNotifiedWebSocketEvent;
89
+ /**
90
+ * Notify all consumers when a message is received from the websocket
91
+ *
92
+ * @param message the message received from the websocket
93
+ */
94
+ handleTransferActivity(message: ActivityMessage): void;
95
+ /**
96
+ * Handle and notify if needed when a connection webSocketEvent occurs. For example, when the SDK
97
+ * websocket connection to IBM Aspera App is closed or reconnected.
98
+ *
99
+ * @param webSocketEvent the event type.
100
+ */
101
+ handleWebSocketEvents(webSocketEvent: WebsocketEvent): void;
102
+ /**
103
+ * Notify all consumers when a connection webSocketEvent occurs.
104
+ *
105
+ * @param webSocketEvent the event type.
106
+ */
107
+ private notifyWebSocketEvent;
108
+ /** Trigger manual event for other event types. */
109
+ sendManualEventCallback(status: string): void;
110
+ /**
111
+ * Notify all consumers when the client changes status. For example, when
112
+ * IBM Aspera App is launched or closed.
113
+ *
114
+ * @param running whether the client is running or not.
115
+ */
116
+ handleClientEvents(running: boolean): void;
117
+ /**
118
+ * Notify all consumers when a Safari extension safariExtensionEvent occurs (enabled/disabled).
119
+ *
120
+ * @param safariExtensionEvent the event type.
121
+ */
122
+ handleSafariExtensionEvents(safariExtensionEvent: SafariExtensionEvent): void;
123
+ /**
124
+ * Set up the activity tracking with IBM Aspera.
125
+ *
126
+ * @returns a promise that resolves when the websocket connection is established.
127
+ * Currently, this promise does not reject.
128
+ */
129
+ setup(): Promise<unknown>;
130
+ /**
131
+ * Register a callback for getting transfers back to the consumer
132
+ *
133
+ * @param callback the function to call with the array of transfers
134
+ *
135
+ * @returns the ID of the callback index
136
+ */
137
+ setCallback(callback: (transfers: TransferResponse) => void): string;
138
+ /**
139
+ * Remove the callback (deregister) from the list of callbacks
140
+ *
141
+ * @param id the string of the callback to remove
142
+ */
143
+ removeCallback(id: string): void;
144
+ /**
145
+ * Register a callback for getting websocket events back to the consumer
146
+ *
147
+ * @param callback the function to call with the websocket event
148
+ *
149
+ * @returns the ID of the callback index
150
+ */
151
+ setWebSocketEventCallback(callback: (status: WebsocketEvent) => void): string;
152
+ /**
153
+ * Remove the callback (deregister) from the list of callbacks
154
+ *
155
+ * @param id the string of the callback to remove
156
+ */
157
+ removeWebSocketEventCallback(id: string): void;
158
+ private registerDesktopAppSession;
159
+ }
160
+ export declare class AsperaSdk {
161
+ /** Global information about IBM Aspera */
162
+ globals: AsperaSdkGlobals;
163
+ /** Activity tracking for watching transfers */
164
+ activityTracking: ActivityTracking;
165
+ /** HTTP Gateway file store. Key is the file name. */
166
+ httpGatewaySelectedFiles: Map<string, File>;
167
+ /** Function to initialize IBM Aspera */
168
+ init: (options: InitOptions) => Promise<any>;
169
+ /** Function to test the IBM Aspera status */
170
+ testConnection: () => Promise<any>;
171
+ /** Function to initiate a transfer */
172
+ startTransfer: (transferSpec: TransferSpec, AsperaSdkSpec: AsperaSdkSpec) => Promise<AsperaSdkTransfer>;
173
+ /** Function to launch IBM Aspera */
174
+ launch: () => void;
175
+ /** Register callback for the transfer activity monitor */
176
+ registerActivityCallback: (callback: (transfers: TransferResponse) => void) => string;
177
+ /** Deregister callback to remove it from the callbacks getting transfer data */
178
+ deregisterActivityCallback: (id: string) => void;
179
+ /** Register callback for connection status events from the app */
180
+ registerStatusCallback: (callback: (status: WebsocketEvent) => void) => string;
181
+ /** Deregister callback to remove it from the callbacks getting connection events */
182
+ deregisterStatusCallback: (id: string) => void;
183
+ /** Function to remove a transfer */
184
+ removeTransfer: (transferId: string) => Promise<any>;
185
+ /** Function to show the transfer's download directory in Finder or Windows Explorer */
186
+ showDirectory: (transferId: string) => Promise<any>;
187
+ /** Function to stop a transfer */
188
+ stopTransfer: (transferId: string) => Promise<any>;
189
+ /** Function to resume a transfer */
190
+ resumeTransfer: (transferId: string, options?: ResumeTransferOptions) => Promise<AsperaSdkTransfer>;
191
+ /** Function to get a list of all transfers */
192
+ getAllTransfers: () => Promise<AsperaSdkTransfer[]>;
193
+ /** Function to get information for a specific transfer */
194
+ getTransfer: (transferId: string) => Promise<AsperaSdkTransfer>;
195
+ /** Function to display a file dialog for the user to select files. */
196
+ showSelectFileDialog: (options?: FileDialogOptions) => Promise<DataTransferResponse>;
197
+ /** Function to display a folder dialog for the user to select folders. */
198
+ showSelectFolderDialog: (options?: FolderDialogOptions) => Promise<DataTransferResponse>;
199
+ /** Function to display the IBM Aspera preferences page */
200
+ showPreferences: () => Promise<any>;
201
+ /** Function to modify a running transfer */
202
+ modifyTransfer: (transferId: string, options: ModifyTransferOptions) => Promise<AsperaSdkTransfer>;
203
+ /** Function to set custom branding for IBM Aspera */
204
+ setBranding: (id: string, options: CustomBrandingOptions) => Promise<any>;
205
+ /** Create dropzone for drop events of files */
206
+ createDropzone: (callback: (data: {
207
+ event: any;
208
+ files: DataTransferResponse;
209
+ }) => void, elementSelector: string) => void;
210
+ /** Remove dropzone for drop events of files */
211
+ removeDropzone: (elementSelector: string) => void;
212
+ /** Function to get latest installer information */
213
+ getInstallerInfo: (options: InstallerOptions) => Promise<InstallerInfoResponse>;
214
+ /** Initialize drag and drop */
215
+ initDragDrop: () => Promise<any>;
216
+ /** Function to get information about the IBM Aspera instance */
217
+ getInfo: () => Promise<AsperaSdkInfo>;
218
+ /** Function to get whether IBM Aspera is running on Safari */
219
+ isSafari: () => boolean;
220
+ /** Function to get URLs for installer management. */
221
+ getInstallerUrls: () => InstallerUrlInfo;
222
+ /** Indicate if Safari Extension is enabled. If the extension is disabled during the lifecycle this will not update to disabled. */
223
+ SAFARI_EXTENSION_STATUS: SafariExtensionEvent;
224
+ /** Aspera HTTP Gateway calls. This normally is not needed by clients but expose just in case. */
225
+ httpGatewayCalls: unknown;
226
+ /** Store of HTTP Gateway transfers */
227
+ httpGatewayTransferStore: Map<string, AsperaSdkTransfer>;
228
+ /** HTTP Gateway in app threshold limit. This can be changed globally for the app. */
229
+ httpGatewayInBrowserDownloadThreshold: number;
230
+ /**
231
+ * Check if IBM Aspera is ready to be used and has been verified.
232
+ *
233
+ * @returns a boolean indicating if SDK can be used for requests
234
+ */
235
+ get isReady(): boolean;
236
+ /** Indicate that Connect is available. */
237
+ get useConnect(): boolean;
238
+ /** Indicate that HTTP Gateway is available. */
239
+ get httpGatewayIsReady(): boolean;
240
+ /** Indicates if internal calls should use Gateway */
241
+ get useHttpGateway(): boolean;
242
+ /** Indicates if old HTTP Gateway SDK should be used (v2 and lower) */
243
+ get useOldHttpGateway(): boolean;
244
+ }
245
+ export {};
@@ -0,0 +1,345 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.AsperaSdk = exports.ActivityTracking = void 0;
15
+ var constants_1 = require("../constants/constants");
16
+ var messages_1 = require("../constants/messages");
17
+ var safari_client_1 = require("../helpers/client/safari-client");
18
+ var client_1 = require("../helpers/client/client");
19
+ var helpers_1 = require("../helpers/helpers");
20
+ var ws_1 = require("../helpers/ws");
21
+ var index_1 = require("../index");
22
+ var AsperaSdkGlobals = /** @class */ (function () {
23
+ function AsperaSdkGlobals() {
24
+ /** The URL of the IBM Aspera HTTP server to use with the SDK */
25
+ this.asperaAppUrl = 'http://127.0.0.1';
26
+ /** The URL of the IBM Aspera Desktop HTTP server to use with the SDK */
27
+ this.rpcPort = 33024;
28
+ /** The default URL to check for latest Aspera installers */
29
+ this.installerUrl = constants_1.installerUrl;
30
+ /** Indicate that the server has been verified as working */
31
+ this.asperaAppVerified = false;
32
+ /** Indicate if multiple session is supported */
33
+ this.supportMultipleUsers = false;
34
+ /** Map of drop zones created by querySelector */
35
+ this.dropZonesCreated = new Map();
36
+ /** Indicate that the HTTP Gateway has been verified as working */
37
+ this.httpGatewayVerified = false;
38
+ /** Connect status */
39
+ this.connectStatus = 'WAITING';
40
+ }
41
+ AsperaSdkGlobals.prototype.backupLaunchMethod = function (url) {
42
+ window.alert(messages_1.messages.loadingProtocol);
43
+ window.location.href = url;
44
+ };
45
+ /**
46
+ * Launch the IBM Aspera App via protocol url. By default, a hidden IFRAME attempts to
47
+ * open the app but if that fails a fallback of opening a new window happens.
48
+ */
49
+ AsperaSdkGlobals.prototype.launch = function () {
50
+ var _this = this;
51
+ try {
52
+ var element = document.createElement('iframe');
53
+ element.src = constants_1.protocol;
54
+ element.onerror = function (error) {
55
+ (0, helpers_1.errorLog)(messages_1.messages.failedToGenerateIframe, error);
56
+ _this.backupLaunchMethod(constants_1.protocol);
57
+ };
58
+ element.setAttribute('style', constants_1.hiddenStyleList);
59
+ document.body.appendChild(element);
60
+ }
61
+ catch (error) {
62
+ (0, helpers_1.errorLog)(messages_1.messages.failedToGenerateIframe, error);
63
+ this.backupLaunchMethod(constants_1.protocol);
64
+ }
65
+ };
66
+ Object.defineProperty(AsperaSdkGlobals.prototype, "sdkResponseData", {
67
+ get: function () {
68
+ return __assign(__assign({ verified: this.asperaAppVerified }, this.asperaSdkInfo), { httpGateway: {
69
+ verified: this.httpGatewayVerified,
70
+ url: this.httpGatewayUrl,
71
+ info: this.httpGatewayInfo,
72
+ }, connect: {
73
+ active: this.connectStatus === 'RUNNING',
74
+ status: this.connectStatus,
75
+ } });
76
+ },
77
+ enumerable: false,
78
+ configurable: true
79
+ });
80
+ return AsperaSdkGlobals;
81
+ }());
82
+ var ActivityTracking = /** @class */ (function () {
83
+ function ActivityTracking() {
84
+ /** Map of callbacks that receive transfer update events */
85
+ this.activity_callbacks = new Map();
86
+ /** Map of callbacks that receive connection events */
87
+ this.event_callbacks = new Map();
88
+ /** Keep track of the last WebSocket event **/
89
+ this.lastWebSocketEvent = 'CLOSED';
90
+ /** Keep track of the last notified WebSocket event **/
91
+ this.lastNotifiedWebSocketEvent = undefined;
92
+ }
93
+ /**
94
+ * Notify all consumers when a message is received from the websocket
95
+ *
96
+ * @param message the message received from the websocket
97
+ */
98
+ ActivityTracking.prototype.handleTransferActivity = function (message) {
99
+ if (message.type === 'transferUpdated' || message.type === 'transferRemoved') {
100
+ this.activity_callbacks.forEach(function (callback) {
101
+ if (typeof callback === 'function') {
102
+ callback(message.data);
103
+ }
104
+ });
105
+ }
106
+ };
107
+ /**
108
+ * Handle and notify if needed when a connection webSocketEvent occurs. For example, when the SDK
109
+ * websocket connection to IBM Aspera App is closed or reconnected.
110
+ *
111
+ * @param webSocketEvent the event type.
112
+ */
113
+ ActivityTracking.prototype.handleWebSocketEvents = function (webSocketEvent) {
114
+ if (this.lastWebSocketEvent === webSocketEvent) {
115
+ return;
116
+ }
117
+ this.lastWebSocketEvent = webSocketEvent;
118
+ this.notifyWebSocketEvent(webSocketEvent);
119
+ };
120
+ /**
121
+ * Notify all consumers when a connection webSocketEvent occurs.
122
+ *
123
+ * @param webSocketEvent the event type.
124
+ */
125
+ ActivityTracking.prototype.notifyWebSocketEvent = function (webSocketEvent) {
126
+ if (this.lastNotifiedWebSocketEvent === webSocketEvent) {
127
+ return;
128
+ }
129
+ this.lastNotifiedWebSocketEvent = webSocketEvent;
130
+ this.event_callbacks.forEach(function (callback) {
131
+ if (typeof callback === 'function') {
132
+ callback(webSocketEvent);
133
+ }
134
+ });
135
+ };
136
+ /** Trigger manual event for other event types. */
137
+ ActivityTracking.prototype.sendManualEventCallback = function (status) {
138
+ this.event_callbacks.forEach(function (callback) {
139
+ if (typeof callback === 'function') {
140
+ callback(status);
141
+ }
142
+ });
143
+ };
144
+ /**
145
+ * Notify all consumers when the client changes status. For example, when
146
+ * IBM Aspera App is launched or closed.
147
+ *
148
+ * @param running whether the client is running or not.
149
+ */
150
+ ActivityTracking.prototype.handleClientEvents = function (running) {
151
+ var webSocketEvent;
152
+ if (!running) {
153
+ webSocketEvent = 'CLOSED';
154
+ }
155
+ else {
156
+ webSocketEvent = this.lastWebSocketEvent;
157
+ }
158
+ this.notifyWebSocketEvent(webSocketEvent);
159
+ };
160
+ /**
161
+ * Notify all consumers when a Safari extension safariExtensionEvent occurs (enabled/disabled).
162
+ *
163
+ * @param safariExtensionEvent the event type.
164
+ */
165
+ ActivityTracking.prototype.handleSafariExtensionEvents = function (safariExtensionEvent) {
166
+ index_1.asperaSdk.SAFARI_EXTENSION_STATUS = safariExtensionEvent;
167
+ };
168
+ /**
169
+ * Set up the activity tracking with IBM Aspera.
170
+ *
171
+ * @returns a promise that resolves when the websocket connection is established.
172
+ * Currently, this promise does not reject.
173
+ */
174
+ ActivityTracking.prototype.setup = function () {
175
+ var _this = this;
176
+ if (index_1.asperaSdk.globals.sessionId) {
177
+ this.registerDesktopAppSession();
178
+ }
179
+ var finalCall = function () {
180
+ if ((0, helpers_1.isSafari)()) {
181
+ return safari_client_1.safariClient.monitorTransferActivity();
182
+ }
183
+ return ws_1.websocketService.init()
184
+ .then(function () {
185
+ ws_1.websocketService.registerMessage('transfer_activity', function (data) { return _this.handleTransferActivity(data); });
186
+ ws_1.websocketService.registerEvent(function (status) { return _this.handleWebSocketEvents(status); });
187
+ });
188
+ };
189
+ if (index_1.asperaSdk.globals.supportMultipleUsers) {
190
+ var retryCount_1 = 0;
191
+ var makeVerifyCall_1 = function (incrementIt) {
192
+ if (incrementIt) {
193
+ index_1.asperaSdk.globals.rpcPort = index_1.asperaSdk.globals.rpcPort + 1;
194
+ }
195
+ if (index_1.asperaSdk.globals.rpcPort > 33029) {
196
+ retryCount_1++;
197
+ index_1.asperaSdk.globals.rpcPort = 33024;
198
+ return new Promise(function (resolve) { return setTimeout(resolve, retryCount_1 * 1050); }).then(function () { return makeVerifyCall_1(false); });
199
+ }
200
+ return client_1.client.request('verify_session', { app_id: index_1.asperaSdk.globals.appId, session_id: index_1.asperaSdk.globals.sessionId })
201
+ .then(function (data) {
202
+ if (data.result) {
203
+ return finalCall();
204
+ }
205
+ return makeVerifyCall_1(true);
206
+ }).catch(function () {
207
+ if (retryCount_1 > 5) {
208
+ index_1.asperaSdk.globals.rpcPort = 33024;
209
+ return Promise.reject('Unable to find port running for session');
210
+ }
211
+ return makeVerifyCall_1(true);
212
+ });
213
+ };
214
+ return makeVerifyCall_1(false);
215
+ }
216
+ else {
217
+ return finalCall();
218
+ }
219
+ };
220
+ /**
221
+ * Register a callback for getting transfers back to the consumer
222
+ *
223
+ * @param callback the function to call with the array of transfers
224
+ *
225
+ * @returns the ID of the callback index
226
+ */
227
+ ActivityTracking.prototype.setCallback = function (callback) {
228
+ if (typeof callback !== 'function') {
229
+ (0, helpers_1.errorLog)(messages_1.messages.callbackIsNotFunction);
230
+ return;
231
+ }
232
+ var id = "callback-".concat(this.activity_callbacks.size + 1);
233
+ this.activity_callbacks.set(id, callback);
234
+ return id;
235
+ };
236
+ /**
237
+ * Remove the callback (deregister) from the list of callbacks
238
+ *
239
+ * @param id the string of the callback to remove
240
+ */
241
+ ActivityTracking.prototype.removeCallback = function (id) {
242
+ this.activity_callbacks.delete(id);
243
+ };
244
+ /**
245
+ * Register a callback for getting websocket events back to the consumer
246
+ *
247
+ * @param callback the function to call with the websocket event
248
+ *
249
+ * @returns the ID of the callback index
250
+ */
251
+ ActivityTracking.prototype.setWebSocketEventCallback = function (callback) {
252
+ if (typeof callback !== 'function') {
253
+ (0, helpers_1.errorLog)(messages_1.messages.callbackIsNotFunction);
254
+ return;
255
+ }
256
+ var id = "callback-".concat(this.event_callbacks.size + 1);
257
+ this.event_callbacks.set(id, callback);
258
+ callback(this.lastWebSocketEvent);
259
+ return id;
260
+ };
261
+ /**
262
+ * Remove the callback (deregister) from the list of callbacks
263
+ *
264
+ * @param id the string of the callback to remove
265
+ */
266
+ ActivityTracking.prototype.removeWebSocketEventCallback = function (id) {
267
+ this.event_callbacks.delete(id);
268
+ };
269
+ ActivityTracking.prototype.registerDesktopAppSession = function () {
270
+ var iframe = document.createElement('iframe');
271
+ iframe.style.display = 'none';
272
+ iframe.src = "aspera://initialize?app_id=".concat(index_1.asperaSdk.globals.appId, "&session_id=").concat(index_1.asperaSdk.globals.sessionId);
273
+ document.body.appendChild(iframe);
274
+ setTimeout(function () {
275
+ document.body.removeChild(iframe);
276
+ }, 1000);
277
+ };
278
+ return ActivityTracking;
279
+ }());
280
+ exports.ActivityTracking = ActivityTracking;
281
+ var AsperaSdk = /** @class */ (function () {
282
+ function AsperaSdk() {
283
+ /** Global information about IBM Aspera */
284
+ this.globals = new AsperaSdkGlobals();
285
+ /** Activity tracking for watching transfers */
286
+ this.activityTracking = new ActivityTracking();
287
+ /** HTTP Gateway file store. Key is the file name. */
288
+ this.httpGatewaySelectedFiles = new Map();
289
+ /** Indicate if Safari Extension is enabled. If the extension is disabled during the lifecycle this will not update to disabled. */
290
+ this.SAFARI_EXTENSION_STATUS = 'DISABLED';
291
+ /** Store of HTTP Gateway transfers */
292
+ this.httpGatewayTransferStore = new Map();
293
+ /** HTTP Gateway in app threshold limit. This can be changed globally for the app. */
294
+ this.httpGatewayInBrowserDownloadThreshold = 1000000000;
295
+ }
296
+ Object.defineProperty(AsperaSdk.prototype, "isReady", {
297
+ /**
298
+ * Check if IBM Aspera is ready to be used and has been verified.
299
+ *
300
+ * @returns a boolean indicating if SDK can be used for requests
301
+ */
302
+ get: function () {
303
+ return this.globals.asperaAppVerified && this.globals.appId !== '';
304
+ },
305
+ enumerable: false,
306
+ configurable: true
307
+ });
308
+ Object.defineProperty(AsperaSdk.prototype, "useConnect", {
309
+ /** Indicate that Connect is available. */
310
+ get: function () {
311
+ return this.globals.connectStatus === 'RUNNING';
312
+ },
313
+ enumerable: false,
314
+ configurable: true
315
+ });
316
+ Object.defineProperty(AsperaSdk.prototype, "httpGatewayIsReady", {
317
+ /** Indicate that HTTP Gateway is available. */
318
+ get: function () {
319
+ return !!this.globals.httpGatewayVerified;
320
+ },
321
+ enumerable: false,
322
+ configurable: true
323
+ });
324
+ Object.defineProperty(AsperaSdk.prototype, "useHttpGateway", {
325
+ /** Indicates if internal calls should use Gateway */
326
+ get: function () {
327
+ return this.httpGatewayIsReady && !this.isReady && !this.useConnect;
328
+ },
329
+ enumerable: false,
330
+ configurable: true
331
+ });
332
+ Object.defineProperty(AsperaSdk.prototype, "useOldHttpGateway", {
333
+ /** Indicates if old HTTP Gateway SDK should be used (v2 and lower) */
334
+ get: function () {
335
+ if (!this.useHttpGateway) {
336
+ return false;
337
+ }
338
+ return Number(this.globals.httpGatewayInfo.version.split('.')[0] || 3) <= 2;
339
+ },
340
+ enumerable: false,
341
+ configurable: true
342
+ });
343
+ return AsperaSdk;
344
+ }());
345
+ exports.AsperaSdk = AsperaSdk;