Bug 1208316 - Simplify stopTracksForStreamInMediaPlayback. r=jib

MozReview-Commit-ID: 9qQfit5l8Tg

--HG--
extra : rebase_source : c138635dd62504ada1c58f2b929a70fcb26f3ec3
This commit is contained in:
Andreas Pehrson 2016-09-09 16:12:00 +02:00
Родитель 53968f02be
Коммит 3ebd9d33a8
1 изменённых файлов: 4 добавлений и 22 удалений

Просмотреть файл

@ -48,28 +48,10 @@ MediaStreamPlayback.prototype = {
*/
stopTracksForStreamInMediaPlayback : function () {
var elem = this.mediaElement;
var waitForEnded = () => new Promise(resolve => {
elem.addEventListener('ended', function ended() {
elem.removeEventListener('ended', ended);
resolve();
});
});
var noTrackEnded = Promise.all(this.mediaStream.getTracks().map(t => {
let onNextLoop = wait(0);
let p = Promise.race([
onNextLoop,
haveEvent(t, "ended", onNextLoop)
.then(() => Promise.reject("Unexpected ended event for track " + t.id),
() => Promise.resolve())
]);
t.stop();
return p;
}));
return timeout(waitForEnded(), ENDED_TIMEOUT_LENGTH, "ended event never fired")
.then(() => ok(true, "ended event successfully fired"))
.then(() => noTrackEnded);
return Promise.all([
haveEvent(elem, "ended", wait(ENDED_TIMEOUT_LENGTH, new Error("Timeout"))),
...this.mediaStream.getTracks().map(t => (t.stop(), haveNoEvent(t, "ended")))
]);
},
/**