Browser-laptop: Feature: WebTorrent Integration

Created on 19 Aug 2016  路  18Comments  路  Source: brave/browser-laptop

It would be great if magnet links downloaded right in the browser. The code to integrate is already quite accessible via WebTorrent.

If you aren't familiar WebTorrent:

  • Works in-browser over WebRTC
  • Works in Node.js over WebRTC _and_ standard Bittorrent protocols and will even act as a bridge node.
  • The desktop client is written for Electron so if you're looking for a place to start it's pretty accessible.

/cc @feross

Qchecked-Win32 Qchecked-Win64 Qtest-plan-specified featurtorrent release-noteinclude

Most helpful comment

Initial PR to add WebTorrent support is out! https://github.com/brave/browser-laptop/pull/5342

馃帀 馃帀 馃帀

All 18 comments

Nice idea, @mikeal. This would definitely set Brave apart from other browsers. Built-in torrent support would be really cool, and not that hard to implement with webtorrent.

Here's how this could work:

  • When a magnet link or .torrent file is clicked, initialize a WebTorrent instance add the link.

js var client = new WebTorrent() var torrent = client.add(magnetLink)

  • Once the metadata is loaded (usually takes ~2 seconds), list the files in the torrent.

js torrent.once('metadata', function () { torrent.files.forEach(function (file) { console.log(file.name, file.length) // render the files in the UI }) }

  • When a file is selected, stream that specific file only.

js // Get a Node.js style Readable stream with file data and render it. // Pieces needed by the stream will be prioritized highly and fetched from the network. file.createReadStream()

  • When the user navigates away, destroy the torrent and (optionally) the WebTorrent client to close all connections and reclaim all resources.

js torrent.destroy() client.destroy()

It also probably makes sense to warn the user before starting a torrent on their behalf so they can make an informed decision about whether they wish to join the swarm.

If you don't want to implement any custom UI, you can actually hack this together really quickly using the torrent.createServer() feature in WebTorrent.

 // create HTTP server for this torrent
var server = torrent.createServer()

// start the server listening to a port
server.listen(port, function () {
  // Navigate the user to http://localhost:<port>/ to see a list of files.

  // Access individual files at http://localhost:<port>/<index> where index is the
  // index in the torrent.files array.

  // As the local http server receives requests for pieces of the file, webtorrent
  // fetches them from the torrent network.
})

More info: https://webtorrent.io/docs

how hard would it be to make it pipe through a VPN?

@TheAlphaNerd There is an open PR on WebTorrent to add SOCKS proxy support. Not sure what's required for VPN support.

@feross I think we will be at some of the same events in the next couple months. maybe we can find time to hack on it ??

[--- Commented from Asana.com

commenter brad richter

---[aa]

@TheAlphaNerd That would be fun!

This would be awesome!

@TheAlphaNerd If the OS is using a VPN everything WebTorrent does should be behind it already. I don't really know if the browsers SOCKS setting would put WebRTC connections behind it, @feross ?

Would it be possible to use this feature while IP address leakage via WebRTC is disabled with the fingerprinting protection? / cc: @diracdeltas

260

We could combine this with serving static files from a webtorrent over a custom protocol:

https://github.com/retrohacker/peerweb/blob/master/index.js#L65-L207

Note: the http fallback there is a nasty hack, when https://github.com/electron/electron/issues/4303 lands, a redirect will solve that.

@luixxiul Yes, WebTorrent should work just fine with the fingerprinting detection in Brave. With that setting enabled, WebRTC just finds detects fewer ip:port candidates. Specifically, it would just use the ip:port of the default route (public IP, or if a VPN聽is in use, then the VPN's IP). Normally WebRTC finds additional IPs, including the local IP address, but that's just to increase the chances of a successful connection (more possible routes) and to improve the performance of the connection (local routes will be faster than public routes).

tldr: WebTorrent's WebRTC functionality will operate fine with the reduced list of IPs that Brave's fingerprinting mode returns.

Hey torrent fans! I'm working on adding WebTorrent to Brave with @dcposch over the next couple weeks. Here's the design doc that explains our current plan.

Feedback and comments welcome!

Initial PR to add WebTorrent support is out! https://github.com/brave/browser-laptop/pull/5342

馃帀 馃帀 馃帀

Can we close this?

Would someone please specify the steps for QA? They must have been specified somewhere in a PR, but it should be clarified here for reference as the QA work should start from the issue, not a PR.

Thanks in advance!

@luixxiul There's a design doc here that will probably be helpful: https://docs.google.com/document/d/1d_NXJp05gGcy8kYYDcntIRPQaDrvU3CUF-QjEpf0PLI/edit?usp=sharing

Support the following in the Brave desktop app:

  • Handle navigation to magnet links and torrent files. For example:

    • magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d&dn=sintel

  • Show torrent content within Brave, without the need for an external torrent app.

@feross thanks, I didn't know .torrent files were just planned but not supported yet. I was almost creating an issue for it.

QA Steps

  1. Open any magnet torrent link
  2. Torrent should start downloading

QA possible once #5981 is fixed

Was this page helpful?
0 / 5 - 0 ratings

Related issues

luixxiul picture luixxiul  路  3Comments

bbondy picture bbondy  路  3Comments

jkup picture jkup  路  3Comments

jonathansampson picture jonathansampson  路  3Comments

shortstuffsushi picture shortstuffsushi  路  3Comments