Browse Source

Only stop user media automatically, when all tracks have ended.

pull/257/head
Simon Eisenmann 10 years ago
parent
commit
20b85f4bcf
  1. 6
      static/js/mediastream/usermedia.js

6
static/js/mediastream/usermedia.js

@ -366,8 +366,10 @@ define(['jquery', 'underscore', 'audiocontext', 'mediastream/dummystream', 'webr
if (stream) { if (stream) {
// Catch events when streams end. // Catch events when streams end.
var trackCount = 0;
var onended = _.bind(function(event) { var onended = _.bind(function(event) {
if (this.started) { trackCount--;
if (this.started && trackCount <= 0) {
console.log("Stopping user media as a stream has ended.", event); console.log("Stopping user media as a stream has ended.", event);
this.stop(); this.stop();
} }
@ -375,10 +377,12 @@ define(['jquery', 'underscore', 'audiocontext', 'mediastream/dummystream', 'webr
if (stream.getTracks) { if (stream.getTracks) {
_.each(stream.getTracks(), function(t) { _.each(stream.getTracks(), function(t) {
t.onended = onended; t.onended = onended;
trackCount++;
}); });
} else { } else {
// Legacy api. // Legacy api.
stream.onended = onended; stream.onended = onended;
trackCount++;
} }
// Set new stream. // Set new stream.
this.localStream = stream; this.localStream = stream;

Loading…
Cancel
Save