From 8c6810a9e351f571337dd981ffc1d068c267ee5b Mon Sep 17 00:00:00 2001 From: Alexey Rodionov Date: Fri, 25 Mar 2016 10:52:21 +0300 Subject: [PATCH 01/10] Change magnetURI to torrentId Change magnetURI to torrentId to avoid confusing, because client.add is not limited only to magnet URIs and there are many ways to define torrentId, e.g. HTTP(S) URL to a *.torrent file. --- docs/api.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/api.md b/docs/api.md index 0956d897..e89e94c5 100644 --- a/docs/api.md +++ b/docs/api.md @@ -298,9 +298,9 @@ Here is a usage example: ```js var client = new WebTorrent() -var magnetURI = 'magnet: ...' +var torrentId = 'magnet: ...' -client.add(magnetURI, function (torrent) { +client.add(torrentId, function (torrent) { // create HTTP server for this torrent var server = torrent.createServer() server.listen(port) // start the server listening to a port From 59a2ecf4f59de92338da19dbb3f4e2d5599ea093 Mon Sep 17 00:00:00 2001 From: Alexey Rodionov Date: Fri, 25 Mar 2016 10:59:41 +0300 Subject: [PATCH 02/10] Use complete magnet URI Use complete magnet URI to keep example working, because trackerless magnet URIs are not supported in web browser environment (at least at this moment). --- docs/api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api.md b/docs/api.md index e89e94c5..38aa63d8 100644 --- a/docs/api.md +++ b/docs/api.md @@ -298,7 +298,7 @@ Here is a usage example: ```js var client = new WebTorrent() -var torrentId = 'magnet: ...' +var torrentId = 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d&dn=sintel.mp4&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&tr=wss%3A%2F%2Ftracker.webtorrent.io&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel-1024-surround.mp4' client.add(torrentId, function (torrent) { // create HTTP server for this torrent From 9c9bfc9119dd3071be1af3e879ab757292b0996b Mon Sep 17 00:00:00 2001 From: Alexey Rodionov Date: Fri, 25 Mar 2016 11:01:45 +0300 Subject: [PATCH 03/10] Add port variable Add missing port variable. --- docs/api.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/api.md b/docs/api.md index 38aa63d8..fd8053c2 100644 --- a/docs/api.md +++ b/docs/api.md @@ -299,6 +299,7 @@ Here is a usage example: ```js var client = new WebTorrent() var torrentId = 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d&dn=sintel.mp4&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&tr=wss%3A%2F%2Ftracker.webtorrent.io&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel-1024-surround.mp4' +var port = 5003 client.add(torrentId, function (torrent) { // create HTTP server for this torrent From 418b6670076c7ca8621d1e7613cccba3f9ae168d Mon Sep 17 00:00:00 2001 From: Alexey Rodionov Date: Fri, 25 Mar 2016 11:10:19 +0300 Subject: [PATCH 04/10] Change magnetURI to torrentId Change magnetURI to torrentId to avoid confusing, because client.add is not limited only to magnet URIs and there are many ways to define torrentId, e.g. HTTP(S) URL to a *.torrent file. --- docs/get-started.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/get-started.md b/docs/get-started.md index 83b069f3..f4f0c800 100644 --- a/docs/get-started.md +++ b/docs/get-started.md @@ -88,9 +88,9 @@ var fs = require('fs') var client = new WebTorrent() -var magnetURI = 'magnet:...' +var torrentId = 'magnet:...' -client.add(magnetURI, function (torrent) { +client.add(torrentId, function (torrent) { torrent.files.forEach(function (file) { console.log('Started saving ' + file.name) From 19cd49bb81e93c36428d5ae14afd22215b270356 Mon Sep 17 00:00:00 2001 From: Alexey Rodionov Date: Fri, 25 Mar 2016 11:12:17 +0300 Subject: [PATCH 05/10] Use real magnet URI Use real magnet URI to keep example working. --- docs/get-started.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/get-started.md b/docs/get-started.md index f4f0c800..209d4faf 100644 --- a/docs/get-started.md +++ b/docs/get-started.md @@ -88,7 +88,7 @@ var fs = require('fs') var client = new WebTorrent() -var torrentId = 'magnet:...' +var torrentId = 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d&dn=sintel.mp4&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&tr=wss%3A%2F%2Ftracker.webtorrent.io&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel-1024-surround.mp4' client.add(torrentId, function (torrent) { torrent.files.forEach(function (file) { From caf2ce42b52e19b477ba4dd842c9972aa6a9097c Mon Sep 17 00:00:00 2001 From: Alexey Rodionov Date: Fri, 25 Mar 2016 11:28:43 +0300 Subject: [PATCH 06/10] Remove concrete ways of install and use modules Remove concrete ways of install and use modules from examples for browser environment. --- docs/get-started.md | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/docs/get-started.md b/docs/get-started.md index 209d4faf..e5f2319d 100644 --- a/docs/get-started.md +++ b/docs/get-started.md @@ -36,8 +36,6 @@ var WebTorrent = require('webtorrent') ### Downloading a torrent (in the browser) ```js -var WebTorrent = require('webtorrent') - var client = new WebTorrent() // Sintel, a free, Creative Commons movie @@ -63,10 +61,25 @@ the needed torrent pieces from the network on-demand. ### Creating a new torrent and seed it (in the browser) +This example uses the [`drag-drop`][drag-drop] package, to make the HTML5 Drag and +Drop API easier to work with. + +It works in the browser with [browserify](http://browserify.org). + +``` +npm install drag-drop +``` + +Then use `drag-drop` like this: + ```js var dragDrop = require('drag-drop') -var WebTorrent = require('webtorrent') +``` + +**Note:** If you do not use browserify, use the included standalone file +`dragdrop.min.js`. This exports a `DragDrop` function on `window`. +```js var client = new WebTorrent() // When user drops files on the browser, create a new torrent and start seeding it! @@ -77,9 +90,6 @@ dragDrop('body', function (files) { }) ``` -This example uses the [`drag-drop`][drag-drop] package, to make the HTML5 Drag and -Drop API easier to work with. - ### Download and save a torrent (in Node.js) ```js From 5f90276e8c15589a5e3fa7ff87c6b111e1d394d5 Mon Sep 17 00:00:00 2001 From: Alexey Rodionov Date: Fri, 25 Mar 2016 11:35:03 +0300 Subject: [PATCH 07/10] Change magnetURI to torrentId Change magnetURI to torrentId to avoid confusing, because client.add is not limited only to magnet URIs and there are many ways to define torrentId, e.g. HTTP(S) URL to a *.torrent file. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8afe65b6..c7ea8d70 100644 --- a/README.md +++ b/README.md @@ -145,9 +145,9 @@ standards (no plugins, just HTML5 and WebRTC)! It's easy to get started! var WebTorrent = require('webtorrent') var client = new WebTorrent() -var magnetURI = '...' +var torrentId = '...' -client.add(magnetURI, function (torrent) { +client.add(torrentId, function (torrent) { // Got torrent metadata! console.log('Client is downloading:', torrent.infoHash) From 8a3cde64194f6ec37977ac015455dd6b389b249d Mon Sep 17 00:00:00 2001 From: Alexey Rodionov Date: Fri, 25 Mar 2016 11:36:26 +0300 Subject: [PATCH 08/10] Use real magnet URI Use real magnet URI to keep example working. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c7ea8d70..8d561917 100644 --- a/README.md +++ b/README.md @@ -145,7 +145,7 @@ standards (no plugins, just HTML5 and WebRTC)! It's easy to get started! var WebTorrent = require('webtorrent') var client = new WebTorrent() -var torrentId = '...' +var torrentId = 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d&dn=sintel.mp4&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&tr=wss%3A%2F%2Ftracker.webtorrent.io&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel-1024-surround.mp4' client.add(torrentId, function (torrent) { // Got torrent metadata! From 8ce5dd03d9b7bdb1c3f6198a38f1eca23eb57dd4 Mon Sep 17 00:00:00 2001 From: Alexey Rodionov Date: Fri, 25 Mar 2016 12:03:00 +0300 Subject: [PATCH 09/10] Remove concrete ways of install and use modules Remove concrete ways of install and use modules from examples for browser environment. --- README.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8d561917..925d599a 100644 --- a/README.md +++ b/README.md @@ -142,8 +142,6 @@ standards (no plugins, just HTML5 and WebRTC)! It's easy to get started! ##### Downloading a file is simple: ```js -var WebTorrent = require('webtorrent') - var client = new WebTorrent() var torrentId = 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d&dn=sintel.mp4&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&tr=wss%3A%2F%2Ftracker.webtorrent.io&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel-1024-surround.mp4' @@ -161,10 +159,15 @@ client.add(torrentId, function (torrent) { ##### Seeding a file is simple, too: -```js -var dragDrop = require('drag-drop') -var WebTorrent = require('webtorrent') +This example uses the [`drag-drop`][drag-drop] package, to make the HTML5 Drag and +Drop API easier to work with. +To start using `drag-drop`, simply include the +`dragdrop.min.js` script on your page. This exports a `dragDrop` function on `window`. +If you use [browserify](http://browserify.org), you can +`npm install drag-drop` and then use like this `var dragDrop = require('drag-drop')`. + +```js var client = new WebTorrent() // When user drops files on the browser, create a new torrent and start seeding it! From 155ca7bceb26b48997967dd232e1509e64003967 Mon Sep 17 00:00:00 2001 From: Alexey Rodionov Date: Fri, 25 Mar 2016 12:27:46 +0300 Subject: [PATCH 10/10] Fix broken link and add ways to specify a torrent Fix broken link and add all available ways to specify a torrent directly to the page. --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 925d599a..6e00dd51 100644 --- a/README.md +++ b/README.md @@ -269,7 +269,14 @@ There are many supported streaming options: --stdout standard out [implies --quiet] ``` -In addition to magnet uris, webtorrent supports [many ways to specify a torrent](#clientaddtorrentid-opts-function-ontorrent-torrent-). +In addition to magnet uris, webtorrent supports many ways to specify a torrent: + +- magnet uri (string) +- torrent file (buffer) +- info hash (hex string or buffer) +- parsed torrent (from [parse-torrent](https://github.com/feross/parse-torrent)) +- http/https url to a torrent file (string) +- filesystem path to a torrent file (string) ### Modules