Skip to content

Commit 20b85f4

Browse files
committed
Only stop user media automatically, when all tracks have ended.
1 parent 2a8ec3f commit 20b85f4

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

static/js/mediastream/usermedia.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,19 +366,23 @@ define(['jquery', 'underscore', 'audiocontext', 'mediastream/dummystream', 'webr
366366

367367
if (stream) {
368368
// Catch events when streams end.
369+
var trackCount = 0;
369370
var onended = _.bind(function(event) {
370-
if (this.started) {
371+
trackCount--;
372+
if (this.started && trackCount <= 0) {
371373
console.log("Stopping user media as a stream has ended.", event);
372374
this.stop();
373375
}
374376
}, this);
375377
if (stream.getTracks) {
376378
_.each(stream.getTracks(), function(t) {
377379
t.onended = onended;
380+
trackCount++;
378381
});
379382
} else {
380383
// Legacy api.
381384
stream.onended = onended;
385+
trackCount++;
382386
}
383387
// Set new stream.
384388
this.localStream = stream;

0 commit comments

Comments
 (0)