Skip to content

Commit

Permalink
fix: remove extra timeupdate event when progress controls is disabled (
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-barstow authored Mar 23, 2021
1 parent 0cc8684 commit b2336aa
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions src/js/control-bar/progress-control/progress-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Component from '../../component.js';
import * as Dom from '../../utils/dom.js';
import clamp from '../../utils/clamp.js';
import {bind, throttle, UPDATE_REFRESH_INTERVAL} from '../../utils/fn.js';
import {silencePromise} from '../../utils/promise';

import './seek-bar.js';

Expand Down Expand Up @@ -137,11 +138,23 @@ class ProgressControl extends Component {

this.off(['mousedown', 'touchstart'], this.handleMouseDown);
this.off(this.el_, 'mousemove', this.handleMouseMove);
this.handleMouseUp();

this.removeListenersAddedOnMousedownAndTouchstart();

this.addClass('disabled');

this.enabled_ = false;

// Restore normal playback state if controls are disabled while scrubbing
if (this.player_.scrubbing()) {
const seekBar = this.getChild('seekBar');

this.player_.scrubbing(false);

if (seekBar.videoWasPlaying) {
silencePromise(this.player_.play());
}
}
}

/**
Expand All @@ -161,6 +174,18 @@ class ProgressControl extends Component {
this.enabled_ = true;
}

/**
* Cleanup listeners after the user finishes interacting with the progress controls
*/
removeListenersAddedOnMousedownAndTouchstart() {
const doc = this.el_.ownerDocument;

this.off(doc, 'mousemove', this.throttledHandleMouseSeek);
this.off(doc, 'touchmove', this.throttledHandleMouseSeek);
this.off(doc, 'mouseup', this.handleMouseUp);
this.off(doc, 'touchend', this.handleMouseUp);
}

/**
* Handle `mousedown` or `touchstart` events on the `ProgressControl`.
*
Expand Down Expand Up @@ -194,17 +219,13 @@ class ProgressControl extends Component {
* @listens mouseup
*/
handleMouseUp(event) {
const doc = this.el_.ownerDocument;
const seekBar = this.getChild('seekBar');

if (seekBar) {
seekBar.handleMouseUp(event);
}

this.off(doc, 'mousemove', this.throttledHandleMouseSeek);
this.off(doc, 'touchmove', this.throttledHandleMouseSeek);
this.off(doc, 'mouseup', this.handleMouseUp);
this.off(doc, 'touchend', this.handleMouseUp);
this.removeListenersAddedOnMousedownAndTouchstart();
}
}

Expand Down

0 comments on commit b2336aa

Please sign in to comment.