Makes sure we use stream.ended in one place. Replaces deprecated ended call with active check for media streams.

This commit is contained in:
damencho 2015-11-19 16:16:57 -06:00
parent 02c7844307
commit 6f3001d6aa
2 changed files with 21 additions and 7 deletions

View File

@ -130,7 +130,7 @@ JitsiLocalTrack.prototype.isMuted = function () {
if (isAudio) {
tracks = this.stream.getAudioTracks();
} else {
if (this.stream.ended)
if (!this.isActive())
return true;
tracks = this.stream.getVideoTracks();
}

View File

@ -3,15 +3,15 @@ var RTCBrowserType = require("./RTCBrowserType");
/**
* This implements 'onended' callback normally fired by WebRTC after the stream
* is stopped. There is no such behaviour yet in FF, so we have to add it.
* @param stream original WebRTC stream object to which 'onended' handling
* will be added.
* @param jitsiTrack our track object holding the original WebRTC stream object
* to which 'onended' handling will be added.
*/
function implementOnEndedHandling(stream) {
function implementOnEndedHandling(jitsiTrack) {
var stream = jitsiTrack.getOriginalStream();
var originalStop = stream.stop;
stream.stop = function () {
originalStop.apply(stream);
if (!stream.ended) {
stream.ended = true;
if (jitsiTrack.isActive()) {
stream.onended();
}
};
@ -66,7 +66,7 @@ function JitsiTrack(rtc, stream, streamInactiveHandler)
}.bind(this);
}
if (RTCBrowserType.isFirefox() && this.stream) {
implementOnEndedHandling(this.stream);
implementOnEndedHandling(this);
}
if(stream)
@ -171,4 +171,18 @@ JitsiTrack.prototype.getId = function () {
return tracks[0].id;
};
/**
* Checks whether the MediaStream is avtive/not ended.
* When there is no check for active we don't have information and so
* will return that stream is active (in case of FF).
* @returns {boolean} whether MediaStream is active.
*/
JitsiTrack.prototype.isActive = function () {
if((typeof this.stream.active !== "undefined"))
return this.stream.active;
else
return true;
};
module.exports = JitsiTrack;