Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't track progress until ready #2316

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one already does a bind to this internally, so the fat arrow function here is redundant.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(fixed and pulled in)

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