From 8cff356ce0f6852a80e3b07217ecaa5b1d3e3098 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sun, 27 Dec 2015 19:37:52 +0100 Subject: [PATCH 1/4] examples: Use sintel torrent --- README.md | 2 +- examples/browser-download.js | 3 +-- examples/node-save-to-file-system.js | 4 ++-- test/cmd.js | 4 ++-- test/rarity-map.js | 2 +- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 9b75aa14..55cb551e 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,7 @@ 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.seed(files, function (torrent) { console.log('Client is seeding:', torrent.infoHash) }) }) diff --git a/examples/browser-download.js b/examples/browser-download.js index 18e1bbe6..42c8789a 100644 --- a/examples/browser-download.js +++ b/examples/browser-download.js @@ -2,8 +2,7 @@ var WebTorrent = require('webtorrent') var client = new WebTorrent() -// Go to https://instant.io, seed a file and use the magnet uri generated -var magnetUri = 'magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36' +var torrentId = 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d' client.add(magnetUri, function (torrent) { // Got torrent metadata! diff --git a/examples/node-save-to-file-system.js b/examples/node-save-to-file-system.js index 1d5e7e6a..a2b1974b 100644 --- a/examples/node-save-to-file-system.js +++ b/examples/node-save-to-file-system.js @@ -2,11 +2,11 @@ var WebTorrent = require('webtorrent') var fs = require('fs') var client = new WebTorrent() -var magnetUri = 'magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36' +var magnetUri = 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d' client.download(magnetUri, function (torrent) { // Got torrent metadata! - console.log('Torrent info hash:', torrent.infoHash) + console.log('Torrent magnet link:', torrent.magnetURI) torrent.files.forEach(function (file) { // Stream each file to the disk diff --git a/test/cmd.js b/test/cmd.js index 461b54df..59f0f56f 100644 --- a/test/cmd.js +++ b/test/cmd.js @@ -70,7 +70,7 @@ test('Command line: webtorrent info /path/to/file.torrent', function (t) { test('Command line: webtorrent info magnet_uri', function (t) { t.plan(2) - var leavesMagnetURI = 'magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36&dn=Leaves+of+Grass+by+Walt+Whitman.epub&tr=http%3A%2F%2Ftracker.bittorrent.am%2Fannounce&tr=http%3A%2F%2Ftracker.thepiratebay.org%2Fannounce&tr=udp%3A%2F%2Ffr33domtracker.h33t.com%3A3310%2Fannounce&tr=udp%3A%2F%2Ftracker.ccc.de%3A80&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80' + var leavesMagnetURI = 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d&dn=Leaves+of+Grass+by+Walt+Whitman.epub&tr=http%3A%2F%2Ftracker.bittorrent.am%2Fannounce&tr=http%3A%2F%2Ftracker.thepiratebay.org%2Fannounce&tr=udp%3A%2F%2Ffr33domtracker.h33t.com%3A3310%2Fannounce&tr=udp%3A%2F%2Ftracker.ccc.de%3A80&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80' cp.exec(CMD + ' info "' + leavesMagnetURI + '"', function (err, data) { t.error(err) @@ -95,7 +95,7 @@ test('Command line: webtorrent create /path/to/file', function (t) { child.stdout.on('end', function () { var buf = Buffer.concat(chunks) var parsedTorrent = parseTorrent(new Buffer(buf, 'binary')) - t.deepEqual(parsedTorrent.infoHash, 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36') + t.deepEqual(parsedTorrent.infoHash, '6a9759bffd5c0af65319979fb7832189f4f3c35d') }) }) diff --git a/test/rarity-map.js b/test/rarity-map.js index f9061200..07ec9a9f 100644 --- a/test/rarity-map.js +++ b/test/rarity-map.js @@ -5,7 +5,7 @@ var RarityMap = require('../lib/rarity-map') var Swarm = require('bittorrent-swarm') var test = require('tape') -var infoHash = 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36' +var infoHash = '6a9759bffd5c0af65319979fb7832189f4f3c35d' var peerId1 = '-WW0001-' + hat(48) test('Rarity map usage', function (t) { From dc2601ed144b5348e6afa30496d380514836f5d2 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sun, 27 Dec 2015 19:38:05 +0100 Subject: [PATCH 2/4] examples: simplify --- examples/browser-download.js | 21 +++++--------------- examples/browser-seed.js | 4 ++-- examples/browser-stream-to-video-or-audio.js | 15 -------------- 3 files changed, 7 insertions(+), 33 deletions(-) delete mode 100644 examples/browser-stream-to-video-or-audio.js diff --git a/examples/browser-download.js b/examples/browser-download.js index 42c8789a..de0cd568 100644 --- a/examples/browser-download.js +++ b/examples/browser-download.js @@ -4,21 +4,10 @@ var client = new WebTorrent() var torrentId = 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d' -client.add(magnetUri, function (torrent) { - // Got torrent metadata! - console.log('Torrent info hash:', torrent.infoHash) +client.add(torrentId, function (torrent) { + // Torrents can contain many files. Let's use the first. + var file = torrent.files[0] - torrent.files.forEach(function (file) { - // Get a url for each file - file.getBlobURL(function (err, url) { - if (err) throw err - - // Add a link to the page - var a = document.createElement('a') - a.download = file.name - a.href = url - a.textContent = 'Download ' + file.name - document.body.appendChild(a) - }) - }) + // Display the file by adding it to the DOM. Supports video, audio, image, etc. files + file.appendTo('body') }) diff --git a/examples/browser-seed.js b/examples/browser-seed.js index ea2fbbe7..7f8594c5 100644 --- a/examples/browser-seed.js +++ b/examples/browser-seed.js @@ -5,8 +5,8 @@ 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.seed(files, function (torrent) { // Client is seeding the file! - console.log('Torrent info hash:', torrent.infoHash) + console.log('Torrent magnet link:', torrent.magnetURI) }) }) diff --git a/examples/browser-stream-to-video-or-audio.js b/examples/browser-stream-to-video-or-audio.js deleted file mode 100644 index a1c63f2f..00000000 --- a/examples/browser-stream-to-video-or-audio.js +++ /dev/null @@ -1,15 +0,0 @@ -var WebTorrent = require('webtorrent') - -var client = new WebTorrent() -var magnetUri = '...' - -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') - }) -}) From ce62427395554f2f87202473007b86d93059f7a1 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sun, 27 Dec 2015 19:38:26 +0100 Subject: [PATCH 3/4] examples: add complete html example (fix #487) --- examples/file-send.html | 74 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 examples/file-send.html diff --git a/examples/file-send.html b/examples/file-send.html new file mode 100644 index 00000000..0091ab94 --- /dev/null +++ b/examples/file-send.html @@ -0,0 +1,74 @@ + + + + WebTorrent – Simple File Sending Example + + + +

