Top Related Projects
Full-featured BitTorrent client package and utilities
Official Transmission BitTorrent client repository
qBittorrent BitTorrent client
an efficient feature complete C++ bittorrent implementation
☁️ Cloud Torrent: a self-hosted remote torrent client
📡 Simple WebRTC video, voice, and data channels
Quick Overview
WebTorrent is a streaming torrent client for the web browser and Node.js. It allows users to download and stream torrents directly in the browser without requiring any additional software or plugins. WebTorrent uses WebRTC for peer-to-peer transport and can work alongside the regular BitTorrent network.
Pros
- Browser-based: No need for separate torrent client software
- Streaming capabilities: Start watching/listening to content before the download is complete
- JavaScript implementation: Easy integration with web applications
- Works with existing torrent ecosystem: Compatible with regular BitTorrent clients
Cons
- Limited browser support: Requires WebRTC, which is not available in all browsers
- Performance: May not be as efficient as native torrent clients for large downloads
- Legal concerns: Potential misuse for distributing copyrighted material
- Network limitations: Some corporate or public networks may block WebRTC traffic
Code Examples
- Creating a WebTorrent client:
const WebTorrent = require('webtorrent')
const client = new WebTorrent()
- Adding a torrent and streaming to a video element:
const magnetURI = 'magnet:?xt=urn:btih:...'
client.add(magnetURI, (torrent) => {
const file = torrent.files.find(file => file.name.endsWith('.mp4'))
file.renderTo('video#player')
})
- Seeding a file:
const file = new File(['Hello World'], 'hello.txt', { type: 'text/plain' })
client.seed(file, (torrent) => {
console.log('Client is seeding:', torrent.magnetURI)
})
Getting Started
To use WebTorrent in a browser environment:
- Include the WebTorrent script in your HTML:
<script src="https://cdn.jsdelivr.net/npm/webtorrent@latest/webtorrent.min.js"></script>
- Create a new WebTorrent client and add a torrent:
const client = new WebTorrent()
const torrentId = 'magnet:?xt=urn:btih:...'
client.add(torrentId, (torrent) => {
torrent.files.forEach(file => {
file.appendTo('body')
})
})
For Node.js, install WebTorrent using npm:
npm install webtorrent
Then use it in your JavaScript file:
const WebTorrent = require('webtorrent')
const client = new WebTorrent()
// Add torrents and handle them as shown in the browser example
Competitor Comparisons
Full-featured BitTorrent client package and utilities
Pros of torrent
- Written in Go, offering better performance and concurrency
- More comprehensive BitTorrent protocol implementation
- Supports both client and server functionalities
Cons of torrent
- Lacks browser-based implementation
- Requires more setup and configuration compared to WebTorrent
- Less focus on streaming capabilities
Code Comparison
WebTorrent (JavaScript):
const WebTorrent = require('webtorrent')
const client = new WebTorrent()
client.add(torrentId, function (torrent) {
torrent.files.forEach(file => {
file.appendTo('body')
})
})
torrent (Go):
import "github.com/anacrolix/torrent"
client, _ := torrent.NewClient(nil)
t, _ := client.AddMagnet("magnet:?xt=urn:btih:...")
<-t.GotInfo()
t.DownloadAll()
client.WaitAll()
WebTorrent focuses on simplicity and browser compatibility, making it easy to stream torrents directly in web applications. It's ideal for web-based projects and quick implementations.
torrent provides a more robust and flexible BitTorrent library, suitable for building complex torrent applications and services. It offers better performance but requires more setup and is not designed for browser use.
Both libraries have their strengths, and the choice depends on the specific requirements of your project, such as platform, performance needs, and desired features.
Official Transmission BitTorrent client repository
Pros of Transmission
- More mature and established project with a longer history
- Supports a wider range of platforms, including desktop and server environments
- Offers advanced features like remote control and scheduling
Cons of Transmission
- Lacks browser-based functionality without additional setup
- Generally requires installation and is not as easily embeddable in web applications
- May have a steeper learning curve for new users
Code Comparison
Transmission (C):
tr_torrentSetFileDLs(tor, fileIndices, fileCount, do_download);
tr_torrentResetCompletion(tor);
tr_torrentSetDirty(tor);
WebTorrent (JavaScript):
client.add(torrentId, { path: '/path/to/folder' }, (torrent) => {
torrent.on('done', () => console.log('Torrent download finished'))
})
Key Differences
- Transmission is primarily written in C, while WebTorrent is JavaScript-based
- WebTorrent focuses on browser and Node.js environments, making it more suitable for web applications
- Transmission offers a more traditional BitTorrent client experience with a broader feature set
- WebTorrent provides a simpler API for integrating torrent functionality into web projects
qBittorrent BitTorrent client
Pros of qBittorrent
- Full-featured desktop application with a robust GUI
- Supports a wider range of torrent protocols and features
- More mature project with a larger user base and community support
Cons of qBittorrent
- Not web-based, requiring installation on each device
- Heavier resource usage compared to WebTorrent
- Less suitable for browser-based or lightweight implementations
Code Comparison
qBittorrent (C++):
void TorrentHandle::addTrackers(const QVector<TrackerEntry> &trackers)
{
const lt::torrent_handle nativeHandle = m_nativeHandle;
for (const TrackerEntry &tracker : trackers)
nativeHandle.add_tracker(tracker.nativeEntry());
}
WebTorrent (JavaScript):
WebTorrent.prototype.add = function (torrentId, opts, ontorrent) {
if (this.destroyed) throw new Error('client is destroyed')
if (typeof opts === 'function') [opts, ontorrent] = [{}, opts]
const client = this
const torrent = new Torrent(torrentId, client, opts)
this.torrents.push(torrent)
Both projects serve different use cases. qBittorrent is a comprehensive desktop torrent client, while WebTorrent focuses on browser-based and Node.js environments. The code snippets highlight the language difference (C++ vs. JavaScript) and the varying approaches to handling torrents in their respective ecosystems.
an efficient feature complete C++ bittorrent implementation
Pros of libtorrent
- More mature and feature-rich C++ library with extensive documentation
- Supports a wider range of BitTorrent protocols and extensions
- Better performance and scalability for large-scale applications
Cons of libtorrent
- Steeper learning curve due to C++ complexity and extensive API
- Requires compilation and platform-specific setup
- Less suitable for web-based or browser applications
Code Comparison
libtorrent (C++):
#include <libtorrent/session.hpp>
#include <libtorrent/add_torrent_params.hpp>
#include <libtorrent/torrent_handle.hpp>
lt::session ses;
lt::add_torrent_params p;
p.save_path = "./";
p.ti = std::make_shared<lt::torrent_info>("test.torrent");
lt::torrent_handle h = ses.add_torrent(p);
WebTorrent (JavaScript):
const WebTorrent = require('webtorrent')
const client = new WebTorrent()
const torrentId = 'magnet:?xt=urn:btih:...'
client.add(torrentId, { path: './' }, (torrent) => {
console.log('Client is downloading:', torrent.infoHash)
})
Summary
libtorrent is a powerful C++ library suitable for high-performance, native applications, while WebTorrent offers a simpler JavaScript-based solution ideal for web and browser environments. The choice between them depends on the specific project requirements, target platform, and developer expertise.
☁️ Cloud Torrent: a self-hosted remote torrent client
Pros of cloud-torrent
- Designed for server-side deployment, allowing remote access to torrents
- Includes a web-based user interface for managing torrents
- Supports downloading directly to the server, useful for seedboxes
Cons of cloud-torrent
- Less active development and community support compared to WebTorrent
- Limited to server-side usage, not suitable for browser-based applications
- Fewer features and integrations with other technologies
Code Comparison
WebTorrent:
const WebTorrent = require('webtorrent')
const client = new WebTorrent()
client.add(torrentId, (torrent) => {
torrent.files.forEach(file => {
file.createReadStream().pipe(process.stdout)
})
})
cloud-torrent:
engine := torrent.NewEngine(config)
engine.NewTorrent(magnetLink)
engine.StartTorrent(torrentHash)
for _, f := range engine.GetTorrent(torrentHash).Files {
fmt.Println(f.Path)
}
Both projects aim to provide torrent functionality, but they differ in their primary use cases and implementation languages. WebTorrent focuses on browser and Node.js environments, while cloud-torrent is designed for server-side deployment with a web interface. WebTorrent has a larger community and more active development, making it more suitable for diverse applications. cloud-torrent, on the other hand, is better suited for remote torrent management and seedbox setups.
📡 Simple WebRTC video, voice, and data channels
Pros of simple-peer
- Lightweight and focused solely on WebRTC peer connections
- Easier to integrate into existing projects due to its simplicity
- More flexible for custom WebRTC implementations
Cons of simple-peer
- Lacks built-in features for torrent-specific functionality
- Requires more manual setup for advanced use cases
- Less comprehensive documentation compared to WebTorrent
Code Comparison
simple-peer:
const peer = new SimplePeer({ initiator: true })
peer.on('signal', data => {
// send signal data to peer
})
peer.on('connect', () => {
peer.send('hello')
})
WebTorrent:
const client = new WebTorrent()
const torrentId = 'magnet:?xt=urn:btih:...'
client.add(torrentId, (torrent) => {
torrent.files.forEach(file => {
file.appendTo('body')
})
})
Summary
simple-peer is a focused WebRTC library, ideal for developers who need direct control over peer connections. WebTorrent, on the other hand, provides a more comprehensive solution for implementing BitTorrent functionality in the browser, including WebRTC as part of its broader feature set. The choice between the two depends on the specific requirements of your project and the level of abstraction you need.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
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, or
import WebTorrent from 'webtorrent'
with browserify or webpack. 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!)
- Insanely fast
- Download multiple torrents simultaneously, efficiently
- Pure Javascript (no native dependencies)
- Exposes files as streams
- Fetches pieces from the network on-demand so seeking is supported (even before torrent is finished)
- Seamlessly switches between sequential and rarest-first piece selection strategy
- Supports advanced torrent client features
- magnet uri support via ut_metadata
- peer discovery via dht, tracker, lsd, and ut_pex
- protocol extension api for adding new extensions
- Comprehensive test suite (runs completely offline, so it's reliable and fast)
- Check all the supported BEPs here
Browser/WebRTC environment features
- WebRTC data channels for lightweight peer-to-peer communication with no plugins
- No silos. WebTorrent is a P2P network for the entire web. WebTorrent clients running on one domain can connect to clients on any other domain.
- Stream video torrents into a
<video>
tag (webm, mkv, mp4, ogv, mov, etc (AV1, H264, HEVC*, VP8, VP9, AAC, FLAC, MP3, OPUS, Vorbis, etc)
) - Supports Chrome, Firefox, Opera and Safari.
Install
To install WebTorrent for use in node or the browser with import WebTorrent from 'webtorrent'
, run:
npm install webtorrent
To install a webtorrent
command line program, run:
npm install webtorrent-cli -g
To install a WebTorrent desktop application for Mac, Windows, or Linux, see WebTorrent Desktop.
Ways to help
- Join us in Gitter or on freenode at
#webtorrent
to help with development or to hang out with some mad science hackers :) - Create a new issue to report bugs
- Fix an issue. WebTorrent is an OPEN Open Source Project!
Who is using WebTorrent today?
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:
import WebTorrent from 'webtorrent'
const client = new WebTorrent()
const magnetURI = '...'
client.add(magnetURI, torrent => {
// Got torrent metadata!
console.log('Client is downloading:', torrent.infoHash)
for (const file of torrent.files) {
document.body.append(file.name)
}
})
Seeding a file is simple, too:
import dragDrop from 'drag-drop'
import WebTorrent from 'webtorrent'
const client = new WebTorrent()
// When user drops files on the browser, create a new torrent and start seeding it!
dragDrop('body', files => {
client.seed(files, torrent => {
console.log('Client is seeding:', torrent.infoHash)
})
})
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 extra configuration which you can find in the webpack bundle config used by webtorrent.
Or, you can just use the pre-built version via
import WebTorrent from 'webtorrent/dist/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:
<script type='module'>
import WebTorrent from 'webtorrent.min.js'
</script>
The WebTorrent script is also hosted on fast, reliable CDN infrastructure (Cloudflare and MaxCDN) for easy inclusion on your site:
<script type='module'>
import WebTorrent from 'https://esm.sh/webtorrent'
</script>
Chrome App
If you want to use WebTorrent in a Chrome App, you can include the following script:
<script type='module'>
import WebTorrent from 'webtorrent.chromeapp.js'
</script>
Be sure to enable the chrome.sockets.udp
and chrome.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:
$ npm install webtorrent-cli -g
$ webtorrent --help
To download a torrent:
$ webtorrent magnet_uri
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 Apple TV
--chromecast Chromecast
--mplayer MPlayer
--mpv MPV
--omx [jack] omx [default: hdmi]
--vlc VLC
--xbmc XBMC
--stdout standard out [implies --quiet]
In addition to magnet uris, WebTorrent supports many ways to specify a torrent.
Talks about WebTorrent
- Sep 2017 - Nordic JS - Get Rich Quick With P2P Crypto Currency
- May 2017 - Char.la - WebTorrent and Peerify (Spanish)
- Nov 2016 - NodeConf Argentina - Real world Electron: Building Cross-platform desktop apps with JavaScript
- May 2016 - SIGNAL Conference - BitTorrent in the Browser
- May 2015 - Data Terra Nemo - WebTorrent: Mother of all demos
- May 2015 - Data Terra Nemo - WebRTC Everywhere
- Nov 2014 - JSConf Asia - How WebTorrent Works
- Sep 2014 - NodeConf EU - WebRTC Mad Science (first working WebTorrent demo)
- Apr 2014 - CraftConf - Bringing BitTorrent to the Web
- May 2014 - JS.LA - How I Built a BitTorrent Client in the Browser (progress update; node client working)
- 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:
module | tests | version | description |
---|---|---|---|
webtorrent | torrent client (this module) | ||
bittorrent-dht | distributed hash table client | ||
bittorrent-peerid | identify client name/version | ||
bittorrent-protocol | bittorrent protocol stream | ||
bittorrent-tracker | bittorrent tracker server/client | ||
bittorrent-lsd | bittorrent local service discovery | ||
create-torrent | create .torrent files | ||
magnet-uri | parse magnet uris | ||
parse-torrent | parse torrent identifiers | ||
torrent-discovery | find peers via dht, tracker, and lsd | ||
ut_metadata | metadata for magnet uris (protocol extension) | ||
ut_pex | peer discovery (protocol extension) |
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:
localStorage.setItem('debug', '*')
Disable by running this:
localStorage.removeItem('debug')
License
MIT. Copyright (c) Feross Aboukhadijeh and WebTorrent, LLC.
Top Related Projects
Full-featured BitTorrent client package and utilities
Official Transmission BitTorrent client repository
qBittorrent BitTorrent client
an efficient feature complete C++ bittorrent implementation
☁️ Cloud Torrent: a self-hosted remote torrent client
📡 Simple WebRTC video, voice, and data channels
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot