diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2014-10-20 07:28:11 +0400 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2014-10-20 07:28:11 +0400 |
commit | a0d3ba2d0cf707730a3e1530c17a045b937ebda6 (patch) | |
tree | 4496a82c538e00159a233a74f1832fcf8831d42c /lib/file-stream.js | |
parent | 6f77c2737543878f3efc99b2470f48cf03f27ee0 (diff) |
support streaming into video tag
close #144
Diffstat (limited to 'lib/file-stream.js')
-rw-r--r-- | lib/file-stream.js | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/file-stream.js b/lib/file-stream.js index 6d86ea8..cbf1319 100644 --- a/lib/file-stream.js +++ b/lib/file-stream.js @@ -2,7 +2,9 @@ module.exports = FileStream var debug = require('debug')('webtorrent:file-stream') var inherits = require('inherits') +var path = require('path') var stream = require('stream') +var VideoStream = require('./video-stream') inherits(FileStream, stream.Readable) @@ -32,6 +34,7 @@ function FileStream (file, opts) { self.startPiece = offset / pieceLength | 0 self.endPiece = (opts.end + file.offset) / pieceLength | 0 + self._extname = path.extname(file.name) self._storage = file.storage self._piece = self.startPiece self._missing = self.length @@ -92,6 +95,21 @@ FileStream.prototype.notify = function () { }) } +FileStream.prototype.pipe = function (dst) { + var self = this + var pipe = stream.Readable.prototype.pipe + + if (dst && dst.nodeName === 'VIDEO') { // <video> tag + var type = self._extname === '.webm' + ? 'video/webm; codecs="vorbis,vp8"' + : self._extname === '.mp4' + ? 'video/mp4; codecs="avc1.42c01e,mp4a.40.2"' + : undefined + return pipe.call(self, new VideoStream(dst, { type: type })) + } else + return pipe.call(self, dst) +} + FileStream.prototype.destroy = function () { var self = this if (self._destroyed) return |