Browse Source

Uses one method from RTC to stop media streams.

j8
damencho 10 years ago
parent
commit
11e1197901
2 changed files with 28 additions and 19 deletions
  1. 27
    4
      modules/RTC/RTC.js
  2. 1
    15
      modules/xmpp/TraceablePeerConnection.js

+ 27
- 4
modules/RTC/RTC.js View File

@@ -210,8 +210,8 @@ var RTC = {
210 210
         var videoStream = this.rtcUtils.createStream(stream, true);
211 211
         this.localVideo =
212 212
             this.createLocalStream(videoStream, "video", true, type);
213
-        // Stop the stream to trigger onended event for old stream
214
-        oldStream.stop();
213
+        // Stop the stream
214
+        this.stopMediaStream(oldStream);
215 215
 
216 216
         APP.xmpp.switchStreams(videoStream, oldStream,localCallback);
217 217
     },
@@ -219,8 +219,8 @@ var RTC = {
219 219
         var oldStream = this.localAudio.getOriginalStream();
220 220
         var newStream = this.rtcUtils.createStream(stream);
221 221
         this.localAudio = this.createLocalStream(newStream, "audio", true);
222
-        // Stop the stream to trigger onended event for old stream
223
-        oldStream.stop();
222
+        // Stop the stream
223
+        this.stopMediaStream(oldStream);
224 224
         APP.xmpp.switchStreams(newStream, oldStream, callback, true);
225 225
     },
226 226
     isVideoMuted: function (jid) {
@@ -262,6 +262,29 @@ var RTC = {
262 262
         if(devices.video === true || devices.video === false)
263 263
             this.devices.video = devices.video;
264 264
         eventEmitter.emit(RTCEvents.AVAILABLE_DEVICES_CHANGED, this.devices);
265
+    },
266
+    /**
267
+     * A method to handle stopping of the stream.
268
+     * One point to handle the differences in various implementations.
269
+     */
270
+    stopMediaStream: function (mediaStream) {
271
+        mediaStream.getAudioTracks().forEach(function (track) {
272
+            // stop() not supported with IE
273
+            if (track.stop) {
274
+                track.stop();
275
+            }
276
+        });
277
+        mediaStream.getVideoTracks().forEach(function (track) {
278
+            // stop() not supported with IE
279
+            if (track.stop) {
280
+                track.stop();
281
+            }
282
+        });
283
+
284
+        //
285
+        if (mediaStream.stop) {
286
+            mediaStream.stop();
287
+        }
265 288
     }
266 289
 };
267 290
 

+ 1
- 15
modules/xmpp/TraceablePeerConnection.js View File

@@ -258,21 +258,7 @@ TraceablePeerConnection.prototype.addStream = function (stream) {
258 258
 TraceablePeerConnection.prototype.removeStream = function (stream, stopStreams) {
259 259
     this.trace('removeStream', stream.id);
260 260
     if(stopStreams) {
261
-        stream.getAudioTracks().forEach(function (track) {
262
-            // stop() not supported with IE
263
-            if (track.stop) {
264
-                track.stop();
265
-            }
266
-        });
267
-        stream.getVideoTracks().forEach(function (track) {
268
-            // stop() not supported with IE
269
-            if (track.stop) {
270
-                track.stop();
271
-            }
272
-        });
273
-        if (stream.stop) {
274
-            stream.stop();
275
-        }
261
+        RTC.stopMediaStream(stream);
276 262
     }
277 263
 
278 264
     try {

Loading…
Cancel
Save