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 specify custom announce urls? #1011

Closed
am1stad opened this issue Jan 9, 2017 · 12 comments
Closed

How to specify custom announce urls? #1011

am1stad opened this issue Jan 9, 2017 · 12 comments

Comments

@am1stad
Copy link

@am1stad am1stad commented Jan 9, 2017

This doesn't work for me...I'm probably not specifying the announce urls properly but I don't really know what they should be.

    const client = new window.WebTorrent()

    client.add(this.torrent.magnet, {
      announce: [
        'http://router.bittorrent.com:6881',
        'http://dht.transmissionbt.com:6881'
      ]
    }, (torrent) => {
      console.log(torrent)
      const file = torrent.files[0]
      console.log(file)
      file.appendTo('body')
    })

Using browser version from CDN.

@DiegoRBaquero

This comment has been minimized.

Copy link
Member

@DiegoRBaquero DiegoRBaquero commented Jan 9, 2017

Why do you say it doesn't work?

Is this in the browser or Node?

Do you get any errors?

@am1stad

This comment has been minimized.

Copy link
Author

@am1stad am1stad commented Jan 10, 2017

    const magnet = 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d&dn=sintel.mp4'
    console.log('play!', magnet)
    const client = new window.WebTorrent()

    client.add(magnet, {
      announce: [
        'wss://tracker.openwebtorrent.com',
        'wss://tracker.btorrent.xyz'
      ]
    }, function (torrent) {
      // this never fires <--------------
      console.log(torrent)
      torrent.on('download', () => {
        console.log('downloadSpeed', torrent.downloadSpeed)
        console.log('timeRemaining', torrent.timeRemaining)
      })

      torrent.on('upload', () => {
        console.log('uploadSpeed', torrent.uploadSpeed)
      })

      console.log(torrent)
      const file = torrent.files[0]
      console.log(file)
      file.appendTo('main')
    })

edit: weird. This took 5+ minutes to load. On webtorrent.io site it loads immediately for me.

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jan 11, 2017

If you find out any info about why it took so long, please share.

@feross feross closed this Jan 11, 2017
@am1stad

This comment has been minimized.

Copy link
Author

@am1stad am1stad commented Jan 11, 2017

The only difference I can see is I'm using vue.js -- perhaps that is causing severe slowdown?

I'm using the same bootstrap socket servers you are. So its very odd. I will do a simple test w/o vue.js and see if that's the issue.

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jan 11, 2017

It could be because webtorrent.io is using a web seed as a fallback. Try adding this to your magnet link:

&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel-1024-surround.mp4
@am1stad

This comment has been minimized.

Copy link
Author

@am1stad am1stad commented Jan 11, 2017

I don't know. I just tried again and it still never loads although it does start to download but does not play right away. I'm guessing it has to wait for the entire file to download for some reason.

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

function play(){
	// var magnet = 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d&dn=sintel.mp4'
	var magnet = document.getElementById('magnet').value;
	console.log('play!', magnet)
	var client = new window.WebTorrent()

	client.add(magnet, {
	  announce: [
		'wss://tracker.openwebtorrent.com',
		'wss://tracker.btorrent.xyz',
		'wss://tracker.fastcast.nz'
	  ]
	}, function (torrent) {
	  // this never fires <--------------
	  console.log(torrent)
	  torrent.on('download', () => {
	    console.log('downloadSpeed', torrent.downloadSpeed)
	    console.log('timeRemaining', torrent.timeRemaining)
	  })

	  torrent.on('upload', () => {
	    console.log('uploadSpeed', torrent.uploadSpeed)
	  })

	  console.log(torrent)
	  var file = torrent.files[0]
	  console.log(file)
	  file.appendTo('body')
	})	
}
</script>
</head>
<body>
<h1>Play</h1>
<p>
	<label for=magnet>Magnet URL:</label>
	<input type=text id=magnet name=magnet>
	<button onclick=play()>play</button>
</p>
<p>
magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d&dn=sintel.mp4<br><br>
magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d&dn=sintel.mp4&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel-1024-surround.mp4<br><br>
</p>

