@ibm-aspera/sdk 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +13 -0
- package/.eslintrc.js +128 -0
- package/.github/CODE_OF_CONDUCT.md +128 -0
- package/.github/CONTRIBUTING.md +147 -0
- package/.github/workflows/ci.yml +36 -0
- package/.github/workflows/documentation.yml +43 -0
- package/.github/workflows/npm_upload.yml +30 -0
- package/.husky/pre-commit +4 -0
- package/CHANGELOG.md +124 -0
- package/LICENSE +201 -0
- package/README.md +25 -0
- package/dist/commonjs/app/core.d.ts +219 -0
- package/dist/commonjs/app/core.js +546 -0
- package/dist/commonjs/app/installer.d.ts +9 -0
- package/dist/commonjs/app/installer.js +50 -0
- package/dist/commonjs/constants/constants.d.ts +6 -0
- package/dist/commonjs/constants/constants.js +9 -0
- package/dist/commonjs/constants/messages.d.ts +29 -0
- package/dist/commonjs/constants/messages.js +32 -0
- package/dist/commonjs/helpers/client/client.d.ts +5 -0
- package/dist/commonjs/helpers/client/client.js +7 -0
- package/dist/commonjs/helpers/client/http-client.d.ts +42 -0
- package/dist/commonjs/helpers/client/http-client.js +84 -0
- package/dist/commonjs/helpers/client/safari-client.d.ts +99 -0
- package/dist/commonjs/helpers/client/safari-client.js +252 -0
- package/dist/commonjs/helpers/helpers.d.ts +84 -0
- package/dist/commonjs/helpers/helpers.js +197 -0
- package/dist/commonjs/helpers/http.d.ts +16 -0
- package/dist/commonjs/helpers/http.js +42 -0
- package/dist/commonjs/helpers/ws.d.ts +62 -0
- package/dist/commonjs/helpers/ws.js +182 -0
- package/dist/commonjs/index.d.ts +41 -0
- package/dist/commonjs/index.js +99 -0
- package/dist/commonjs/models/aspera-sdk.model.d.ts +213 -0
- package/dist/commonjs/models/aspera-sdk.model.js +288 -0
- package/dist/commonjs/models/models.d.ts +640 -0
- package/dist/commonjs/models/models.js +2 -0
- package/dist/js/aspera-sdk.js +3 -0
- package/dist/js/aspera-sdk.js.LICENSE.txt +7 -0
- package/dist/js/aspera-sdk.js.map +1 -0
- package/docs/DEVELOPMENT.md +38 -0
- package/jest.config.js +15 -0
- package/jest.setup.js +0 -0
- package/package.json +50 -0
- package/src/app/core.ts +610 -0
- package/src/app/installer.ts +53 -0
- package/src/constants/constants.ts +16 -0
- package/src/constants/messages.ts +29 -0
- package/src/helpers/client/client.ts +11 -0
- package/src/helpers/client/http-client.ts +92 -0
- package/src/helpers/client/safari-client.ts +318 -0
- package/src/helpers/helpers.ts +200 -0
- package/src/helpers/http.ts +39 -0
- package/src/helpers/ws.ts +215 -0
- package/src/index.html +404 -0
- package/src/index.ts +104 -0
- package/src/models/aspera-sdk.model.ts +360 -0
- package/src/models/models.ts +669 -0
- package/tests/client.spec.ts +52 -0
- package/tests/core.spec.ts +13 -0
- package/tests/helpers.spec.ts +124 -0
- package/tests/http.spec.ts +14 -0
- package/tests/installer.spec.ts +135 -0
- package/tests/mocks.ts +11 -0
- package/tsconfig.json +10 -0
- package/tsconfig.module.json +15 -0
- package/typedoc.js +17 -0
- package/webpack.config.js +53 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { CustomBrandingOptions, DataTransferResponse, AsperaSdkSpec, AsperaSdkTransfer, FileDialogOptions, FolderDialogOptions, InitOptions, InstallerInfoResponse, InstallerOptions, ModifyTransferOptions, ResumeTransferOptions, SafariExtensionEvent, TransferSpec, WebsocketEvent } from './models';
|
|
2
|
+
declare class AsperaSdkGlobals {
|
|
3
|
+
/** The URL of the IBM Aspera HTTP server to use with the SDK */
|
|
4
|
+
asperaAppUrl: string;
|
|
5
|
+
/** The URL of the IBM Aspera Desktop HTTP server to use with the SDK */
|
|
6
|
+
rpcPort: number;
|
|
7
|
+
/** The default URL to check for latest Aspera installers */
|
|
8
|
+
installerUrl: string;
|
|
9
|
+
/** Aspera SDK info */
|
|
10
|
+
AsperaSdkInfo: AsperaSdkInfo;
|
|
11
|
+
/** Indication that the server has been verified as working */
|
|
12
|
+
asperaAppVerified: boolean;
|
|
13
|
+
/** The unique ID for the website */
|
|
14
|
+
appId: string;
|
|
15
|
+
/** The session ID for the current user */
|
|
16
|
+
sessionId?: string;
|
|
17
|
+
/** Map of drop zones created by querySelector */
|
|
18
|
+
dropZonesCreated: Map<string, {
|
|
19
|
+
event: string;
|
|
20
|
+
callback: (event: any) => void;
|
|
21
|
+
}[]>;
|
|
22
|
+
backupLaunchMethod(url: string): void;
|
|
23
|
+
/**
|
|
24
|
+
* Launch the IBM Aspera App via protocol url. By default, a hidden IFRAME attempts to
|
|
25
|
+
* open the app but if that fails a fallback of opening a new window happens.
|
|
26
|
+
*/
|
|
27
|
+
launch(): void;
|
|
28
|
+
}
|
|
29
|
+
export declare class AsperaSdkInfo {
|
|
30
|
+
/** The version of IBM Aspera SDK */
|
|
31
|
+
version: string;
|
|
32
|
+
/** The public key corresponding to the SSH private key generated by IBM Aspera */
|
|
33
|
+
client_pubkey?: string;
|
|
34
|
+
}
|
|
35
|
+
export declare class TransferResponse {
|
|
36
|
+
transfers: AsperaSdkTransfer[];
|
|
37
|
+
}
|
|
38
|
+
export type ActivityMessageTypes = 'transferUpdated' | 'transferRemoved';
|
|
39
|
+
export declare class ActivityMessage {
|
|
40
|
+
type: ActivityMessageTypes;
|
|
41
|
+
data: unknown;
|
|
42
|
+
}
|
|
43
|
+
export declare class ActivityTracking {
|
|
44
|
+
/** Map of callbacks that receive transfer update events */
|
|
45
|
+
private activity_callbacks;
|
|
46
|
+
/** Map of callbacks that received removed transfer events */
|
|
47
|
+
private removed_callbacks;
|
|
48
|
+
/** Map of callbacks that receive connection events */
|
|
49
|
+
private event_callbacks;
|
|
50
|
+
/** Map of callbacks that receive Safari extension events */
|
|
51
|
+
private safari_extension_callbacks;
|
|
52
|
+
/** Keep track of the last WebSocket event **/
|
|
53
|
+
private lastWebSocketEvent;
|
|
54
|
+
/** Keep track of the last Safari extension event **/
|
|
55
|
+
private lastSafariExtensionEvent;
|
|
56
|
+
/**
|
|
57
|
+
* Notify all consumers when a message is received from the websocket
|
|
58
|
+
*
|
|
59
|
+
* @param message the message received from the websocket
|
|
60
|
+
*/
|
|
61
|
+
handleTransferActivity(message: ActivityMessage): void;
|
|
62
|
+
/**
|
|
63
|
+
* Notify all consumers when a connection webSocketEvent occurs. For example, when the SDK
|
|
64
|
+
* websocket connection to IBM Aspera App is closed or reconnected.
|
|
65
|
+
*
|
|
66
|
+
* @param webSocketEvent the event type.
|
|
67
|
+
*/
|
|
68
|
+
handleWebSocketEvents(webSocketEvent: WebsocketEvent): void;
|
|
69
|
+
/**
|
|
70
|
+
* Notify all consumers when a Safari extension safariExtensionEvent occurs (enabled/disabled).
|
|
71
|
+
*
|
|
72
|
+
* @param safariExtensionEvent the event type.
|
|
73
|
+
*/
|
|
74
|
+
handleSafariExtensionEvents(safariExtensionEvent: SafariExtensionEvent): void;
|
|
75
|
+
/**
|
|
76
|
+
* Set up the activity tracking with IBM Aspera.
|
|
77
|
+
*
|
|
78
|
+
* @returns a promise that resolves when the websocket connection is established.
|
|
79
|
+
* Currently, this promise does not reject.
|
|
80
|
+
*/
|
|
81
|
+
setup(): Promise<unknown>;
|
|
82
|
+
/**
|
|
83
|
+
* Register a callback for getting transfers back to the consumer
|
|
84
|
+
*
|
|
85
|
+
* @param callback the function to call with the array of transfers
|
|
86
|
+
*
|
|
87
|
+
* @returns the ID of the callback index
|
|
88
|
+
*/
|
|
89
|
+
setCallback(callback: (transfers: TransferResponse) => void): string;
|
|
90
|
+
/**
|
|
91
|
+
* Remove the callback (deregister) from the list of callbacks
|
|
92
|
+
*
|
|
93
|
+
* @param id the string of the callback to remove
|
|
94
|
+
*/
|
|
95
|
+
removeCallback(id: string): void;
|
|
96
|
+
/**
|
|
97
|
+
* Register a callback for getting transfers back to the consumer
|
|
98
|
+
*
|
|
99
|
+
* @param callback the function to call with the array of transfers
|
|
100
|
+
*
|
|
101
|
+
* @returns the ID of the callback index
|
|
102
|
+
*/
|
|
103
|
+
setRemovedCallback(callback: (transfer: AsperaSdkTransfer) => void): string;
|
|
104
|
+
/**
|
|
105
|
+
* Remove the callback (deregister) from the list of callbacks
|
|
106
|
+
*
|
|
107
|
+
* @param id the string of the callback to remove
|
|
108
|
+
*/
|
|
109
|
+
removeRemovedCallback(id: string): void;
|
|
110
|
+
/**
|
|
111
|
+
* Register a callback for getting websocket events back to the consumer
|
|
112
|
+
*
|
|
113
|
+
* @param callback the function to call with the websocket event
|
|
114
|
+
*
|
|
115
|
+
* @returns the ID of the callback index
|
|
116
|
+
*/
|
|
117
|
+
setWebSocketEventCallback(callback: (status: WebsocketEvent) => void): string;
|
|
118
|
+
/**
|
|
119
|
+
* Remove the callback (deregister) from the list of callbacks
|
|
120
|
+
*
|
|
121
|
+
* @param id the string of the callback to remove
|
|
122
|
+
*/
|
|
123
|
+
removeWebSocketEventCallback(id: string): void;
|
|
124
|
+
/**
|
|
125
|
+
* Register a callback for getting Safari extension events back to the consumer
|
|
126
|
+
*
|
|
127
|
+
* @param callback the function to call with the websocket event
|
|
128
|
+
*
|
|
129
|
+
* @returns the ID of the callback index
|
|
130
|
+
*/
|
|
131
|
+
setSafariExtensionEventCallback(callback: (status: SafariExtensionEvent) => void): string;
|
|
132
|
+
/**
|
|
133
|
+
* Remove the callback (deregister) from the list of callbacks
|
|
134
|
+
*
|
|
135
|
+
* @param id the string of the callback to remove
|
|
136
|
+
*/
|
|
137
|
+
removeSafariExtensionEventCallback(id: string): void;
|
|
138
|
+
private registerDesktopAppSession;
|
|
139
|
+
}
|
|
140
|
+
export declare class AsperaSdk {
|
|
141
|
+
/** Global information about IBM Aspera */
|
|
142
|
+
globals: AsperaSdkGlobals;
|
|
143
|
+
/** Activity tracking for watching transfers */
|
|
144
|
+
activityTracking: ActivityTracking;
|
|
145
|
+
/** Function to initialize IBM Aspera */
|
|
146
|
+
init: (options: InitOptions) => Promise<any>;
|
|
147
|
+
/** Function to test the IBM Aspera status */
|
|
148
|
+
testConnection: () => Promise<any>;
|
|
149
|
+
/** Function to initiate a transfer */
|
|
150
|
+
startTransfer: (transferSpec: TransferSpec, AsperaSdkSpec: AsperaSdkSpec) => Promise<AsperaSdkTransfer>;
|
|
151
|
+
/** Function to launch IBM Aspera */
|
|
152
|
+
launch: () => void;
|
|
153
|
+
/** Register callback for the transfer activity monitor */
|
|
154
|
+
registerActivityCallback: (callback: (transfers: TransferResponse) => void) => string;
|
|
155
|
+
/** Deregister callback to remove it from the callbacks getting transfer data */
|
|
156
|
+
deregisterActivityCallback: (id: string) => void;
|
|
157
|
+
/** Register callback for removed transfers from the app */
|
|
158
|
+
registerRemovedCallback: (callback: (transfer: AsperaSdkTransfer) => void) => string;
|
|
159
|
+
/** Deregister callback to remove it from the callbacks getting removed transfer data */
|
|
160
|
+
deregisterRemovedCallback: (id: string) => void;
|
|
161
|
+
/** Register callback for connection status events from the app */
|
|
162
|
+
registerStatusCallback: (callback: (status: WebsocketEvent) => void) => string;
|
|
163
|
+
/** Deregister callback to remove it from the callbacks getting connection events */
|
|
164
|
+
deregisterStatusCallback: (id: string) => void;
|
|
165
|
+
/** Register callback for Safari extension status events */
|
|
166
|
+
registerSafariExtensionStatusCallback: (callback: (status: SafariExtensionEvent) => void) => string;
|
|
167
|
+
/** Deregister callback to remove it from the callbacks getting Safari extension events */
|
|
168
|
+
deregisterSafariExtensionStatusCallback: (id: string) => void;
|
|
169
|
+
/** Function to remove a transfer */
|
|
170
|
+
removeTransfer: (transferId: string) => Promise<any>;
|
|
171
|
+
/** Function to show the transfer's download directory in Finder or Windows Explorer */
|
|
172
|
+
showDirectory: (transferId: string) => Promise<any>;
|
|
173
|
+
/** Function to stop a transfer */
|
|
174
|
+
stopTransfer: (transferId: string) => Promise<any>;
|
|
175
|
+
/** Function to resume a transfer */
|
|
176
|
+
resumeTransfer: (transferId: string, options?: ResumeTransferOptions) => Promise<AsperaSdkTransfer>;
|
|
177
|
+
/** Function to get a list of all transfers */
|
|
178
|
+
getAllTransfers: () => Promise<AsperaSdkTransfer[]>;
|
|
179
|
+
/** Function to get information for a specific transfer */
|
|
180
|
+
getTransfer: (transferId: string) => Promise<AsperaSdkTransfer>;
|
|
181
|
+
/** Function to display a file dialog for the user to select files. */
|
|
182
|
+
showSelectFileDialog: (options?: FileDialogOptions) => Promise<DataTransferResponse>;
|
|
183
|
+
/** Function to display a folder dialog for the user to select folders. */
|
|
184
|
+
showSelectFolderDialog: (options?: FolderDialogOptions) => Promise<DataTransferResponse>;
|
|
185
|
+
/** Function to display the IBM Aspera preferences page */
|
|
186
|
+
showPreferences: () => Promise<any>;
|
|
187
|
+
/** Function to modify a running transfer */
|
|
188
|
+
modifyTransfer: (transferId: string, options: ModifyTransferOptions) => Promise<AsperaSdkTransfer>;
|
|
189
|
+
/** Function to set custom branding for IBM Aspera */
|
|
190
|
+
setBranding: (id: string, options: CustomBrandingOptions) => Promise<any>;
|
|
191
|
+
/** Create dropzone for drop events of files */
|
|
192
|
+
createDropzone: (callback: (data: {
|
|
193
|
+
event: any;
|
|
194
|
+
files: DataTransferResponse;
|
|
195
|
+
}) => void, elementSelector: string) => void;
|
|
196
|
+
/** Remove dropzone for drop events of files */
|
|
197
|
+
removeDropzone: (elementSelector: string) => void;
|
|
198
|
+
/** Function to get latest installer information */
|
|
199
|
+
getInstallerInfo: (options: InstallerOptions) => Promise<InstallerInfoResponse>;
|
|
200
|
+
/** Initialize drag and drop */
|
|
201
|
+
initDragDrop: () => Promise<any>;
|
|
202
|
+
/** Function to get information about the IBM Aspera instance */
|
|
203
|
+
getInfo: () => Promise<AsperaSdkInfo>;
|
|
204
|
+
/** Function to get whether IBM Aspera is running on Safari */
|
|
205
|
+
isSafari: () => boolean;
|
|
206
|
+
/**
|
|
207
|
+
* Check if IBM Aspera is ready to be used and has been verified.
|
|
208
|
+
*
|
|
209
|
+
* @returns a boolean indicating if SDK can be used for requests
|
|
210
|
+
*/
|
|
211
|
+
get isReady(): boolean;
|
|
212
|
+
}
|
|
213
|
+
export {};
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AsperaSdk = exports.ActivityTracking = exports.ActivityMessage = exports.TransferResponse = exports.AsperaSdkInfo = void 0;
|
|
4
|
+
var constants_1 = require("../constants/constants");
|
|
5
|
+
var messages_1 = require("../constants/messages");
|
|
6
|
+
var safari_client_1 = require("../helpers/client/safari-client");
|
|
7
|
+
var helpers_1 = require("../helpers/helpers");
|
|
8
|
+
var ws_1 = require("../helpers/ws");
|
|
9
|
+
var index_1 = require("../index");
|
|
10
|
+
var AsperaSdkGlobals = /** @class */ (function () {
|
|
11
|
+
function AsperaSdkGlobals() {
|
|
12
|
+
/** The URL of the IBM Aspera HTTP server to use with the SDK */
|
|
13
|
+
this.asperaAppUrl = 'http://127.0.0.1';
|
|
14
|
+
/** The URL of the IBM Aspera Desktop HTTP server to use with the SDK */
|
|
15
|
+
this.rpcPort = 33024;
|
|
16
|
+
/** The default URL to check for latest Aspera installers */
|
|
17
|
+
this.installerUrl = constants_1.installerUrl;
|
|
18
|
+
/** Indication that the server has been verified as working */
|
|
19
|
+
this.asperaAppVerified = false;
|
|
20
|
+
/** Map of drop zones created by querySelector */
|
|
21
|
+
this.dropZonesCreated = new Map();
|
|
22
|
+
}
|
|
23
|
+
AsperaSdkGlobals.prototype.backupLaunchMethod = function (url) {
|
|
24
|
+
window.alert(messages_1.messages.loadingProtocol);
|
|
25
|
+
window.location.href = url;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Launch the IBM Aspera App via protocol url. By default, a hidden IFRAME attempts to
|
|
29
|
+
* open the app but if that fails a fallback of opening a new window happens.
|
|
30
|
+
*/
|
|
31
|
+
AsperaSdkGlobals.prototype.launch = function () {
|
|
32
|
+
var _this = this;
|
|
33
|
+
try {
|
|
34
|
+
var element = document.createElement('iframe');
|
|
35
|
+
element.src = constants_1.protocol;
|
|
36
|
+
element.onerror = function (error) {
|
|
37
|
+
(0, helpers_1.errorLog)(messages_1.messages.failedToGenerateIframe, error);
|
|
38
|
+
_this.backupLaunchMethod(constants_1.protocol);
|
|
39
|
+
};
|
|
40
|
+
element.setAttribute('style', constants_1.hiddenStyleList);
|
|
41
|
+
document.body.appendChild(element);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
(0, helpers_1.errorLog)(messages_1.messages.failedToGenerateIframe, error);
|
|
45
|
+
this.backupLaunchMethod(constants_1.protocol);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
return AsperaSdkGlobals;
|
|
49
|
+
}());
|
|
50
|
+
var AsperaSdkInfo = /** @class */ (function () {
|
|
51
|
+
function AsperaSdkInfo() {
|
|
52
|
+
}
|
|
53
|
+
return AsperaSdkInfo;
|
|
54
|
+
}());
|
|
55
|
+
exports.AsperaSdkInfo = AsperaSdkInfo;
|
|
56
|
+
var TransferResponse = /** @class */ (function () {
|
|
57
|
+
function TransferResponse() {
|
|
58
|
+
}
|
|
59
|
+
return TransferResponse;
|
|
60
|
+
}());
|
|
61
|
+
exports.TransferResponse = TransferResponse;
|
|
62
|
+
var ActivityMessage = /** @class */ (function () {
|
|
63
|
+
function ActivityMessage() {
|
|
64
|
+
}
|
|
65
|
+
return ActivityMessage;
|
|
66
|
+
}());
|
|
67
|
+
exports.ActivityMessage = ActivityMessage;
|
|
68
|
+
var ActivityTracking = /** @class */ (function () {
|
|
69
|
+
function ActivityTracking() {
|
|
70
|
+
/** Map of callbacks that receive transfer update events */
|
|
71
|
+
this.activity_callbacks = new Map();
|
|
72
|
+
/** Map of callbacks that received removed transfer events */
|
|
73
|
+
this.removed_callbacks = new Map();
|
|
74
|
+
/** Map of callbacks that receive connection events */
|
|
75
|
+
this.event_callbacks = new Map();
|
|
76
|
+
/** Map of callbacks that receive Safari extension events */
|
|
77
|
+
this.safari_extension_callbacks = new Map();
|
|
78
|
+
/** Keep track of the last WebSocket event **/
|
|
79
|
+
this.lastWebSocketEvent = 'CLOSED';
|
|
80
|
+
/** Keep track of the last Safari extension event **/
|
|
81
|
+
this.lastSafariExtensionEvent = 'DISABLED';
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Notify all consumers when a message is received from the websocket
|
|
85
|
+
*
|
|
86
|
+
* @param message the message received from the websocket
|
|
87
|
+
*/
|
|
88
|
+
ActivityTracking.prototype.handleTransferActivity = function (message) {
|
|
89
|
+
if (message.type === 'transferUpdated') {
|
|
90
|
+
this.activity_callbacks.forEach(function (callback) {
|
|
91
|
+
if (typeof callback === 'function') {
|
|
92
|
+
callback(message.data);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
if (message.type === 'transferRemoved') {
|
|
97
|
+
this.removed_callbacks.forEach(function (callback) {
|
|
98
|
+
if (typeof callback === 'function') {
|
|
99
|
+
callback(message.data);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Notify all consumers when a connection webSocketEvent occurs. For example, when the SDK
|
|
106
|
+
* websocket connection to IBM Aspera App is closed or reconnected.
|
|
107
|
+
*
|
|
108
|
+
* @param webSocketEvent the event type.
|
|
109
|
+
*/
|
|
110
|
+
ActivityTracking.prototype.handleWebSocketEvents = function (webSocketEvent) {
|
|
111
|
+
if (this.lastWebSocketEvent === webSocketEvent) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
this.event_callbacks.forEach(function (callback) {
|
|
115
|
+
if (typeof callback === 'function') {
|
|
116
|
+
callback(webSocketEvent);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
this.lastWebSocketEvent = webSocketEvent;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Notify all consumers when a Safari extension safariExtensionEvent occurs (enabled/disabled).
|
|
123
|
+
*
|
|
124
|
+
* @param safariExtensionEvent the event type.
|
|
125
|
+
*/
|
|
126
|
+
ActivityTracking.prototype.handleSafariExtensionEvents = function (safariExtensionEvent) {
|
|
127
|
+
if (this.lastSafariExtensionEvent === safariExtensionEvent) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
this.safari_extension_callbacks.forEach(function (callback) {
|
|
131
|
+
if (typeof callback === 'function') {
|
|
132
|
+
callback(safariExtensionEvent);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
this.lastSafariExtensionEvent = safariExtensionEvent;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Set up the activity tracking with IBM Aspera.
|
|
139
|
+
*
|
|
140
|
+
* @returns a promise that resolves when the websocket connection is established.
|
|
141
|
+
* Currently, this promise does not reject.
|
|
142
|
+
*/
|
|
143
|
+
ActivityTracking.prototype.setup = function () {
|
|
144
|
+
var _this = this;
|
|
145
|
+
if (index_1.asperaSdk.globals.sessionId) {
|
|
146
|
+
this.registerDesktopAppSession();
|
|
147
|
+
}
|
|
148
|
+
if ((0, helpers_1.isSafari)()) {
|
|
149
|
+
return safari_client_1.safariClient.monitorTransferActivity();
|
|
150
|
+
}
|
|
151
|
+
return ws_1.websocketService.init()
|
|
152
|
+
.then(function () {
|
|
153
|
+
ws_1.websocketService.registerMessage('transfer_activity', function (data) { return _this.handleTransferActivity(data); });
|
|
154
|
+
ws_1.websocketService.registerEvent(function (status) { return _this.handleWebSocketEvents(status); });
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* Register a callback for getting transfers back to the consumer
|
|
159
|
+
*
|
|
160
|
+
* @param callback the function to call with the array of transfers
|
|
161
|
+
*
|
|
162
|
+
* @returns the ID of the callback index
|
|
163
|
+
*/
|
|
164
|
+
ActivityTracking.prototype.setCallback = function (callback) {
|
|
165
|
+
if (typeof callback !== 'function') {
|
|
166
|
+
(0, helpers_1.errorLog)(messages_1.messages.callbackIsNotFunction);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
var id = "callback-".concat(this.activity_callbacks.size + 1);
|
|
170
|
+
this.activity_callbacks.set(id, callback);
|
|
171
|
+
return id;
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* Remove the callback (deregister) from the list of callbacks
|
|
175
|
+
*
|
|
176
|
+
* @param id the string of the callback to remove
|
|
177
|
+
*/
|
|
178
|
+
ActivityTracking.prototype.removeCallback = function (id) {
|
|
179
|
+
this.activity_callbacks.delete(id);
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* Register a callback for getting transfers back to the consumer
|
|
183
|
+
*
|
|
184
|
+
* @param callback the function to call with the array of transfers
|
|
185
|
+
*
|
|
186
|
+
* @returns the ID of the callback index
|
|
187
|
+
*/
|
|
188
|
+
ActivityTracking.prototype.setRemovedCallback = function (callback) {
|
|
189
|
+
if (typeof callback !== 'function') {
|
|
190
|
+
(0, helpers_1.errorLog)(messages_1.messages.callbackIsNotFunction);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
var id = "callback-".concat(this.removed_callbacks.size + 1);
|
|
194
|
+
this.removed_callbacks.set(id, callback);
|
|
195
|
+
return id;
|
|
196
|
+
};
|
|
197
|
+
/**
|
|
198
|
+
* Remove the callback (deregister) from the list of callbacks
|
|
199
|
+
*
|
|
200
|
+
* @param id the string of the callback to remove
|
|
201
|
+
*/
|
|
202
|
+
ActivityTracking.prototype.removeRemovedCallback = function (id) {
|
|
203
|
+
this.removed_callbacks.delete(id);
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* Register a callback for getting websocket events back to the consumer
|
|
207
|
+
*
|
|
208
|
+
* @param callback the function to call with the websocket event
|
|
209
|
+
*
|
|
210
|
+
* @returns the ID of the callback index
|
|
211
|
+
*/
|
|
212
|
+
ActivityTracking.prototype.setWebSocketEventCallback = function (callback) {
|
|
213
|
+
if (typeof callback !== 'function') {
|
|
214
|
+
(0, helpers_1.errorLog)(messages_1.messages.callbackIsNotFunction);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
var id = "callback-".concat(this.event_callbacks.size + 1);
|
|
218
|
+
this.event_callbacks.set(id, callback);
|
|
219
|
+
callback(this.lastWebSocketEvent);
|
|
220
|
+
return id;
|
|
221
|
+
};
|
|
222
|
+
/**
|
|
223
|
+
* Remove the callback (deregister) from the list of callbacks
|
|
224
|
+
*
|
|
225
|
+
* @param id the string of the callback to remove
|
|
226
|
+
*/
|
|
227
|
+
ActivityTracking.prototype.removeWebSocketEventCallback = function (id) {
|
|
228
|
+
this.event_callbacks.delete(id);
|
|
229
|
+
};
|
|
230
|
+
/**
|
|
231
|
+
* Register a callback for getting Safari extension events back to the consumer
|
|
232
|
+
*
|
|
233
|
+
* @param callback the function to call with the websocket event
|
|
234
|
+
*
|
|
235
|
+
* @returns the ID of the callback index
|
|
236
|
+
*/
|
|
237
|
+
ActivityTracking.prototype.setSafariExtensionEventCallback = function (callback) {
|
|
238
|
+
if (typeof callback !== 'function') {
|
|
239
|
+
(0, helpers_1.errorLog)(messages_1.messages.callbackIsNotFunction);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
var id = "callback-".concat(this.safari_extension_callbacks.size + 1);
|
|
243
|
+
this.safari_extension_callbacks.set(id, callback);
|
|
244
|
+
callback(this.lastSafariExtensionEvent);
|
|
245
|
+
return id;
|
|
246
|
+
};
|
|
247
|
+
/**
|
|
248
|
+
* Remove the callback (deregister) from the list of callbacks
|
|
249
|
+
*
|
|
250
|
+
* @param id the string of the callback to remove
|
|
251
|
+
*/
|
|
252
|
+
ActivityTracking.prototype.removeSafariExtensionEventCallback = function (id) {
|
|
253
|
+
this.safari_extension_callbacks.delete(id);
|
|
254
|
+
};
|
|
255
|
+
ActivityTracking.prototype.registerDesktopAppSession = function () {
|
|
256
|
+
var iframe = document.createElement('iframe');
|
|
257
|
+
iframe.style.display = 'none';
|
|
258
|
+
iframe.src = "aspera://initialize?app_id=".concat(index_1.asperaSdk.globals.appId, "&session_id=").concat(index_1.asperaSdk.globals.sessionId);
|
|
259
|
+
document.body.appendChild(iframe);
|
|
260
|
+
setTimeout(function () {
|
|
261
|
+
document.body.removeChild(iframe);
|
|
262
|
+
}, 1000);
|
|
263
|
+
};
|
|
264
|
+
return ActivityTracking;
|
|
265
|
+
}());
|
|
266
|
+
exports.ActivityTracking = ActivityTracking;
|
|
267
|
+
var AsperaSdk = /** @class */ (function () {
|
|
268
|
+
function AsperaSdk() {
|
|
269
|
+
/** Global information about IBM Aspera */
|
|
270
|
+
this.globals = new AsperaSdkGlobals();
|
|
271
|
+
/** Activity tracking for watching transfers */
|
|
272
|
+
this.activityTracking = new ActivityTracking();
|
|
273
|
+
}
|
|
274
|
+
Object.defineProperty(AsperaSdk.prototype, "isReady", {
|
|
275
|
+
/**
|
|
276
|
+
* Check if IBM Aspera is ready to be used and has been verified.
|
|
277
|
+
*
|
|
278
|
+
* @returns a boolean indicating if SDK can be used for requests
|
|
279
|
+
*/
|
|
280
|
+
get: function () {
|
|
281
|
+
return this.globals.asperaAppVerified && this.globals.appId !== '';
|
|
282
|
+
},
|
|
283
|
+
enumerable: false,
|
|
284
|
+
configurable: true
|
|
285
|
+
});
|
|
286
|
+
return AsperaSdk;
|
|
287
|
+
}());
|
|
288
|
+
exports.AsperaSdk = AsperaSdk;
|