Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get progress of a download #381

Closed
webchaz opened this issue Jul 18, 2015 · 7 comments
Closed

How to get progress of a download #381

webchaz opened this issue Jul 18, 2015 · 7 comments

Comments

@webchaz
Copy link

@webchaz webchaz commented Jul 18, 2015

I started with the example provided here for node: https://github.com/feross/webtorrent/blob/master/examples/browser-download.js

I can't see a way to get the download progress (speed, percent left, etc.). Is there an event for this?

@webchaz

This comment has been minimized.

Copy link
Author

@webchaz webchaz commented Jul 19, 2015

In addition, running node v0.10.38, I get a ton of:

(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.

and then finally:

RangeError: Maximum call stack size exceeded

This is using the same example.

@ericwooley

This comment has been minimized.

Copy link
Contributor

@ericwooley ericwooley commented Jul 20, 2015

We worked on a webtorrent based project over the weekend, and here is the file where we calculated speed and progress.

https://github.com/ericwooley/ship-it-wt/blob/master/app/src/js/src/ui/download-stats/download-stats.js

It's also really helpful to look through the instant.io source code to find a lot of these things.

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jul 20, 2015

@webchaz The node warning you're seeing is a node 0.10 bug. If you upgrade to node 0.12 or iojs, the warning should go away. See: nodejs/node-v0.x-archive#6065

@ericwooley's advice is right. For now, it's really useful to look at the code for https://instant.io to learn how to do various things. Please send PRs to improve the docs, if you find things that aren't documented.

Specifically, here's how to get download progress: https://github.com/feross/instant.io/blob/0bfc78b401ae39bcd3352c8c7cb6f5d5c1bc5e0b/client/index.js#L144

@feross feross closed this Jul 20, 2015
@ericwooley

This comment has been minimized.

Copy link
Contributor

@ericwooley ericwooley commented Jul 20, 2015

@feross Are you open to a PR on torrent-swarm the torrent object to implement a getProgress / getSpeed type method?

@webchaz

This comment has been minimized.

Copy link
Author

@webchaz webchaz commented Jul 20, 2015

@feross @ericwooley Thanks for the links and info, this was exactly what I was looking for.

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jul 20, 2015

@ericwooley

I'd accept a PR to add torrent.downloadSpeed() and torrent.uploadSpeed() which would just call torrent.swarm.downloadSpeed() and torrent.swarm.uploadSpeed().

torrent.progress is already implemented: https://github.com/feross/webtorrent/blob/master/lib/torrent.js#L99-L103

@ericwooley

This comment has been minimized.

Copy link
Contributor

@ericwooley ericwooley commented Jul 20, 2015

@feross I didn't notice the swarm speeds were implemented. That makes things easy!

@lock lock bot locked as resolved and limited conversation to collaborators May 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.