Skip to content

Commit

Permalink
don't track progress until ready
Browse files Browse the repository at this point in the history
Delay manual progress checks until the tech is ready to avoid errors. The Flash tech errors if buffered() is called before the SWF has loaded, for instance.
  • Loading branch information
dmlap committed Jul 7, 2015
1 parent 49fbea6 commit 19a0628
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/js/tech/tech.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ class Tech extends Component {
this.manualProgress = true;

// Trigger progress watching when a source begins loading
this.trackProgress();
this.one('ready', () => {
this.trackProgress();
});
}

manualProgressOff() {
Expand All @@ -109,6 +111,7 @@ class Tech extends Component {
}

trackProgress() {
this.stopTrackingProgress();
this.progressInterval = this.setInterval(Fn.bind(this, function(){
// Don't trigger unless buffered amount is greater than last time

Expand Down
14 changes: 13 additions & 1 deletion test/unit/tech/tech.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,26 @@ test('stops manual timeupdates while paused', function() {
});

test('should synthesize progress events by default', function() {
var progresses = 0, tech;
var progresses = 0, bufferedPercent = 0.5, tech;
tech = new Tech();
tech.on('progress', function() {
progresses++;
});
tech.bufferedPercent = function() {
return bufferedPercent;
};

this.clock.tick(500);
equal(progresses, 0, 'waits until ready');

tech.trigger('ready');
this.clock.tick(500);
equal(progresses, 1, 'triggered one event');

tech.trigger('ready');
bufferedPercent = 0.75;
this.clock.tick(500);
equal(progresses, 2, 'repeated readies are ok');
});

test('dispose() should stop time tracking', function() {
Expand Down

0 comments on commit 19a0628

Please sign in to comment.