From 74227e182abbe3a95b10bb817e7a9a00bb4eb5a8 Mon Sep 17 00:00:00 2001 From: damencho Date: Fri, 30 Oct 2015 17:57:01 -0500 Subject: [PATCH] Makes sure we use stream.ended in one place. --- modules/RTC/LocalStream.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/RTC/LocalStream.js b/modules/RTC/LocalStream.js index 4f13cce3c..a20a219d0 100644 --- a/modules/RTC/LocalStream.js +++ b/modules/RTC/LocalStream.js @@ -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;