Skip to content

Conversation

@RZulfikri
Copy link
Contributor

Related issue: #811

Problem
When I called multiple RNFS.downloadFile, begin and progress callbacks return all events that occur, not only event that related to that instance only.

For example, I have 2 download process with jobId 1 and 2. In begin callback I'll receive responses of jobId 1 and 2, also in the progress callback.

Solution
When I check the native code there is nothing wrong with that, so I add conditions in event listener to check jobId before pass it event callback.

    if (options.begin) {
      subscriptions.push(RNFS_NativeEventEmitter.addListener('DownloadBegin', (res) => {
        if (res.jobId === jobId) options.begin(res);
      }));
    }

    if (options.progress) {
      subscriptions.push(RNFS_NativeEventEmitter.addListener('DownloadProgress', (res) => {
        if (res.jobId === jobId) options.progress(res);
      }));
    }

    if (options.resumable) {
      subscriptions.push(RNFS_NativeEventEmitter.addListener('DownloadResumable', (res) => {
        if (res.jobId === joibId) options.resumable(res);
      }));
    }

@itinance itinance merged commit ce71cba into itinance:master Feb 5, 2020
@itinance
Copy link
Owner

itinance commented Feb 5, 2020

Many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants