fix: load active downloads on app open

This commit is contained in:
Fredrik Burmester
2025-02-17 17:24:11 +01:00
parent f30f53f566
commit ec153ebfc6
3 changed files with 45 additions and 27 deletions

View File

@@ -34,6 +34,14 @@ async function cancelDownload(id: string): Promise<void> {
return HlsDownloaderModule.cancelDownload(id);
}
/**
*
* @returns A list of active downloads.
*/
async function getActiveDownloads(): Promise<DownloadInfo[]> {
return HlsDownloaderModule.getActiveDownloads();
}
/**
* Subscribes to download progress events.
* @param listener A callback invoked with progress updates.
@@ -104,4 +112,5 @@ export {
addProgressListener,
HlsDownloaderModule,
cancelDownload,
getActiveDownloads,
};

View File

@@ -73,6 +73,18 @@ public class HlsDownloaderModule: Module {
Events("onProgress", "onError", "onComplete")
Function("getActiveDownloads") { () -> [[String: Any]] in
return activeDownloads.map { (taskId, downloadInfo) in
return [
"id": downloadInfo.delegate.providedId,
"state": "DOWNLOADING",
"metadata": downloadInfo.metadata,
"startTime": downloadInfo.startTime,
"taskId": taskId,
]
}
}
Function("downloadHLSAsset") {
(providedId: String, url: String, metadata: [String: Any]?) -> Void in
let startTime = Date().timeIntervalSince1970