From 8e608707c79280209c5df07f6828c95e7325a606 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Da=CC=81vid=20Viniczay?= Date: Fri, 10 Jul 2020 15:02:10 +0200 Subject: [PATCH] Added an option to the downloadTask constructor to receive another task to keep the listeners --- index.js | 2 +- lib/downloadTask.js | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 0ce997c9..02a5f0c7 100644 --- a/index.js +++ b/index.js @@ -49,7 +49,7 @@ export function checkForExistingDownloads() { return RNBackgroundDownloader.checkForExistingDownloads() .then(foundTasks => { return foundTasks.map(taskInfo => { - let task = new DownloadTask(taskInfo); + let task = new DownloadTask(taskInfo,tasksMap.get(taskInfo.id)); if (taskInfo.state === RNBackgroundDownloader.TaskRunning) { task.state = 'DOWNLOADING'; } else if (taskInfo.state === RNBackgroundDownloader.TaskSuspended) { diff --git a/lib/downloadTask.js b/lib/downloadTask.js index 5de948dc..e22f6091 100644 --- a/lib/downloadTask.js +++ b/lib/downloadTask.js @@ -12,7 +12,7 @@ export default class DownloadTask { bytesWritten = 0 totalBytes = 0 - constructor(taskInfo) { + constructor(taskInfo, originalTask) { if (typeof taskInfo === 'string') { this.id = taskInfo; } else { @@ -21,6 +21,12 @@ export default class DownloadTask { this.bytesWritten = taskInfo.bytesWritten; this.totalBytes = taskInfo.totalBytes; } + if(originalTask){ + this._beginHandler= originalTask._beginHandler + this._progressHandler= originalTask._progressHandler + this._doneHandler= originalTask._doneHandler + this._errorHandler= originalTask._errorHandler + } } begin(handler) {