Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ./examples/ directory #247

Merged
merged 1 commit into from Jan 17, 2015
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -173,6 +173,8 @@ client.add(magnet_uri, function (torrent) {
})
```

There are more examples in the [examples](https://github.com/feross/webtorrent/tree/master/examples) folder.

##### Browserify

WebTorrent works great with [browserify](http://browserify.org/), an npm module that let's
@@ -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)
})
})
})
@@ -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)
})
})
@@ -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)
})
@@ -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)
})
@@ -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)
})
})
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.