Skip to content
This repository has been archived by the owner on Feb 27, 2022. It is now read-only.

Keep the listeners from the original tasks when checkForExistingDownloads is called #78

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 7 additions & 1 deletion lib/downloadTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down