From 11e1197901c8f63382e5631aae4ef2322ee46021 Mon Sep 17 00:00:00 2001 From: damencho Date: Fri, 30 Oct 2015 14:25:06 -0500 Subject: [PATCH] Uses one method from RTC to stop media streams. --- modules/RTC/RTC.js | 31 +++++++++++++++++++++---- modules/xmpp/TraceablePeerConnection.js | 16 +------------ 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/modules/RTC/RTC.js b/modules/RTC/RTC.js index 3edf99506..b788fb0c9 100644 --- a/modules/RTC/RTC.js +++ b/modules/RTC/RTC.js @@ -210,8 +210,8 @@ var RTC = { var videoStream = this.rtcUtils.createStream(stream, true); this.localVideo = this.createLocalStream(videoStream, "video", true, type); - // Stop the stream to trigger onended event for old stream - oldStream.stop(); + // Stop the stream + this.stopMediaStream(oldStream); APP.xmpp.switchStreams(videoStream, oldStream,localCallback); }, @@ -219,8 +219,8 @@ var RTC = { var oldStream = this.localAudio.getOriginalStream(); var newStream = this.rtcUtils.createStream(stream); this.localAudio = this.createLocalStream(newStream, "audio", true); - // Stop the stream to trigger onended event for old stream - oldStream.stop(); + // Stop the stream + this.stopMediaStream(oldStream); APP.xmpp.switchStreams(newStream, oldStream, callback, true); }, isVideoMuted: function (jid) { @@ -262,6 +262,29 @@ var RTC = { if(devices.video === true || devices.video === false) this.devices.video = devices.video; eventEmitter.emit(RTCEvents.AVAILABLE_DEVICES_CHANGED, this.devices); + }, + /** + * A method to handle stopping of the stream. + * One point to handle the differences in various implementations. + */ + stopMediaStream: function (mediaStream) { + mediaStream.getAudioTracks().forEach(function (track) { + // stop() not supported with IE + if (track.stop) { + track.stop(); + } + }); + mediaStream.getVideoTracks().forEach(function (track) { + // stop() not supported with IE + if (track.stop) { + track.stop(); + } + }); + + // + if (mediaStream.stop) { + mediaStream.stop(); + } } }; diff --git a/modules/xmpp/TraceablePeerConnection.js b/modules/xmpp/TraceablePeerConnection.js index f72055ad0..f1486bc66 100644 --- a/modules/xmpp/TraceablePeerConnection.js +++ b/modules/xmpp/TraceablePeerConnection.js @@ -258,21 +258,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 {