Skip to content

Commit

Permalink
fix(source-updater): run callbacks after setting timestampOffset (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
squarebracket authored Apr 26, 2019
1 parent fe3b378 commit 6ecf859
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/source-updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export default class SourceUpdater {
if (typeof offset !== 'undefined') {
this.queueCallback_(() => {
this.sourceBuffer_.timestampOffset = offset;
this.runCallback_();
});
this.timestampOffset_ = offset;
}
Expand Down
18 changes: 18 additions & 0 deletions test/source-updater.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,24 @@ QUnit.test('runs the next callback after updateend fires', function(assert) {
'appended the bytes');
});

QUnit.test('runs the next callback after calling timestampOffset', function(assert) {
let updater = new SourceUpdater(this.mediaSource, 'video/mp2t');
let sourceBuffer;

updater.timestampOffset(10);
updater.appendBuffer({
bytes: new Uint8Array([0, 1, 2])
}, () => {});

this.mediaSource.trigger('sourceopen');
sourceBuffer = this.mediaSource.sourceBuffers[0];

assert.equal(sourceBuffer.timestampOffset, 10, 'offset correctly set');
assert.equal(sourceBuffer.updates_.length, 1, 'updated once');
assert.deepEqual(sourceBuffer.updates_[0].append, new Uint8Array([0, 1, 2]),
'appended the bytes');
});

QUnit.test('runs only one callback at a time', function(assert) {
let updater = new SourceUpdater(this.mediaSource, 'video/mp2t');
let sourceBuffer;
Expand Down

0 comments on commit 6ecf859

Please sign in to comment.