diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2015-01-27 05:04:18 +0300 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2015-01-27 05:04:18 +0300 |
commit | bb07d4db0e213611899d834b022e00936172557e (patch) | |
tree | 898c2ab31961ddfa2bc0c950e5bd44b4e1522529 /examples | |
parent | a3fdd9aafeb70f1fea545879131523b2906c3979 (diff) |
JavaScript Standard Style
Diffstat (limited to 'examples')
-rw-r--r-- | examples/browser-download.js | 45 | ||||
-rw-r--r-- | examples/browser-seed.js | 24 | ||||
-rw-r--r-- | examples/browser-stream-to-audio.js | 39 | ||||
-rw-r--r-- | examples/browser-stream-to-video.js | 39 | ||||
-rw-r--r-- | examples/node-save-to-file-system.js | 33 |
5 files changed, 92 insertions, 88 deletions
diff --git a/examples/browser-download.js b/examples/browser-download.js index 3428f72..a60e3bd 100644 --- a/examples/browser-download.js +++ b/examples/browser-download.js @@ -1,22 +1,23 @@ -var WebTorrent = require('webtorrent')
-
-var client = new WebTorrent()
-
-client.add(magnet_uri, function (torrent) {
- // Got torrent metadata!
- console.log('Torrent info hash:', torrent.infoHash)
-
- 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)
- })
- })
-})
+var WebTorrent = require('webtorrent') + +var client = new WebTorrent() +var magnetUri = 'magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36' + +client.add(magnetUri, function (torrent) { + // Got torrent metadata! + console.log('Torrent info hash:', torrent.infoHash) + + 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) + }) + }) +}) diff --git a/examples/browser-seed.js b/examples/browser-seed.js index 6a6d498..cad1061 100644 --- a/examples/browser-seed.js +++ b/examples/browser-seed.js @@ -1,12 +1,12 @@ -var dragDrop = require('drag-drop/buffer')
-var WebTorrent = require('webtorrent')
-
-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 is seeding the file!
- console.log('Torrent info hash:', torrent.infoHash)
- })
-})
+var dragDrop = require('drag-drop/buffer') +var WebTorrent = require('webtorrent') + +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 is seeding the file! + console.log('Torrent info hash:', torrent.infoHash) + }) +}) diff --git a/examples/browser-stream-to-audio.js b/examples/browser-stream-to-audio.js index 84dfdfd..01c6499 100644 --- a/examples/browser-stream-to-audio.js +++ b/examples/browser-stream-to-audio.js @@ -1,19 +1,20 @@ -var WebTorrent = require('webtorrent')
-
-var client = new WebTorrent()
-
-client.add(magnet_uri, function (torrent) {
- // Got torrent metadata!
- console.log('Torrent info hash:', torrent.infoHash)
-
- // Let's say the first file is an mp3 audio file
- var file = torrent.files[0]
-
- // Create an audio element
- var audio = document.createElement('audio')
- audio.controls = true
- document.body.appendChild(audio)
-
- // Stream the audio into the audio tag
- file.createReadStream().pipe(audio)
-})
+var WebTorrent = require('webtorrent') + +var client = new WebTorrent() +var magnetUri = 'magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36' + +client.add(magnetUri, function (torrent) { + // Got torrent metadata! + console.log('Torrent info hash:', torrent.infoHash) + + // Let's say the first file is an mp3 audio file + var file = torrent.files[0] + + // Create an audio element + var audio = document.createElement('audio') + audio.controls = true + document.body.appendChild(audio) + + // Stream the audio into the audio tag + file.createReadStream().pipe(audio) +}) diff --git a/examples/browser-stream-to-video.js b/examples/browser-stream-to-video.js index 7943a64..e721cee 100644 --- a/examples/browser-stream-to-video.js +++ b/examples/browser-stream-to-video.js @@ -1,19 +1,20 @@ -var WebTorrent = require('webtorrent')
-
-var client = new WebTorrent()
-
-client.add(magnet_uri, function (torrent) {
- // Got torrent metadata!
- console.log('Torrent info hash:', torrent.infoHash)
-
- // Let's say the first file is a webm (vp8) or mp4 (h264) video...
- var file = torrent.files[0]
-
- // Create a video element
- var video = document.createElement('video')
- video.controls = true
- document.body.appendChild(video)
-
- // Stream the video into the video tag
- file.createReadStream().pipe(video)
-})
+var WebTorrent = require('webtorrent') + +var client = new WebTorrent() +var magnetUri = 'magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36' + +client.add(magnetUri, function (torrent) { + // Got torrent metadata! + console.log('Torrent info hash:', torrent.infoHash) + + // Let's say the first file is a webm (vp8) or mp4 (h264) video... + var file = torrent.files[0] + + // Create a video element + var video = document.createElement('video') + video.controls = true + document.body.appendChild(video) + + // Stream the video into the video tag + file.createReadStream().pipe(video) +}) diff --git a/examples/node-save-to-file-system.js b/examples/node-save-to-file-system.js index 5b33d0c..1d5e7e6 100644 --- a/examples/node-save-to-file-system.js +++ b/examples/node-save-to-file-system.js @@ -1,16 +1,17 @@ -var WebTorrent = require('webtorrent')
-var fs = require('fs')
-
-var client = new WebTorrent()
-
-client.download(magnet_uri, function (torrent) {
- // Got torrent metadata!
- console.log('Torrent info hash:', torrent.infoHash)
-
- torrent.files.forEach(function (file) {
- // Stream each file to the disk
- var source = file.createReadStream()
- var destination = fs.createWriteStream(file.name)
- source.pipe(destination)
- })
-})
+var WebTorrent = require('webtorrent') +var fs = require('fs') + +var client = new WebTorrent() +var magnetUri = 'magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36' + +client.download(magnetUri, function (torrent) { + // Got torrent metadata! + console.log('Torrent info hash:', torrent.infoHash) + + torrent.files.forEach(function (file) { + // Stream each file to the disk + var source = file.createReadStream() + var destination = fs.createWriteStream(file.name) + source.pipe(destination) + }) +}) |