Warning: This is pre-alpha software. Watch/star to follow along with progress.
- Torrent client for node.js or the browser (same module!)
- Insanely fast
- Exposes files as streams to access file content before torrent is finished
- Sequentially requests pieces from peers (when necessary)
- Otherwise, uses rarest-first piece strategy
- Many streaming options (AirPlay, Chromecast, VLC,
<video>
tag in the browser) - Download multiple torrents simultaneously, efficiently
- Supports advanced torrent client features
- magnet uri support via ut_metadata
- peer discovery via dht, tracker, and ut_pex
- awesome extension api for adding new extensions
- Pure Javascript (no native dependencies)
- Comprehensive test suite (completely offline, so it's reliable and fast)
- Uses WebRTC data channels for lightweight peer-to-peer communication (no plugins)
- No silos. WebTorrent clients on one domain can connect to clients running on any other domain – no same origin policy. WebTorrent is a P2P network for the entire web!
- Stream video torrents into a
<video>
tag (webm (vp8, vp9)
ormp4 (h.264)
)
With npm, run:
npm install webtorrent -g
WebTorrent is the first BitTorrent client that works in the browser, using open web standards (no plugins, just HTML5 and WebRTC)!
It's easy to get started!
Downloading a file is simple:
var WebTorrent = require('webtorrent')
var concat = require('concat-stream')
var client = new WebTorrent()
client.download(magnet_uri, function (torrent) {
// Got torrent metadata!
console.log('Torrent info hash:', torrent.infoHash)
torrent.files.forEach(function (file) {
// Get the file data as a Buffer (Uint8Array typed array)
file.createReadStream().pipe(concat(function (buf) {
// Append a link to download the file
var a = document.createElement('a')
a.download = file.name
a.href = URL.createObjectURL(new Blob([ buf ]))
a.textContent = 'download ' + file.name
document.body.appendChild(a)
}))
})
}
Seeding a file is simple, too:
var dragDrop = require('drag-drop/buffer')
var WebTorrent = require('webtorrent')
var client = new WebTorrent()
// When user drops files on the browser, create a new torrent and start seeding it!
dragDrop('body', function (files) {
client.seed(files, function onTorrent (torrent) {
// Client is seeding the file!
console.log('Torrent info hash:', torrent.infoHash)
})
})
WebTorrent works great with browserify, an npm module that let's you use node-style require() to organize your browser code and load modules installed by npm (as seen in the previous examples).
WebTorrent is also available as a standalone script
(webtorrent.min.js
) which exposes WebTorrent
on the window
object, so it can be used with just a script tag:
<script src="webtorrent.min.js"></script>
WebTorrent also works in node.js, using the same npm module! It's mad science!
Here's how to get started:
$ npm install webtorrent -g
$ webtorrent --help
To download a torrent:
$ webtorrent magnet_uri
$ webtorrent /path/to/file.torrent
To stream a torrent to a device like AirPlay or Chromecast, just pass a flag:
$ webtorrent magnet_uri --airplay
There are many supported streaming options:
--airplay stream to Apple TV (AirPlay)
--chromecast stream to Chromecast
--mplayer stream to MPlayer
--mpv stream to MPV
--omx [jack] stream to omx (jack=local|hdmi)
--vlc stream to VLC
--xbmc stream to XBMC
- Report bugs!
- Fix an open issue in this repo or one of it's many dependencies. WebTorrent is an OPEN Open Source Project!
- If you believe in the vision, send bitcoin to 1B6aystcqu8fd6ejzpmMFMPRqH9b86iiwh or donate via Coinbase to support the project.
Join us in IRC on freenode at #webtorrent
if you want to help with development, or you just want to hang out with some cool mad science hackers :)
Most of the active development is happening inside of small npm modules which are used by WebTorrent.
"When applications are done well, they are just the really application-specific, brackish residue that can't be so easily abstracted away. All the nice, reusable components sublimate away onto github and npm where everybody can collaborate to advance the commons." — substack from "how I write modules"
These are the modules I am writing to make WebTorrent work:
module | tests | version | description |
---|---|---|---|
webtorrent | torrent client (this module) | ||
addr-to-ip-port | cache for addr->ip:port | ||
bittorrent-client | access torrents as stream | ||
bittorrent-dht | bittorrent dht client | ||
bittorrent-peerid | identify client name/version | ||
bittorrent-protocol | bittorrent protocol stream | ||
bittorrent-swarm | bittorrent connection manager | ||
bittorrent-tracker | bittorrent tracker server/client | ||
buffer | node buffer api for the browser | ||
create-torrent | create .torrent files | ||
ip-set | efficient mutable ip set | ||
load-ip-set | load ip sets | ||
magnet-uri | parse magnet uris | ||
parse-torrent | parse torrent identifiers | ||
parse-torrent-file | parse .torrent files | ||
simple-peer | webrtc wrapper api | ||
simple-websocket | websocket wrapper api | ||
string2compact | convert 'hostname:port' to compact | ||
torrent-discovery | find peers via dht and tracker | ||
typedarray-to-buffer | efficient buffer creation | ||
ut_metadata | get metadata for magnet uris (ext) | ||
ut_pex | peer discovery (ext) | ||
webtorrent-swarm | webtorrent connection management | ||
webtorrent-tracker | webtorrent tracker server/client |
- compress-sdp (compress sdp messages to lighten load on webtorrent trackers & dht)
- protocol extension: protocol encryption
- protocol extension: µTP
- protocol extension: UPnP and NAT-PMP port forwarding
- protocol extension: webseed support
- webtorrent-dht
WebTorrent is an OPEN Open Source Project. Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit.
WebTorrent is only possible due to the excellent work of the following contributors:
Feross Aboukhadijeh | GitHub/feross | Twitter/@feross |
---|---|---|
Daniel Posch | GitHub/dcposch | Twitter/@dcposch |
John Hiesey | GitHub/jhiesey | Twitter/@jhiesey |
Travis Fischer | GitHub/fisch0920 | Twitter/@fisch0920 |
Astro | GitHub/astro | Twitter/@astro1138 |
Iván Todorovich | GitHub/ivantodorovich | Twitter/@ivantodorovich |
Mathias Buus | GitHub/mafintosh | Twitter/@mafintosh |
Bob Ren | GitHub/bobrenjc93 | Twitter/@bobrenjc93 |
git clone https://github.com/feross/webtorrent.git
cd webtorrent
npm install
./bin/cmd.js --help
Enable debug output by setting the DEBUG
environment variable to the name of the module
you want to debug (e.g. bittorrent-tracker
, or *
to print all logs).
DEBUG=* ./bin/cmd.js
This even works for WebTorrent releases installed with npm install webtorrent -g
:
DEBUG=* webtorrent
WebTorrent is a modular BitTorrent client, so functionality is split up into many
npm modules. You can git clone
all the relevant dependencies with one command. This
makes it easier to send PRs:
./bin/clone.sh
- Sep 2014 (NodeConf EU) – WebTorrent & WebRTC: Mad Science (first working demo of WebTorrent)
- May 2014 (JS.LA) – How I Built a BitTorrent Client in the Browser (progress update; node client working)
- Oct 2013 (RealtimeConf) – WebRTC Black Magic (RealtimeConf) (where I first shared the idea of WebTorrent)
- Instant – Secure, anonymous, streaming file transfer [code]
- Your app here! (send a PR or open an issue with the URL to your app)
Build a browser BitTorrent client that requires no install (no plugin/extension/etc.) and fully-interoperates with the regular BitTorrent network. Use WebRTC Data Channels for peer-to-peer transport.
Since WebTorrent is web-first, it's simple for users who do not understand .torrent files, magnet links, NATs, etc. By making BitTorrent easier, it will be accessible to new swathes of users who were previously intimidated, confused, or unwilling to install a program on their machine to participate.
Problem: WebTorrent clients and normal BitTorrent clients cannot directly connect because WebRTC cannot open UDP/TCP sockets. This is a security restriction on WebRTC that is unlikely to change. So, how do we get content into the WebTorrent network?
Best solution: Mainstream BitTorrent clients add support for WebTorrent. Basically, normal clients implement WebRTC so that WebTorrent clients can directly connect to them. (This could happen once WebTorrent has a lot of users.)
Good solution: Users who want to download torrents that aren't yet seeded by any WebTorrent users need to install a "hybrid client" that implements WebTorrent and BitTorrent. This can be implemented as a native torrent client that bridges the two networks like this:
- Hybrid clients can seed+leech from both WebTorrent and BitTorrent users.
- Hybrid clients are DHT nodes in both the WebTorrent and BitTorrent DHTs.
- The first time a hybrid client downloads a torrent that no other WebTorrent clients are seeding, they become the first WebTorrent seeder. (They essentially "bring" the file into the WebTorrent network).
- Important note: Hybrid clients never download torrents on behalf of other users. That would be a terrible idea.
- Until BitTorrent clients support WebTorrent, "pure" WebTorrent clients can only download from other WebTorrent clients.
- WebTorrent is slower at finding peers since "DHT over WebRTC" requires multiple roundtrips for peer introductions. (This is a requirement of WebRTC signaling - no way around this)
- WebTorrent peers must keep their browser tab open to seed (Show UI to encourage seeding back at least 2x)
- Slower piece verification (SHA1) (max 2MB/s with web worker pool, Web Crypto API will bring huge speed-up when it's finally ready)
- WebTorrent bootstrap DHT node does a bit more work than a BitTorrent one since it must do WebRTC signaling. (Not a huge deal)
Chromebooks are set to refuse all incoming connections by default. To change this, run:
sudo iptables -P INPUT ACCEPT
MIT. Copyright (c) Feross Aboukhadijeh.