From 366b8912a24f5e448c5dcf67854604e988c3df96 Mon Sep 17 00:00:00 2001 From: Joseph Dykstra Date: Fri, 16 Jan 2015 10:22:21 -0600 Subject: [PATCH 1/2] Renamed instances of 'video' to 'media' --- lib/file-stream.js | 5 ++--- lib/{video-stream.js => media-stream.js} | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 14 deletions(-) rename lib/{video-stream.js => media-stream.js} (73%) diff --git a/lib/file-stream.js b/lib/file-stream.js index 2084ba16..3b2cf234 100644 --- a/lib/file-stream.js +++ b/lib/file-stream.js @@ -4,7 +4,7 @@ var debug = require('debug')('webtorrent:file-stream') var inherits = require('inherits') var path = require('path') var stream = require('stream') -var VideoStream = require('./video-stream') +var MediaStream = require('./media-stream') inherits(FileStream, stream.Readable) @@ -108,8 +108,7 @@ FileStream.prototype.pipe = function (dst) { : self._extname === '.mp3' ? 'audio/mpeg' : undefined - // TODO: consider renaming VideoStream to MediaStream, since it supports audio as well. - return pipe.call(self, new VideoStream(dst, { type: type })) + return pipe.call(self, new MediaStream(dst, { type: type })) } else return pipe.call(self, dst) } diff --git a/lib/video-stream.js b/lib/media-stream.js similarity index 73% rename from lib/video-stream.js rename to lib/media-stream.js index 821b044b..01f7d92a 100644 --- a/lib/video-stream.js +++ b/lib/media-stream.js @@ -1,6 +1,6 @@ -module.exports = VideoStream +module.exports = MediaStream -var debug = require('debug')('webtorrent:video-stream') +var debug = require('debug')('webtorrent:media-stream') var inherits = require('inherits') var once = require('once') var stream = require('stream') @@ -8,25 +8,25 @@ var stream = require('stream') var MediaSource = typeof window !== 'undefined' && (window.MediaSource || window.WebKitMediaSource) -inherits(VideoStream, stream.Writable) +inherits(MediaStream, stream.Writable) -function VideoStream (video, opts) { +function MediaStream (media, opts) { var self = this - if (!(self instanceof VideoStream)) return new VideoStream(video, opts) + if (!(self instanceof MediaStream)) return new MediaStream(media, opts) stream.Writable.call(self, opts) - self.video = video + self.media = media opts = opts || {} opts.type = opts.type || 'video/webm; codecs="vorbis,vp8"' - debug('new videostream %s %s', video, JSON.stringify(opts)) + debug('new mediastream %s %s', media, JSON.stringify(opts)) self._mediaSource = new MediaSource() self._playing = false self._sourceBuffer = null self._cb = null - self.video.src = window.URL.createObjectURL(self._mediaSource) + self.media.src = window.URL.createObjectURL(self._mediaSource) var sourceopen = once(function () { self._sourceBuffer = self._mediaSource.addSourceBuffer(opts.type) @@ -43,7 +43,7 @@ function VideoStream (video, opts) { window.vs = self } -VideoStream.prototype._write = function (chunk, encoding, cb) { +MediaStream.prototype._write = function (chunk, encoding, cb) { var self = this if (!self._sourceBuffer) { self._cb = function (err) { @@ -60,12 +60,12 @@ VideoStream.prototype._write = function (chunk, encoding, cb) { debug('appendBuffer %s', chunk.length) self._cb = cb if (!self._playing) { - self.video.play() + self.media.play() self._playing = true } } -VideoStream.prototype._flow = function () { +MediaStream.prototype._flow = function () { var self = this debug('flow') if (self._cb) { From 81427cd808d3fdc9af0e8161c7df3f40ba57e837 Mon Sep 17 00:00:00 2001 From: Joseph Dykstra Date: Fri, 16 Jan 2015 10:30:16 -0600 Subject: [PATCH 2/2] Use a map instead of multiple ternary statements --- lib/file-stream.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/file-stream.js b/lib/file-stream.js index 3b2cf234..2abfd615 100644 --- a/lib/file-stream.js +++ b/lib/file-stream.js @@ -101,13 +101,11 @@ FileStream.prototype.pipe = function (dst) { //