Makes sure we use stream.ended in one place.

This commit is contained in:
damencho 2015-10-30 17:57:01 -05:00
parent 8cebbbb347
commit 74227e182a
1 changed files with 13 additions and 4 deletions

View File

@ -9,11 +9,12 @@ var RTCBrowserType = require("./RTCBrowserType");
* @param stream original WebRTC stream object to which 'onended' handling
* will be added.
*/
function implementOnEndedHandling(stream) {
function implementOnEndedHandling(localStream) {
var stream = localStream.getOriginalStream();
var originalStop = stream.stop;
stream.stop = function () {
originalStop.apply(stream);
if (!stream.ended) {
if (localStream.isActive()) {
stream.ended = true;
stream.onended();
}
@ -46,7 +47,7 @@ function LocalStream(stream, type, eventEmitter, videoType, isGUMStream) {
});
if (RTCBrowserType.isFirefox()) {
implementOnEndedHandling(this.stream);
implementOnEndedHandling(this);
}
}
@ -109,7 +110,7 @@ LocalStream.prototype.isMuted = function () {
if (this.isAudioStream()) {
tracks = this.stream.getAudioTracks();
} else {
if (this.stream.ended)
if (this.isActive())
return true;
tracks = this.stream.getVideoTracks();
}
@ -124,4 +125,12 @@ LocalStream.prototype.getId = function () {
return this.stream.getTracks()[0].id;
};
/**
* Checks whether the MediaStream is avtive/not ended.
* @returns {boolean} whether MediaStream is active.
*/
LocalStream.prototype.isActive = function () {
return !this.stream.ended;
};
module.exports = LocalStream;