Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/helpers/client/safari-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class SafariClient implements Client {
this.listenResponseEvents();
this.listenTransferActivityEvents();
this.listenStatusEvents();
this.listenClientStatusEvents();
this.listenPongEvents();

if (keepAliveTimeout) {
Expand Down Expand Up @@ -205,6 +206,10 @@ export class SafariClient implements Client {
*/
private listenResponseEvents() {
document.addEventListener('AsperaDesktop.Response', (event: CustomEvent<JSONRPCResponse>) => {
if (!event.detail) {
return;
}

this.handleResponse(event.detail);
});
}
Expand All @@ -214,6 +219,10 @@ export class SafariClient implements Client {
*/
private listenTransferActivityEvents() {
document.addEventListener('AsperaDesktop.TransferActivity', (event: any) => {
if (!event.detail) {
return;
}

asperaSdk.activityTracking.handleTransferActivity(event.detail);
});
}
Expand All @@ -223,10 +232,27 @@ export class SafariClient implements Client {
*/
private listenStatusEvents() {
document.addEventListener('AsperaDesktop.Status', (event: any) => {
if (!event.detail) {
return;
}

asperaSdk.activityTracking.handleWebSocketEvents(event.detail);
});
}

/**
* Listens for 'isAppAlive' events. This was introduced in version 1.0.9.
*/
private listenClientStatusEvents() {
document.addEventListener('isAppAlive', (event: any) => {
if (!event.detail?.running) {
return;
}

asperaSdk.activityTracking.handleClientEvents(event.detail.running);
Comment thread
dwosk marked this conversation as resolved.
});
}

/**
* Listens for 'AsperaDesktop.Pong' events.
*/
Expand Down
39 changes: 37 additions & 2 deletions src/models/aspera-sdk.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ export class ActivityTracking {

/** Keep track of the last WebSocket event **/
private lastWebSocketEvent: WebsocketEvent = 'CLOSED';
/** Keep track of the last notified WebSocket event **/
private lastNotifiedWebSocketEvent: WebsocketEvent = undefined;
/** Keep track of the last Safari extension event **/
private lastSafariExtensionEvent: SafariExtensionEvent = 'DISABLED';

Expand Down Expand Up @@ -109,7 +111,7 @@ export class ActivityTracking {
}

/**
* Notify all consumers when a connection webSocketEvent occurs. For example, when the SDK
* Handle and notify if needed when a connection webSocketEvent occurs. For example, when the SDK
* websocket connection to IBM Aspera App is closed or reconnected.
*
* @param webSocketEvent the event type.
Expand All @@ -119,13 +121,46 @@ export class ActivityTracking {
return;
}

this.lastWebSocketEvent = webSocketEvent;
Comment thread
dwosk marked this conversation as resolved.

this.notifyWebSocketEvent(webSocketEvent);
}

/**
* Notify all consumers when a connection webSocketEvent occurs.
*
* @param webSocketEvent the event type.
*/
private notifyWebSocketEvent(webSocketEvent: WebsocketEvent): void {
if (this.lastNotifiedWebSocketEvent === webSocketEvent) {
return;
}

this.lastNotifiedWebSocketEvent = webSocketEvent;

this.event_callbacks.forEach(callback => {
if (typeof callback === 'function') {
callback(webSocketEvent);
}
});
}

this.lastWebSocketEvent = webSocketEvent;
/**
* Notify all consumers when the client changes status. For example, when
* IBM Aspera App is launched or closed.
*
* @param running whether the client is running or not.
*/
handleClientEvents(running: boolean): void {
let webSocketEvent: WebsocketEvent;

if (!running) {
webSocketEvent = 'CLOSED';
} else {
webSocketEvent = this.lastWebSocketEvent;
Comment thread
dwosk marked this conversation as resolved.
}

this.notifyWebSocketEvent(webSocketEvent);
}

/**
Expand Down