Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
5142f07
Added βTorrent to production list
DiegoRBaquero Dec 1, 2015
68b1110
Merge pull request #499 from DiegoRBaquero/patch-1
feross Dec 1, 2015
0693711
add new collaborators
feross Dec 1, 2015
2c3f59d
executable@2
feross Dec 2, 2015
388dd3f
bittorrent-dht@4
feross Dec 2, 2015
e0db3e8
fix test for create-torrent change
feross Dec 2, 2015
08ae55c
remove npm cache
feross Dec 2, 2015
149a2f0
travis: test node 5
feross Dec 2, 2015
e68ddb5
Merge pull request #500 from feross/update-deps
feross Dec 2, 2015
0f31614
Merge pull request #498 from feross/fix-control-c
feross Dec 2, 2015
80650f3
Merge pull request #501 from feross/node5
feross Dec 2, 2015
9328dc9
0.63.0
feross Dec 2, 2015
cfca533
build
feross Dec 2, 2015
16e4445
timeRemaining should be 0 once done (Fix #503)
DiegoRBaquero Dec 2, 2015
efbc9f8
zuul: test current and last chrome/firefox version
feross Dec 2, 2015
5385c9d
Merge pull request #504 from feross/DiegoRBaquero-patch-1
feross Dec 2, 2015
f6c872e
0.63.1
feross Dec 2, 2015
46487f5
build
feross Dec 2, 2015
a3185b9
Update README (Fix #495)
DiegoRBaquero Dec 2, 2015
0619d4d
Merge pull request #506 from feross/DiegoRBaquero-patch-1
feross Dec 2, 2015
c06529d
fix tests
feross Dec 2, 2015
6fee6b2
Capitalize "p2p" in README.
adjohnson916 Dec 3, 2015
ba26a45
Merge pull request #508 from adjohnson916/patch-1
feross Dec 3, 2015
7e8f9d2
Merge pull request #505 from feross/zuul-versions
feross Dec 3, 2015
eaf085b
Standardize hash variable names (fix #374)
feross Dec 3, 2015
b4f2040
browser: exclude two unused packages
feross Dec 3, 2015
8e88e4a
torrent-discovery@4
feross Dec 3, 2015
3c3a06a
bittorrent-dht@5
feross Dec 3, 2015
0e51347
bittorrent-swarm@6
feross Dec 3, 2015
f0570b3
ut_metadata@3
feross Dec 3, 2015
be882a4
Merge pull request #509 from feross/unused-deps
feross Dec 4, 2015
3a6a7af
Merge pull request #510 from feross/standardize-var-names
feross Dec 4, 2015
1bd5fa6
self -> this
feross Dec 4, 2015
87ff003
code style
feross Dec 4, 2015
3f148aa
remove debug statement
feross Dec 4, 2015
55266e1
dedupe urlList
feross Dec 4, 2015
2ff3820
0.63.2
feross Dec 4, 2015
074836e
build
feross Dec 4, 2015
8451b86
zelda@3
feross Dec 5, 2015
cbe31a8
add debug log
feross Dec 5, 2015
721ffa7
fix talk links
feross Dec 7, 2015
7f01f07
remove clone script
feross Dec 7, 2015
d084f3f
move js standard style logo to top of readme
feross Dec 7, 2015
23dbefe
remove ip-set from readme
feross Dec 7, 2015
4a96eab
readme: remove old "known issues" section
feross Dec 7, 2015
377e7dc
only test last two browsers
feross Dec 7, 2015
7c48a6b
move sauce labs badge to top
feross Dec 7, 2015
8a1333e
remove unused dep zelda
feross Dec 7, 2015
6aff656
0.63.3
feross Dec 7, 2015
276e167
build
feross Dec 7, 2015
efa410d
Initialize pieces on constructor
DiegoRBaquero Dec 9, 2015
cf9e89f
Standard fix
DiegoRBaquero Dec 9, 2015
b302418
Merge pull request #520 from feross/DiegoRBaquero-patch-1
DiegoRBaquero Dec 9, 2015
b08894a
0.63.4
DiegoRBaquero Dec 9, 2015
aac23e9
build
DiegoRBaquero Dec 9, 2015
6a5c846
Merge pull request #521 from feross/build-0.63.4
DiegoRBaquero Dec 9, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
language: node_js
node_js:
- '4.2'
- 'node'
- '4'
- '0.12'
sudo: false
env:
global:
- secure: AJsEWFnWC5W8hcF3hJzm3PT7heazJpKg85xiSvIWVzLHZU/s0h4+WfJ6t0F9v3L4awaowm62vy8CRaxRkB4lJyJg+JK2K0QN7lNFGj2f8Jx2cFlVJ1IyY959GY4iUg66JrNj1yzS02+yQfweDngyifqzb7IlxnowiveDjUO2gyo=
- secure: hvihwLUqlPchrGFXKWFF7iKRugISU7r/gLBo6O63nPeg0OwnYqYcC2BnBWoSiOdu9oR5bM4a5u0os04XL+bP3dqt324g0uBTqvyyxD6NhBsphVFkUmdUH3HMe7IQY6JTns96KT/6UkQapKhIuW4CUDeidR+5NFKvyRdKIjSawS4=
cache:
directories:
- node_modules
4 changes: 2 additions & 2 deletions .zuul.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ui: tape
browsers:
- name: chrome
version: latest
version: -1..latest
- name: firefox
version: latest
version: -1..latest
73 changes: 17 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

### Streaming torrent client for node & the browser

[![Sauce Test Status][webtorrent-sauce-image]][webtorrent-sauce-url]
     
[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](http://standardjs.com)

**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.
Expand All @@ -24,7 +28,7 @@ on your page to start fetching files over WebRTC using the BitTorrent protocol,
`require('webtorrent')` with [browserify](http://browserify.org/). See [demo apps
](#webtorrent-in-production) and [code examples](#usage) below.

To make BitTorrent work over WebRTC (which is the only p2p transport that works on the
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.

Expand Down Expand Up @@ -66,8 +70,6 @@ connect to both normal *and* web peers.
- Stream video torrents into a `<video>` tag (`webm (vp8, vp9)` or `mp4 (h.264)`)
- Supports Chrome, Firefox, and Opera.

[![Sauce Test Status][webtorrent-sauce-image]][webtorrent-sauce-url]

#### Node-only features

- Stream to **AirPlay**, **Chromecast**, **VLC player**, and many other devices/players
Expand Down Expand Up @@ -105,6 +107,7 @@ npm install webtorrent -g
- **[Webtorrentapp](https://github.com/alexeisavca/webtorrentapp)** – A tool/platform for launching web apps from torrents
- **[People-driven web](http://www.peopledrivenweb.com/)** – Decentralized content management system ([source code](https://github.com/peopledrivenweb/pwjs))
- **[PeerCloud](https://github.com/jhiesey/peercloud)** - Serverless websites via WebTorrent
- **[βTorrent](https://btorrent.xyz)** - Fully-featured WebTorrent browser client ([source code](https://github.com/DiegoRBaquero/bTorrent))
- Your app here! (send a PR or open an issue with your app's URL)

### Usage
Expand Down Expand Up @@ -272,7 +275,7 @@ Start seeding a new torrent.

`input` can be any of the following:

- path to the file or folder on filesystem (string)
- path to the file or folder on filesystem (string) (Node.js only)
- W3C [File](https://developer.mozilla.org/en-US/docs/Web/API/File) object (from an `<input>` or drag and drop)
- W3C [FileList](https://developer.mozilla.org/en-US/docs/Web/API/FileList) object (basically an array of `File` objects)
- Node [Buffer](http://nodejs.org/api/buffer.html) object (works in [the browser](https://www.npmjs.org/package/buffer))
Expand Down Expand Up @@ -579,8 +582,6 @@ These are the main modules that make up WebTorrent:
| [bittorrent-swarm][bittorrent-swarm] | [![][bittorrent-swarm-ti]][bittorrent-swarm-tu] | [![][bittorrent-swarm-ni]][bittorrent-swarm-nu] | bittorrent connection manager
| [bittorrent-tracker][bittorrent-tracker] | [![][bittorrent-tracker-ti]][bittorrent-tracker-tu] | [![][bittorrent-tracker-ni]][bittorrent-tracker-nu] | bittorrent tracker server/client
| [create-torrent][create-torrent] | [![][create-torrent-ti]][create-torrent-tu] | [![][create-torrent-ni]][create-torrent-nu] | create .torrent files
| [ip-set][ip-set] | [![][ip-set-ti]][ip-set-tu] | [![][ip-set-ni]][ip-set-nu] | efficient mutable ip set
| [load-ip-set][load-ip-set] | [![][load-ip-set-ti]][load-ip-set-tu] | [![][load-ip-set-ni]][load-ip-set-nu] | load ip sets from local/network
| [magnet-uri][magnet-uri] | [![][magnet-uri-ti]][magnet-uri-tu] | [![][magnet-uri-ni]][magnet-uri-nu] | parse magnet uris
| [parse-torrent][parse-torrent] | [![][parse-torrent-ti]][parse-torrent-tu] | [![][parse-torrent-ni]][parse-torrent-nu] | parse torrent identifiers
| [torrent-discovery][torrent-discovery] | [![][torrent-discovery-ti]][torrent-discovery-tu] | [![][torrent-discovery-ni]][torrent-discovery-nu] | find peers via dht and tracker
Expand Down Expand Up @@ -637,18 +638,6 @@ These are the main modules that make up WebTorrent:
[create-torrent-ni]: https://img.shields.io/npm/v/create-torrent.svg?style=flat
[create-torrent-nu]: https://npmjs.org/package/create-torrent

[ip-set]: https://github.com/fisch0920/ip-set
[ip-set-ti]: https://img.shields.io/travis/fisch0920/ip-set.svg?style=flat
[ip-set-tu]: https://travis-ci.org/fisch0920/ip-set
[ip-set-ni]: https://img.shields.io/npm/v/ip-set.svg?style=flat
[ip-set-nu]: https://npmjs.org/package/ip-set

[load-ip-set]: https://github.com/feross/load-ip-set
[load-ip-set-ti]: https://img.shields.io/travis/feross/load-ip-set.svg?style=flat
[load-ip-set-tu]: https://travis-ci.org/feross/load-ip-set
[load-ip-set-ni]: https://img.shields.io/npm/v/load-ip-set.svg?style=flat
[load-ip-set-nu]: https://npmjs.org/package/load-ip-set

[magnet-uri]: https://github.com/feross/magnet-uri
[magnet-uri-ti]: https://img.shields.io/travis/feross/magnet-uri.svg?style=flat
[magnet-uri-tu]: https://travis-ci.org/feross/magnet-uri
Expand Down Expand Up @@ -694,23 +683,14 @@ WebTorrent is only possible due to the excellent work of the following contribut
<tr><th align="left">Iván Todorovich</th><td><a href="https://github.com/ivantodorovich">GitHub/ivantodorovich</a></td><td><a href="http://twitter.com/ivantodorovich">Twitter/@ivantodorovich</a></td></tr>
<tr><th align="left">Mathias Buus</th><td><a href="https://github.com/mafintosh">GitHub/mafintosh</a></td><td><a href="http://twitter.com/mafintosh">Twitter/@mafintosh</a></td></tr>
<tr><th align="left">Bob Ren</th><td><a href="https://github.com/bobrenjc93">GitHub/bobrenjc93</a></td><td><a href="http://twitter.com/bobrenjc93">Twitter/@bobrenjc93</a></td></tr>
<tr><th align="left">James Halliday</th><td><a href="https://github.com/substack">GitHub/substack</a></td><td><a href="http://twitter.com/substack">Twitter/@substack</a></td></tr>
<tr><th align="left">Gilles De Mey</th><td><a href="https://github.com/gillesdemey">GitHub/gillesdemey</a></td><td><a href="http://twitter.com/gdemey">Twitter/@gdemey</a></td></tr>
<tr><th align="left">Valérian Galliat</th><td><a href="https://github.com/valeriangalliat">GitHub/valeriangalliat</a></td><td><a href="http://twitter.com/valeriangalliat">Twitter/@valeriangalliat</a></td></tr>
<tr><th align="left">Joseph Frazier</th><td><a href="https://github.com/josephfrazier">GitHub/josephfrazier</a></td><td></td></tr>
<tr><th align="left">Lucas Pelegrino</th><td><a href="https://github.com/lucaswxp">GitHub/lucaswxp</a></td><td><a href="http://twitter.com/lucaswxp">Twitter/@lucaswxp</a></td></tr>
<tr><th align="left">Diego Rodríguez B.</th><td><a href="https://github.com/DiegoRBaquero">GitHub/DiegoRBaquero</a></td><td><a href="http://twitter.com/DiegoRBaquero">Twitter/@DiegoRBaquero</a></td></tr>
</tbody></table>

#### Clone the code

```bash
git clone https://github.com/feross/webtorrent.git
cd webtorrent
npm install
./bin/cmd.js --help
```

#### JavaScript Standard Style

WebTorrent uses [JavaScript Standard Style](https://github.com/feross/standard).

[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)

#### Enable debug logs

In **node**, enable debug logs by setting the `DEBUG` environment variable to the name of the
Expand Down Expand Up @@ -738,32 +718,13 @@ Disable by running this:
localStorage.removeItem('debug')
```

#### Clone all dependencies

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:

```bash
./bin/clone.sh
```

### Talks about WebTorrent

- Nov 2014 (NodeConf Asia) - [WebTorrent](https://www.youtube.com/watch?v=kxHRATfvnlw)
- Sep 2014 (NodeConf EU) – WebTorrent &amp; WebRTC: Mad Science (first working demo of WebTorrent)
- May 2015 (Data Terra Nemo) - [WebTorrent: Mother of all demos](https://www.youtube.com/watch?v=RRtNEcAaUO8)
- Nov 2014 (JSConf Asia) - [How WebTorrent Works](https://www.youtube.com/watch?v=kxHRATfvnlw)
- Sep 2014 (NodeConf EU) – [WebTorrent Mad Science](https://www.youtube.com/watch?v=BVBXkzVjvPc) (first working WebTorrent demo)
- May 2014 (JS.LA) – [How I Built a BitTorrent Client in the Browser](https://vimeo.com/97324247) (progress update; node client working)
- Oct 2013 (RealtimeConf) – [WebRTC Black Magic (RealtimeConf)](https://vimeo.com/77265280) (where I first shared the idea of WebTorrent)

### Known issues

#### Downloads don't start on Chromebook

Chromebooks are set to refuse all incoming connections by default. To change this, run:

```bash
sudo iptables -P INPUT ACCEPT
```
- Oct 2013 (RealtimeConf) – [WebRTC Black Magic](https://vimeo.com/77265280) (first mention of idea for WebTorrent)

### License

Expand Down
27 changes: 0 additions & 27 deletions bin/clone.sh

This file was deleted.

46 changes: 27 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,38 @@ var Torrent = require('./lib/torrent')

inherits(WebTorrent, EventEmitter)

/**
* WebTorrent version.
*/
var VERSION = require('./package.json').version

/**
* BitTorrent client version string (used in peer ID).
* Generated from package.json major and minor version. For example:
* Version number in Azureus-style. Generated from major and minor semver version.
* For example:
* '0.16.1' -> '0016'
* '1.2.5' -> '0102'
*/
var VERSION_STR = VERSION.match(/([0-9]+)/g).slice(0, 2).map(zeroFill(2)).join('')

/**
* Version prefix string (used in peer ID). WebTorrent uses the Azureus-style
* encoding: '-', two characters for client id ('WW'), four ascii digits for version
* number, '-', followed by random numbers.
* For example:
* '-WW0102-'...
*/
var VERSION_PREFIX = '-WW' + VERSION_STR + '-'

/**
* WebTorrent Client
* @param {Object} opts
*/
function WebTorrent (opts) {
var self = this
if (!(self instanceof WebTorrent)) return new WebTorrent(opts)
if (!opts) opts = {}
EventEmitter.call(self)

if (!opts) opts = {}
if (!debug.enabled) self.setMaxListeners(0)

self.destroyed = false
Expand All @@ -51,27 +64,23 @@ function WebTorrent (opts) {
self.downloadSpeed = speedometer()
self.uploadSpeed = speedometer()

self.peerId = opts.peerId === undefined
? new Buffer('-WW' + VERSION_STR + '-' + hat(48), 'utf8')
: typeof opts.peerId === 'string'
? new Buffer(opts.peerId, 'hex')
: opts.peerId
self.peerIdHex = self.peerId.toString('hex')
self.peerId = typeof opts.peerId === 'string'
? opts.peerId
: (opts.peerId || new Buffer(VERSION_PREFIX + hat(48))).toString('hex')
self.peerIdBuffer = new Buffer(self.peerId, 'hex')

self.nodeId = opts.nodeId === undefined
? new Buffer(hat(160), 'hex')
: typeof opts.nodeId === 'string'
? new Buffer(opts.nodeId, 'hex')
: opts.nodeId
self.nodeIdHex = self.nodeId.toString('hex')
self.nodeId = typeof opts.nodeId === 'string'
? opts.nodeId
: (opts.nodeId && opts.nodeId.toString('hex')) || hat(160)
self.nodeIdBuffer = new Buffer(self.nodeId, 'hex')

if (opts.dht !== false && typeof DHT === 'function' /* browser exclude */) {
// use a single DHT instance for all torrents, so the routing table can be reused
self.dht = new DHT(extend({ nodeId: self.nodeId }, opts.dht))
self.dht.listen(opts.dhtPort)
}

debug('new webtorrent (peerId %s, nodeId %s)', self.peerIdHex, self.nodeIdHex)
debug('new webtorrent (peerId %s, nodeId %s)', self.peerId, self.nodeId)

if (typeof loadIPSet === 'function') {
loadIPSet(opts.blocklist, {
Expand Down Expand Up @@ -145,14 +154,13 @@ WebTorrent.prototype.download = function (torrentId, opts, ontorrent) {
if (typeof opts === 'function') return self.add(torrentId, null, opts)
debug('add')
if (!opts) opts = {}
else opts = extend({}, opts)
else opts = extend(opts)

opts.client = self

var torrent = self.get(torrentId)

function _ontorrent () {
debug('on torrent %s', torrent.infoHash)
if (typeof ontorrent === 'function') ontorrent(torrent)
}

Expand Down Expand Up @@ -193,7 +201,7 @@ WebTorrent.prototype.seed = function (input, opts, onseed) {
if (typeof opts === 'function') return self.seed(input, null, opts)
debug('seed')
if (!opts) opts = {}
else opts = extend({}, opts)
else opts = extend(opts)

// When seeding from filesystem, initialize store from that path (avoids a copy)
if (typeof input === 'string') opts.path = path.dirname(input)
Expand Down
Loading