From 6f3001d6aaa72e001ecc6b732f99700cd0735833 Mon Sep 17 00:00:00 2001 From: damencho Date: Thu, 19 Nov 2015 16:16:57 -0600 Subject: [PATCH] Makes sure we use stream.ended in one place. Replaces deprecated ended call with active check for media streams. --- modules/RTC/JitsiLocalTrack.js | 2 +- modules/RTC/JitsiTrack.js | 26 ++++++++++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/modules/RTC/JitsiLocalTrack.js b/modules/RTC/JitsiLocalTrack.js index bb9b15ec0..b79bc9570 100644 --- a/modules/RTC/JitsiLocalTrack.js +++ b/modules/RTC/JitsiLocalTrack.js @@ -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(); } diff --git a/modules/RTC/JitsiTrack.js b/modules/RTC/JitsiTrack.js index c7a01e061..67b8ad712 100644 --- a/modules/RTC/JitsiTrack.js +++ b/modules/RTC/JitsiTrack.js @@ -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;