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

Webtorrent not working in the browser. #987

Closed
Rakesh-webdeveloper opened this issue Dec 1, 2016 · 6 comments
Closed

Webtorrent not working in the browser. #987

Rakesh-webdeveloper opened this issue Dec 1, 2016 · 6 comments

Comments

@Rakesh-webdeveloper
Copy link

@Rakesh-webdeveloper Rakesh-webdeveloper commented Dec 1, 2016

**

  • WebTorrent version: using cdn latest webtorrent.min.js
  • Node.js version:
  • Browser name/version (if using WebTorrent in the browser): chrome and firefox latest version

Log

<script src="https://cdn.jsdelivr.net/webtorrent/latest/webtorrent.min.js"></script>

<script>
  var client = new WebTorrent()

  client.on('error', function (err) {
    console.error('ERROR: ' + err.message)
  })

  var torrentId = 'magnet link';
  log('Adding ' + torrentId)
  client.add(torrentId, onTorrent)

  function onTorrent (torrent) {
    console.log(torrent.infoHash);
    console.log(torrent.name);
    console.log(torrent.magnetURI);

    // Print out progress every 5 seconds
    var interval = setInterval(function () {
      log('Progress: ' + (torrent.progress * 100).toFixed(1) + '%')
    }, 5000)

    torrent.on('done', function () {
      log('Progress: 100%')
      clearInterval(interval)
    })

    // Render all files into to the page
    // torrent.files.forEach(function (file) {
    //   file.appendTo('.log')
    //   log('(Blob URLs only work if the file is loaded from a server. "http//localhost" works. "file://" does not.)')
    //   file.getBlobURL(function (err, url) {
    //     if (err) return log(err.message)
    //     log('File done.')
    //     log('<a href="' + url + '">Download full file: ' + file.name + '</a>')
    //   })
    // })
  }

  function log (str) {
    var p = document.createElement('p')
    p.innerHTML = str
    document.querySelector('.log').appendChild(p)
  }
</script>
I'm using the webtorrent desktop app for seeding the torrent. Here i'm using the magnet link

i'm using same magnet link to open in the browser using the webtorrent(example code from webtorret) isn't identiyfing the any peer. Where as instant.io identifies the peer and start loads the video.

Above I posted the sample code i'm testing it is not working

I dont know what is the error.

Note: I had the webrtc seeders. Even i'm seeding through the webtorrent desktop app
Any help would be appreciated. @feross
@xuset

This comment has been minimized.

Copy link

@xuset xuset commented Dec 1, 2016

Hi! Thanks for providing the code snippet; everything looks good there. The reason why it's not downloading could be a few things, but I need more info. Could you provide the debug logs for webtorrent? They can be enabled by opening the browser console and executing localStorage.debug = "webtorrent*". This should help identify the underlying problem.

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Dec 2, 2016

I suspect that you're not specifying any tracker servers in your magnet link. WebTorrent Desktop adds some automatically for you, but the lower-level client.add() function does not.

You can add &tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com to the end of your magnet link

@feross feross closed this Dec 2, 2016
@Rakesh-webdeveloper

This comment has been minimized.

Copy link
Author

@Rakesh-webdeveloper Rakesh-webdeveloper commented Dec 3, 2016

Yes I agree that i'm not adding those tracker. Now it working fine thank @feross

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Dec 4, 2016

Glad to hear that

@stanislasdrg

This comment has been minimized.

Copy link

@stanislasdrg stanislasdrg commented Apr 12, 2018

Sorry to spam everybody, but I have a question relating to this. From the info I gathered reading around the web, magnet links use a DHT table to prevent the use of a tracker. Therefore, why would the appending those to the hash be necessary ? Does it relate to the fact that webtorrent will only work with webrtc seeded torrents ?

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented May 10, 2018

@stanislasdrg There are two reasons to include trackers in magnet links:

  1. To enable finding WebRTC peers, which requires the use of a tracker for now. (as you mentioned)

  2. To enable finding any kind of peer faster. Trackers are just another source of potential peers in addition to the DHT, and can oftentimes respond faster than the DHT. So it's additive, not a replacement for the DHT.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 8, 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
4 participants
You can’t perform that action at this time.