From 63ddf6c7ff1a7b68c4dfd1258df7f0942b892fb3 Mon Sep 17 00:00:00 2001 From: damencho Date: Wed, 18 Nov 2015 16:59:24 -0600 Subject: [PATCH] Uses one method from RTC to stop media streams. --- modules/RTC/JitsiLocalTrack.js | 4 +- modules/RTC/RTC.js | 60 ++++--------------------- modules/RTC/RTCUtils.js | 19 ++++++++ modules/xmpp/TraceablePeerConnection.js | 16 +------ 4 files changed, 31 insertions(+), 68 deletions(-) diff --git a/modules/RTC/JitsiLocalTrack.js b/modules/RTC/JitsiLocalTrack.js index 2249049f5..c3c918516 100644 --- a/modules/RTC/JitsiLocalTrack.js +++ b/modules/RTC/JitsiLocalTrack.js @@ -55,7 +55,7 @@ JitsiLocalTrack.prototype._setMute = function (mute) { if (mute) { this.dontFireRemoveEvent = true; this.rtc.room.removeStream(this.stream); - this.stream.stop(); + this.rtc.stopMediaStream(this.stream); if(isAudio) this.rtc.room.setAudioMute(mute); else @@ -111,7 +111,7 @@ JitsiLocalTrack.prototype.stop = function () { return; if(this.rtc) this.rtc.room.removeStream(this.stream); - this.stream.stop(); + this.rtc.stopMediaStream(this.stream); this.detach(); } diff --git a/modules/RTC/RTC.js b/modules/RTC/RTC.js index 7ace1cc86..29cb02c1a 100644 --- a/modules/RTC/RTC.js +++ b/modules/RTC/RTC.js @@ -174,6 +174,15 @@ RTC.setVideoSrc = function (element, src) { RTCUtils.setVideoSrc(element, src); }; +/** + * A method to handle stopping of the stream. + * One point to handle the differences in various implementations. + * @param mediaStream MediaStream object to stop. + */ +RTC.stopMediaStream = function (mediaStream) { + RTCUtils.stopMediaStream(mediaStream); +}; + RTC.prototype.getVideoElementName = function () { return RTCBrowserType.isTemasysPluginUsed() ? 'object' : 'video'; }; @@ -210,57 +219,6 @@ RTC.prototype.switchVideoStreams = function (new_stream) { this.localStreams.push(this.localVideo); }; -/** - * Creates JitsiTrack instance and replaces it with the local video. - * The method also handles the sdp changes. - * @param stream the new MediaStream received by the browser. - * @param isUsingScreenStream true if the stream is for desktop stream. - * @param callback - function that will be called after the operation is completed. - */ -RTC.prototype.changeLocalVideo = function (stream, isUsingScreenStream, callback) { - var oldStream = this.localVideo.getOriginalStream(); - var type = (isUsingScreenStream ? "screen" : "camera"); - var localCallback = callback; - - if(this.localVideo.isMuted() && this.localVideo.videoType !== type) { - localCallback = function() { - this.room.setVideoMute(false, function(mute) { - this.eventEmitter.emit(RTCEvents.VIDEO_MUTE, mute); - }.bind(this)); - - callback(); - }; - } - // FIXME: Workaround for FF/IE/Safari - if (stream && stream.videoStream) { - stream = stream.videoStream; - } - var videoStream = RTCUtils.createStream(stream, true); - this.localVideo = this.createLocalStream(videoStream, "video", true, type); - // Stop the stream to trigger onended event for old stream - oldStream.stop(); - - this.switchVideoStreams(videoStream, oldStream); - - this.room.switchStreams(videoStream, oldStream,localCallback); -}; - - -/** - * Creates JitsiTrack instance and replaces it with the local audio. - * The method also handles the sdp changes. - * @param stream the new MediaStream received by the browser. - * @param callback - function that will be called after the operation is completed. - */ -RTC.prototype.changeLocalAudio = function (stream, callback) { - var oldStream = this.localAudio.getOriginalStream(); - var newStream = RTCUtils.createStream(stream); - this.localAudio = this.createLocalStream(newStream, "audio", true); - // Stop the stream to trigger onended event for old stream - oldStream.stop(); - this.room.switchStreams(newStream, oldStream, callback, true); -}; - RTC.prototype.isVideoMuted = function (jid) { if (jid === APP.xmpp.myJid()) { var localVideo = APP.RTC.localVideo; diff --git a/modules/RTC/RTCUtils.js b/modules/RTC/RTCUtils.js index 1a08bcfe0..34a3a44b6 100644 --- a/modules/RTC/RTCUtils.js +++ b/modules/RTC/RTCUtils.js @@ -810,7 +810,26 @@ var RTCUtils = { return true; } return (MediaStreamTrack && MediaStreamTrack.getSources)? true : false; + }, + /** + * A method to handle stopping of the stream. + * One point to handle the differences in various implementations. + * @param mediaStream MediaStream object to stop. + */ + stopMediaStream: function (mediaStream) { + mediaStream.getTracks().forEach(function (track) { + // stop() not supported with IE + if (track.stop) { + track.stop(); + } + }); + + // leave stop for implementation still using it + if (mediaStream.stop) { + mediaStream.stop(); + } } + }; module.exports = RTCUtils; diff --git a/modules/xmpp/TraceablePeerConnection.js b/modules/xmpp/TraceablePeerConnection.js index 7596a81e3..9822723c6 100644 --- a/modules/xmpp/TraceablePeerConnection.js +++ b/modules/xmpp/TraceablePeerConnection.js @@ -257,21 +257,7 @@ TraceablePeerConnection.prototype.addStream = function (stream) { TraceablePeerConnection.prototype.removeStream = function (stream, stopStreams) { this.trace('removeStream', stream.id); if(stopStreams) { - stream.getAudioTracks().forEach(function (track) { - // stop() not supported with IE - if (track.stop) { - track.stop(); - } - }); - stream.getVideoTracks().forEach(function (track) { - // stop() not supported with IE - if (track.stop) { - track.stop(); - } - }); - if (stream.stop) { - stream.stop(); - } + RTC.stopMediaStream(stream); } try {