Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'examples/browser-download.js')
-rw-r--r--examples/browser-download.js21
1 files changed, 5 insertions, 16 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')
})