Skip to content

Commit

Permalink
fix: prevent double source buffer ready on IE11 (#1015)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey authored Dec 2, 2020
1 parent 5f14909 commit b1c2969
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
18 changes: 14 additions & 4 deletions src/source-updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,12 @@ export default class SourceUpdater extends videojs.EventTarget {
};
this.createdSourceBuffers_ = false;
this.initializedEme_ = false;
this.triggeredReady_ = false;
}

initializedEme() {
this.initializedEme_ = true;
if (this.ready()) {
this.trigger('ready');
}
this.triggerReady();
}

hasCreatedSourceBuffers() {
Expand Down Expand Up @@ -371,7 +370,18 @@ export default class SourceUpdater extends videojs.EventTarget {
this.addOrChangeSourceBuffers(codecs);
this.createdSourceBuffers_ = true;
this.trigger('createdsourcebuffers');
if (this.ready()) {
this.triggerReady();
}

triggerReady() {
// only allow ready to be triggered once, this prevents the case
// where:
// 1. we trigger createdsourcebuffers
// 2. ie 11 synchronously initializates eme
// 3. the synchronous initialization causes us to trigger ready
// 4. We go back to the ready check in createSourceBuffers and ready is triggered again.
if (this.ready() && !this.triggeredReady_) {
this.triggeredReady_ = true;
this.trigger('ready');
}
}
Expand Down
11 changes: 9 additions & 2 deletions test/videojs-http-streaming.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4640,7 +4640,14 @@ QUnit.test('integration: updates source updater after eme init', function(assert
sourceUpdater.on(
'createdsourcebuffers',
() => {
assert.notOk(sourceUpdater.hasInitializedAnyEme(), 'has not initialized eme yet');
let expected = false;

// IE initializes eme syncronously directly after source buffer
// creation
if (videojs.browser.IE_VERSION) {
expected = true;
}
assert.equal(sourceUpdater.hasInitializedAnyEme(), expected, 'correct eme state');
}
);

Expand All @@ -4661,7 +4668,7 @@ QUnit.test('integration: updates source updater after eme init', function(assert
this.standardXHRResponse(this.requests.shift(), audioSegment());
});

QUnit.test('player error when key session creation rejects promise', function(assert) {
QUnit[testOrSkip]('player error when key session creation rejects promise', function(assert) {
const done = assert.async();

this.player.error = (errorObject) => {
Expand Down

0 comments on commit b1c2969

Please sign in to comment.