Streaming File Transfer over WebTorrent

+ +

Download files using the WebTorrent protocol (BitTorrent over WebRTC).

+ +

Log

+
+ +

Start downloading

+ +
+ + + +
+ +
+

Code is available on GitHub under MIT License. Run localStorage.debug = '*' in the console and refresh to enable verbose logs.

+ + + + + + + From 081385d06aab74364b7aed53bbd6dbed134cfbd9 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sun, 27 Dec 2015 19:57:20 +0100 Subject: [PATCH 4/4] undo accidental test changes --- test/cmd.js | 4 ++-- test/rarity-map.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/cmd.js b/test/cmd.js index 59f0f56f..461b54df 100644 --- a/test/cmd.js +++ b/test/cmd.js @@ -70,7 +70,7 @@ test('Command line: webtorrent info /path/to/file.torrent', function (t) { test('Command line: webtorrent info magnet_uri', function (t) { t.plan(2) - var leavesMagnetURI = 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d&dn=Leaves+of+Grass+by+Walt+Whitman.epub&tr=http%3A%2F%2Ftracker.bittorrent.am%2Fannounce&tr=http%3A%2F%2Ftracker.thepiratebay.org%2Fannounce&tr=udp%3A%2F%2Ffr33domtracker.h33t.com%3A3310%2Fannounce&tr=udp%3A%2F%2Ftracker.ccc.de%3A80&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80' + var leavesMagnetURI = 'magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36&dn=Leaves+of+Grass+by+Walt+Whitman.epub&tr=http%3A%2F%2Ftracker.bittorrent.am%2Fannounce&tr=http%3A%2F%2Ftracker.thepiratebay.org%2Fannounce&tr=udp%3A%2F%2Ffr33domtracker.h33t.com%3A3310%2Fannounce&tr=udp%3A%2F%2Ftracker.ccc.de%3A80&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80' cp.exec(CMD + ' info "' + leavesMagnetURI + '"', function (err, data) { t.error(err) @@ -95,7 +95,7 @@ test('Command line: webtorrent create /path/to/file', function (t) { child.stdout.on('end', function () { var buf = Buffer.concat(chunks) var parsedTorrent = parseTorrent(new Buffer(buf, 'binary')) - t.deepEqual(parsedTorrent.infoHash, '6a9759bffd5c0af65319979fb7832189f4f3c35d') + t.deepEqual(parsedTorrent.infoHash, 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36') }) }) diff --git a/test/rarity-map.js b/test/rarity-map.js index 07ec9a9f..f9061200 100644 --- a/test/rarity-map.js +++ b/test/rarity-map.js @@ -5,7 +5,7 @@ var RarityMap = require('../lib/rarity-map') var Swarm = require('bittorrent-swarm') var test = require('tape') -var infoHash = '6a9759bffd5c0af65319979fb7832189f4f3c35d' +var infoHash = 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36' var peerId1 = '-WW0001-' + hat(48) test('Rarity map usage', function (t) {