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

Parallel download in Android & Last progress date fix #71

Open
wants to merge 3 commits 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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import com.tonyodev.fetch2.Status;
import com.tonyodev.fetch2core.DownloadBlock;
import com.tonyodev.fetch2core.Func;
import com.tonyodev.fetch2.HttpUrlConnectionDownloader;
import com.tonyodev.fetch2core.Downloader;

import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -81,6 +83,8 @@ public RNBackgroundDownloaderModule(ReactApplicationContext reactContext) {
FetchConfiguration fetchConfiguration = new FetchConfiguration.Builder(this.getReactApplicationContext())
.setDownloadConcurrentLimit(4)
.setNamespace("RNBackgroundDownloader")
.enableRetryOnNetworkGain(true)
.setHttpDownloader(new HttpUrlConnectionDownloader(Downloader.FileDownloaderType.PARALLEL))
.build();
fetch = Fetch.Impl.getInstance(fetchConfiguration);
fetch.addListener(this);
Expand Down Expand Up @@ -232,6 +236,7 @@ public void call(Error error) {
);

synchronized(sharedLock) {
lastProgressReport = new Date();
idToRequestId.put(id, request.getId());
requestIdToConfig.put(request.getId(), config);
saveConfigMap();
Expand Down
2 changes: 2 additions & 0 deletions ios/RNBackgroundDownloader.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ - (id) init {
NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
NSString *sessonIdentifier = [bundleIdentifier stringByAppendingString:@".backgrounddownloadtask"];
sessionConfig = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:sessonIdentifier];
sessionConfig.HTTPMaximumConnectionsPerHost = 4;
progressReports = [[NSMutableDictionary alloc] init];
lastProgressReport = [[NSDate alloc] init];
sharedLock = [NSNumber numberWithInt:1];
Expand Down Expand Up @@ -136,6 +137,7 @@ + (void)setCompletionHandlerWithIdentifier: (NSString *)identifier completionHan
idToPercentMap[identifier] = @0.0;

[task resume];
lastProgressReport = [[NSDate alloc] init];
}
}

Expand Down