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:
authorJoseph Dykstra <josephdykstra@gmail.com>2015-01-17 01:45:13 +0300
committerJoseph Dykstra <josephdykstra@gmail.com>2015-01-17 01:45:13 +0300
commit777d6c2225a5fae5f514a141ea3ec25d97763754 (patch)
tree88a5d6d433e7ce9c9a0f0c995fbdafbdbf59378e /examples
parentd880b81ff83a860594a5310dd0a05fdb1ca7f876 (diff)
Added ./examples/ directory
Diffstat (limited to 'examples')
-rw-r--r--examples/browser-download.js22
-rw-r--r--examples/browser-seed.js12
-rw-r--r--examples/browser-stream-to-audio.js19
-rw-r--r--examples/browser-stream-to-video.js19
-rw-r--r--examples/node-save-to-file-system.js16
5 files changed, 88 insertions, 0 deletions
diff --git a/examples/browser-download.js b/examples/browser-download.js
new file mode 100644
index 0000000..3428f72
--- /dev/null
+++ b/examples/browser-download.js
@@ -0,0 +1,22 @@
+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)
+ })
+ })
+})
diff --git a/examples/browser-seed.js b/examples/browser-seed.js
new file mode 100644
index 0000000..6a6d498
--- /dev/null
+++ b/examples/browser-seed.js
@@ -0,0 +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)
+ })
+})
diff --git a/examples/browser-stream-to-audio.js b/examples/browser-stream-to-audio.js
new file mode 100644
index 0000000..84dfdfd
--- /dev/null
+++ b/examples/browser-stream-to-audio.js
@@ -0,0 +1,19 @@
+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)
+})
diff --git a/examples/browser-stream-to-video.js b/examples/browser-stream-to-video.js
new file mode 100644
index 0000000..7943a64
--- /dev/null
+++ b/examples/browser-stream-to-video.js
@@ -0,0 +1,19 @@
+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)
+})
diff --git a/examples/node-save-to-file-system.js b/examples/node-save-to-file-system.js
new file mode 100644
index 0000000..5b33d0c
--- /dev/null
+++ b/examples/node-save-to-file-system.js
@@ -0,0 +1,16 @@
+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)
+ })
+})