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..de0cd568 100644 --- a/examples/browser-download.js +++ b/examples/browser-download.js @@ -2,24 +2,12 @@ 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! - 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') - }) -}) 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 @@ + + +
+Download files using the WebTorrent protocol (BitTorrent over WebRTC).
+ +Code is available on GitHub under MIT License. Run localStorage.debug = '*' in the console and refresh to enable verbose logs.