diff options
author | Josh Duff <me@JoshDuff.com> | 2014-12-14 06:51:35 +0300 |
---|---|---|
committer | Josh Duff <me@JoshDuff.com> | 2014-12-14 06:51:35 +0300 |
commit | 04ec598159909e9bce1e08fc9c99b3cadb889d00 (patch) | |
tree | dc0dbef8b56b13460bc5c4794a1345a12fae6e0c /README.md | |
parent | e01cb256922bdfb95162662e48f2d2c1506eaea1 (diff) |
Streaming video example
Copied straight from #144
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -135,6 +135,30 @@ dragDrop('body', function (files) { }) ``` +##### Streaming to an HTML5 video element? Also simple! + +```js +var WebTorrent = require('webtorrent') + +var client = new WebTorrent() + +client.download(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) +}) +``` + ##### Browserify WebTorrent works great with [browserify](http://browserify.org/), an npm module that let's |