From c288aa6e84ff680f6fa86c2970600bb52386015b Mon Sep 17 00:00:00 2001 From: paweldomas Date: Thu, 6 Aug 2015 11:53:10 +0200 Subject: [PATCH] Fixes issue with toggling video mute in FF caused by the fact that it has no 'onended' callback handling implemented. --- modules/RTC/LocalStream.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/modules/RTC/LocalStream.js b/modules/RTC/LocalStream.js index 0722ceb87..468cc96f4 100644 --- a/modules/RTC/LocalStream.js +++ b/modules/RTC/LocalStream.js @@ -1,6 +1,24 @@ /* global APP */ var StreamEventTypes = require("../../service/RTC/StreamEventTypes.js"); var RTCEvents = require("../../service/RTC/RTCEvents"); +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. + */ +function implementOnEndedHandling(stream) { + var originalStop = stream.stop; + stream.stop = function () { + originalStop.apply(stream); + if (!stream.ended) { + stream.ended = true; + stream.onended(); + } + }; +} function LocalStream(stream, type, eventEmitter, videoType, isGUMStream) { this.stream = stream; @@ -21,9 +39,12 @@ function LocalStream(stream, type, eventEmitter, videoType, isGUMStream) { }; } - this.stream.onended = function() { + this.stream.onended = function () { self.streamEnded(); }; + if (RTCBrowserType.isFirefox()) { + implementOnEndedHandling(this.stream); + } } LocalStream.prototype.streamEnded = function () {