From dc2601ed144b5348e6afa30496d380514836f5d2 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sun, 27 Dec 2015 19:38:05 +0100 Subject: 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 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') - }) -}) -- cgit v1.2.3