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

In browser, if no trackers specified, use wss://tracker.webtorrent.io #218

Closed
feross opened this issue Dec 23, 2014 · 17 comments
Closed

In browser, if no trackers specified, use wss://tracker.webtorrent.io #218

feross opened this issue Dec 23, 2014 · 17 comments

Comments

@feross
Copy link
Member

@feross feross commented Dec 23, 2014

People think code like this should work:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <script src="http://cdn.rawgit.com/feross/webtorrent/master/webtorrent.min.js"></script>
        <script src="http://wzrd.in/standalone/concat-stream@1.4.7"></script>
    </head>
    <body>
        <script>

    var url = 'magnet:?xt=urn:btih:b781cc28e64373378bff35f6a4a66d62cd5c6661';
    var client = new WebTorrent();

    client.add(url, function (torrent) {
      // Got torrent metadata!
      console.log('Torrent info hash:', torrent.infoHash);
    });
        </script>
    </body>
</html>

Currently, you need to do:

client.add(url + '&tr=wss://tracker.webtorrent.io', function () {})

To tell the client to use the webtorrent tracker.

@astro

This comment has been minimized.

Copy link
Contributor

@astro astro commented Dec 23, 2014

In my opinion, a library shouldn't talk to specific services if the user didn't intend to.

@feross

This comment has been minimized.

Copy link
Member Author

@feross feross commented Dec 24, 2014

@astro In general, I agree with your sentiment. In this case, if the user specifies no tracker then WebTorrent simply won't work since no peers will be discovered (the DHT is still unimplemented). This is definitely never what the user wanted.

For the time being, we can throw an informative exception:

"specify a tracker server to discover peers (you can use wss://tracker.webtorrent.io) (required in browser because DHT is unimplemented)"

@jessetane

This comment has been minimized.

Copy link

@jessetane jessetane commented Jan 21, 2015

Just tried webtorrent for the first time - basically copied the example (which uses torrent.infoHash), and got this error. It's not obvious from the message exactly how to add the tracker though - perhaps the example could use magnetURI, or if client.add's opts somehow accepts this, document it?

@FrancoAguilera

This comment has been minimized.

Copy link

@FrancoAguilera FrancoAguilera commented Feb 21, 2015

Hi guys, I'm kind of new in all this js world, so my question is that I had use the example above. here is my code (it was writen in an empty html file)

<script src="js/webtorrent.min.js"></script>
<script src="http://wzrd.in/standalone/concat-stream@1.4.7"></script>
<script>
    var client = new WebTorrent()
    var magnetUri = 'magnet:?xt=urn:btih:b781cc28e64373378bff35f6a4a66d62cd5c6661'

        client.add(magnetUri + '&tr=wss://tracker.webtorrent.io', function (torrent) {

        // Got torrent metadata!
        console.log('Torrent info hash:', torrent.infoHash)

        // Let's say the first file is a webm (vp8) or mp4 (h264) video...
        var file = torrent.files[0]

        // Create a video element
        var video = document.createElement('video')

        video.controls = true
        document.body.appendChild(video)

        // Stream the video into the video tag
        file.createReadStream().pipe(video)

    });
</script>

tested on chrome, and the browser doesn't trow any error , but despite that... nothing seems to happen, I'm I missing something out ?

@feross

This comment has been minimized.

Copy link
Member Author

@feross feross commented Mar 5, 2015

@FrancoAguilera It's likely that you're trying to download a torrent with no seeders. See: https://github.com/feross/webtorrent/wiki/FAQ#why-does-browser-downloading-not-work

@prashant-andani

This comment has been minimized.

Copy link

@prashant-andani prashant-andani commented Mar 17, 2015

<script src="js/webtorrent.min.js"></script> <script src="http://wzrd.in/standalone/concat-stream@1.4.7"></script> <script> var client = new WebTorrent() var magnetUri = 'magnet:?xt=urn:btih:d20d2186e129712666ba4c5b40e78877b814418f' client.add(magnetUri + '&tr=wss://tracker.webtorrent.io', function (torrent) { // Got torrent metadata! console.log('Torrent info hash:', torrent.infoHash) // Let's say the first file is a webm (vp8) or mp4 (h264) video... var file = torrent.files[0] // Create a video element var video = document.createElement('video') video.controls = true document.body.appendChild(video) // Stream the video into the video tag file.createReadStream().pipe(video) }); </script>

This doesnt seem to be working. The same .torrent file for the given magnet url i could play it using npm through vlc player.
Im i missing out anything....

@feross

This comment has been minimized.

Copy link
Member Author

@feross feross commented Mar 17, 2015

@prashant-andani

This comment has been minimized.

Copy link

@prashant-andani prashant-andani commented Mar 17, 2015

@feross can we have list of few explicitly seeded torrent files. It would be of great help.

@feross

This comment has been minimized.

Copy link
Member Author

@feross feross commented Mar 20, 2015

Just seed your own file at https://instant.io and test against that. :)

@sqren

This comment has been minimized.

Copy link

@sqren sqren commented May 22, 2015

I was struggling with the tracker part for a couple of hours. No obvious errors as far as I could tell. In the end it worked by explicitly adding a tracker:

client.add({
    infoHash: infoHash,
    announce: 'wss://tracker.webtorrent.io'
}, function (torrent) {...});

Instead of just

client.add(infoHash, function (torrent) {...});

An explicit error would definitely be helpful.

@feross

This comment has been minimized.

Copy link
Member Author

@feross feross commented May 22, 2015

@sqren That's weird. Are you running the latest version of webtorrent? There's code to automatically add some reasonable defaults if you don't specify any trackers.

https://github.com/feross/webtorrent/blob/e8783fec76bb965605875101399096d4ee2aa57d/lib/torrent.js#L124-L127

@sqren

This comment has been minimized.

Copy link

@sqren sqren commented May 22, 2015

Thanks for quick reply!

I'm on 0.42 and seeing the problem. I've created a jsbin (with 0.41) to reproduce it:
http://jsbin.com/rivudu/5/edit?html,console

@feross

This comment has been minimized.

Copy link
Member Author

@feross feross commented May 22, 2015

Try 0.43, which fixes the issue. Not sure why that's not on the CDN yet, but you can use https://rawgit.com/feross/webtorrent/master/webtorrent.min.js to get the latest script from the github repo.

@sqren

This comment has been minimized.

Copy link

@sqren sqren commented May 23, 2015

0.43 did the trick. Awesome!

@feross

This comment has been minimized.

Copy link
Member Author

@feross feross commented May 25, 2015

Awesome, glad it works for you now :)

@Enelar

This comment has been minimized.

Copy link

@Enelar Enelar commented Jul 11, 2016

@feross i think this should be implemented, as far as user always able to disable it.
like client.disableDefaultTracker()

@lock

This comment has been minimized.

Copy link

@lock 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.
Linked pull requests

Successfully merging a pull request may close this issue.

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