The streaming torrent client. For node.js and the web.
Sponsored by
WebTorrent is a streaming torrent client for node.js and the browser. YEP,
THAT'S RIGHT. THE BROWSER. It's written completely in JavaScript – the language of the web
– so the same code works in both runtimes.
In node.js, this module is a simple torrent client, using TCP and UDP to talk to
other torrent clients.
In the browser, WebTorrent uses WebRTC (data channels) for peer-to-peer transport.
It can be used without browser plugins, extensions, or installations. It's Just
JavaScript™. Note: WebTorrent does not support UDP/TCP peers in browser.
Simply include the
webtorrent.min.js script
on your page to start fetching files over WebRTC using the BitTorrent protocol, or
require('webtorrent') with browserify. See demo apps
and code examples below.
To make BitTorrent work over WebRTC (which is the only P2P transport that works on the
web) we made some protocol changes. Therefore, a browser-based WebTorrent client or "web
peer" can only connect to other clients that support WebTorrent/WebRTC.
To seed files to web peers, use a client that supports WebTorrent, e.g.
WebTorrent Desktop, a desktop client with a
familiar UI that can connect to web peers,
webtorrent-hybrid, a command line program,
or Instant.io, a website. Established torrent clients like
Vuze have already added WebTorrent support so
they can connect to both normal and web peers. We hope other clients will follow.
Features
Torrent client for node.js & the browser (same npm package!)
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!
In the browser
Downloading a file is simple:
constWebTorrent=require('webtorrent')constclient=newWebTorrent()constmagnetURI='...'client.add(magnetURI,function(torrent){// Got torrent metadata!console.log('Client is downloading:',torrent.infoHash)torrent.files.forEach(function(file){// Display the file by appending it to the DOM. Supports video, audio, images, and// more. Specify a container element (CSS selector or reference to DOM node).file.appendTo('body')})})
Seeding a file is simple, too:
constdragDrop=require('drag-drop')constWebTorrent=require('webtorrent')constclient=newWebTorrent()// When user drops files on the browser, create a new torrent and start seeding it!dragDrop('body',function(files){client.seed(files,function(torrent){console.log('Client is seeding:',torrent.infoHash)})})
WebTorrent works great with browserify, an npm package that lets
you use node-style require() to organize your browser code and load modules installed by npm (as seen in the previous examples).
Webpack
WebTorrent also works with webpack, another module
bundler. However, webpack requires the following extra configuration:
{target: 'web',node: {fs: 'empty'}}
Or, you can just use the pre-built version via
require('webtorrent/webtorrent.min.js') and skip the webpack configuration.
Script tag
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:
<scriptsrc="webtorrent.min.js"></script>
The WebTorrent script is also hosted on fast, reliable CDN infrastructure (Cloudflare and
MaxCDN) for easy inclusion on your site:
Oct 2013 - RealtimeConf - WebRTC Black Magic (first mention of idea for WebTorrent)
Modules
Most of the active development is happening inside of small npm packages which are used by WebTorrent.
The Node Way™
"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"
Modules
These are the main modules that make up WebTorrent:
In node, enable debug logs by setting the DEBUG environment variable to the name of the
module you want to debug (e.g. bittorrent-protocol, or * to print all logs).
DEBUG=* webtorrent
In the browser, enable debug logs by running this in the developer console:
webtorrent/webtorrent
WebTorrent
The streaming torrent client. For node.js and the web.
Sponsored by
WebTorrent is a streaming torrent client for node.js and the browser. YEP, THAT'S RIGHT. THE BROWSER. It's written completely in JavaScript – the language of the web – so the same code works in both runtimes.
In node.js, this module is a simple torrent client, using TCP and UDP to talk to other torrent clients.
In the browser, WebTorrent uses WebRTC (data channels) for peer-to-peer transport. It can be used without browser plugins, extensions, or installations. It's Just JavaScript™. Note: WebTorrent does not support UDP/TCP peers in browser.
Simply include the
webtorrent.min.js
script on your page to start fetching files over WebRTC using the BitTorrent protocol, orrequire('webtorrent')
with browserify. See demo apps and code examples below.To make BitTorrent work over WebRTC (which is the only P2P transport that works on the web) we made some protocol changes. Therefore, a browser-based WebTorrent client or "web peer" can only connect to other clients that support WebTorrent/WebRTC.
To seed files to web peers, use a client that supports WebTorrent, e.g. WebTorrent Desktop, a desktop client with a familiar UI that can connect to web peers, webtorrent-hybrid, a command line program, or Instant.io, a website. Established torrent clients like Vuze have already added WebTorrent support so they can connect to both normal and web peers. We hope other clients will follow.
Features
Browser/WebRTC environment features
<video>
tag (webm (vp8, vp9)
ormp4 (h.264)
)Install
To install WebTorrent for use in node or the browser with
require('webtorrent')
, run:To install a
webtorrent
command line program, run:To install a WebTorrent desktop application for Mac, Windows, or Linux, see WebTorrent Desktop.
Ways to help
#webtorrent
to help with development or to hang out with some mad science hackers :)Who is using WebTorrent today?
Lots of folks!
WebTorrent API Documentation
Read the full API Documentation.
Usage
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!
In the browser
Downloading a file is simple:
Seeding a file is simple, too:
There are more examples in docs/get-started.md.
Browserify
WebTorrent works great with browserify, an npm package that lets you use node-style require() to organize your browser code and load modules installed by npm (as seen in the previous examples).
Webpack
WebTorrent also works with webpack, another module bundler. However, webpack requires the following extra configuration:
Or, you can just use the pre-built version via
require('webtorrent/webtorrent.min.js')
and skip the webpack configuration.Script tag
WebTorrent is also available as a standalone script (
webtorrent.min.js
) which exposesWebTorrent
on thewindow
object, so it can be used with just a script tag:The WebTorrent script is also hosted on fast, reliable CDN infrastructure (Cloudflare and MaxCDN) for easy inclusion on your site:
Chrome App
If you want to use WebTorrent in a Chrome App, you can include the following script:
Be sure to enable the
chrome.sockets.udp
andchrome.sockets.tcp
permissions!In Node.js
WebTorrent also works in node.js, using the same npm package! It's mad science!
NOTE: To connect to "web peers" (browsers) in addition to normal BitTorrent peers, use webtorrent-hybrid which includes WebRTC support for node.
As a command line app
WebTorrent is also available as a command line app. Here's how to use it:
To download a torrent:
To stream a torrent to a device like AirPlay or Chromecast, just pass a flag:
There are many supported streaming options:
In addition to magnet uris, WebTorrent supports many ways to specify a torrent.
Talks about WebTorrent
Modules
Most of the active development is happening inside of small npm packages which are used by WebTorrent.
The Node Way™
Modules
These are the main modules that make up WebTorrent:
Enable debug logs
In node, enable debug logs by setting the
DEBUG
environment variable to the name of the module you want to debug (e.g.bittorrent-protocol
, or*
to print all logs).DEBUG=* webtorrent
In the browser, enable debug logs by running this in the developer console:
Disable by running this:
License
MIT. Copyright (c) Feross Aboukhadijeh and WebTorrent, LLC.