</body>

Above is a simple test which rules out vue.js being my problem. I tried the 2nd url (with ws fallback) and it still seems to not play until the entire file is downloaded (i did not wait that long).

If I do webtorrent 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d&dn=sintel.mp4' --vlc it starts playing in VLC immediately and it plays on webtorrent.io immediately.

torrent downloaded successfully from 9/10 peers in 20s!

The above test.html seems to be missing some options perhaps? I could not tell by looking at webtorrent.io source what options (if any) you are passing to client.add()

20 seconds on the cli and basically never on web. I gotta be missing something here.

Tried in both Canary and Chrome. Both have same issues.

@am1stad

This comment has been minimized.

Copy link
Author

@am1stad am1stad commented Jan 11, 2017

I did not see this error with console all showing. but when I clicked on errors tab I can see there are some errors:

Not allowed to load local resource: blob:null/7f22f81e-4a71-49b1-ae03-17520713fa35
webtorrent.min.js:6 Uncaught (in promise) DOMException: The element has no supported sources.
a @ webtorrent.min.js:6
webtorrent.min.js:6 Uncaught (in promise) DOMException: The element has no supported sources.
@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jan 11, 2017

Ahh, are you running this page with a file:// url? That will block Blob URLs for security reasons (which I do not understand). That prevents Mediasource streaming from working.

Try creating a server and running from http://localhost instead.

@am1stad

This comment has been minimized.

Copy link
Author

@am1stad am1stad commented Jan 12, 2017

Yeah. I realized that right away. I am using http-server from npm and it does load the movie (sometimes). It is really inconsistent, flaky and slow. After around 10 tries it loaded.

Like i said cli interface starts playing right away in VLC. I even cloned the repo and built the debug version to make sure I have the latest.

I'm curious if you want that test and paste in the magnet does it work consistently for you?

The webtorrent.io site works fine and so does instant.io but not when web server is running locally.

One difference I observed between your webinstant.io and my test is that when i watch the websocket frames in the announce list, on your server it is constantly spitting out information from the tracker. On mine it seems to only get an object back every 120 seconds.

@am1stad

This comment has been minimized.

Copy link
Author

@am1stad am1stad commented Jan 13, 2017

Only diff i could find is that you're adding this tracker option with ice servers. What is that?

var client = window.client = new WebTorrent({
  tracker: {
    rtcConfig: rtcConfig
  }
})
client.on('warning', onWarning)
client.on('error', onError)

torrent = client.add(TORRENT, onTorrent)

rtcConfig (ice servers)

{
    "iceServers": [{
        "urls": "stun:23.21.150.121"
    }, {
        "username": "xxx",
        "credential": "xxx",
        "urls": "turn:global.turn.twilio.com:3478?transport=udp"
    }, {
        "username": "xxx",
        "credential": "xxx",
        "urls": "turn:global.turn.twilio.com:3478?transport=tcp"
    }, {
        "username": "xxxx",
        "credential": "xxx",
        "urls": "turn:global.turn.twilio.com:443?transport=tcp"
    }]
}

When I tried adding this your demo movie plays right away for me. But other magnet urls I try still suffer from same problem where downloading never starts.

What are these ice servers used for and where can I read more about setting one up?

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jan 13, 2017

Sounds like you're on a network with a restrictive firewall or NAT. This makes it harder for peers to connect to you. Those "ice servers" are also known as TURN servers and they're a way to help WebRTC connections succeed even when there's a firewall or NAT that is preventing the direct P2P connection from working.

You can make an account with Twilio and sign up for this service (https://www.twilio.com/stun-turn) and they'll run the server for you. That's what I currently do. You can also try to install a TURN server yourself, but I hear it's tricky. If you include these in the rtcConfig option, then webtorrent will include them in the RTCPeerConnection (webrtc constructor) option, so the WebRTC connections are more likely to succeed.

TURN servers are only used as a fallback, when P2P connections fail. TURN is essentially a central server.

@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
3 participants
You can’t perform that action at this time.