diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2015-12-27 21:38:05 +0300 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2015-12-27 21:38:05 +0300 |
commit | dc2601ed144b5348e6afa30496d380514836f5d2 (patch) | |
tree | 74c1d2be5ce1423334a0a4377f1e987d9eb0500b | |
parent | 8cff356ce0f6852a80e3b07217ecaa5b1d3e3098 (diff) |
examples: simplify
-rw-r--r-- | examples/browser-download.js | 21 | ||||
-rw-r--r-- | examples/browser-seed.js | 4 | ||||
-rw-r--r-- | examples/browser-stream-to-video-or-audio.js | 15 |
3 files changed, 7 insertions, 33 deletions
diff --git a/examples/browser-download.js b/examples/browser-download.js index 42c8789..de0cd56 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 ea2fbbe..7f8594c 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 a1c63f2..0000000 --- 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') - }) -}) |