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

Functions are not working #565

Closed
guigaoliveira opened this issue Jan 10, 2016 · 8 comments
Closed

Functions are not working #565

guigaoliveira opened this issue Jan 10, 2016 · 8 comments

Comments

@guigaoliveira
Copy link

The functions torrent.timeRemaining, torrent.downloadSpeed (), torrent.uploadSpeed (), are not working for me, all display the result = 0; I put the functions inside the client.download function

@feross
Copy link
Member

feross commented Jan 10, 2016

Please share the code you're using, or there's no way to help you.

@feross
Copy link
Member

feross commented Jan 10, 2016

Also, note that in the latest version, the function were just changed to getters:

torrent.downloadSpeed
torrent.uploadSpeed

@guigaoliveira
Copy link
Author

My code:

var WebTorrent = require('webtorrent');
var fs = require('fs');

var client = new WebTorrent();
var torrentId =magnet_url; // link
var counter=1;

client.download(torrentId, function (torrent) 
{
  console.log('Torrent magnet link:', torrent.magnetURI);
  console.log(torrent.timeRemaining);
  console.log(torrent.downloadSpeed);
  torrent.files.forEach(function (file) 
  {
    // get mp4 files
    if(file.path.indexOf("mp4") !=-1) 
    {
    var source = file.createReadStream();
    var destination = fs.createWriteStream('docs/'+file.name);
    source.pipe(destination);
    // finish 
    destination.on('finish', function() 
    {
        console.log(file.name)
        if(counter===torrent.files.length)
        {
         client.destroy(function callback (err) {})
          return console.log('finish');
        }
        else
        {
         counter++;
        }
    });
   }
   })

 return false;
})  

@guigaoliveira
Copy link
Author

torrent.timeRemaining = infinity
torrent.downloadSpeed = 0

@Stiveknx
Copy link
Contributor

Maybe, because there's no peers for that torrent, so the download doesn't start and the time reimaining is not calculated.
Try checking the number of peers:

console.log(torrent.swarm.numPeers)

@guigaoliveira
Copy link
Author

No, I checked and there are 43 peers. I don't know the cause of this.

@feross
Copy link
Member

feross commented Jan 12, 2016

Please read this part of the FAQ:

Why does browser downloading not work? I see no peers!

It does work! But you can't just use any random magnet uri or .torrent file. The torrent must be seeded by a WebRTC-capable client, i.e. webtorrent-hybrid, instant.io, or Playback.

In the browser, WebTorrent can only download torrents that are explicitly seeded to web peers via a WebRTC-capable client. Desktop torrent clients need to support WebRTC to connect to web browsers.

@lock
Copy link

lock bot commented May 4, 2018

This thread has been automatically locked because it has not had recent activity. To discuss futher, please open a new issue.

@lock lock bot locked as resolved and limited conversation to collaborators May 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants