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

Tech change handler spam #1859

Closed
Closed
Changes from 5 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
40 changes: 29 additions & 11 deletions src/js/media/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,14 @@ vjs.MediaTechController = vjs.Component.extend({
* any controls will still keep the user active
*/
vjs.MediaTechController.prototype.initControlsListeners = function(){
var player, activateControls;
var player;

player = this.player();

activateControls = function(){
if (player.controls() && !player.usingNativeControls()) {
this.addControlsListeners();
}
};

// Set up event listeners once the tech is ready and has an element to apply
// listeners to
this.ready(activateControls);
this.on(player, 'controlsenabled', activateControls);
this.ready(this.activateControls);
this.on(player, 'controlsenabled', this.activateControls);
this.on(player, 'controlsdisabled', this.removeControlsListeners);

// if we're loading the playback object after it has started loading or playing the
Expand All @@ -81,6 +75,15 @@ vjs.MediaTechController.prototype.initControlsListeners = function(){
});
};

vjs.MediaTechController.prototype.removeControlsListeners = function () {
Copy link
Member

Choose a reason for hiding this comment

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

There's already a removeControlsListeners. Should this be combined with that?

Copy link
Member

Choose a reason for hiding this comment

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

I think there's a problem with this. It will remove the removeControlsListeners and activateControls listeners when controlsdisabled is triggered, but what if controlsenabled is triggered again? I think this will break that use case.
e.g.

  • enable controls
  • disable controls
  • enable controls again

var player;

player = this.player();

this.off(player, 'controlsenabled', this.activateControls);
this.off(player, 'controlsdisabled', this.removeControlsListeners);
};

vjs.MediaTechController.prototype.addControlsListeners = function(){
var userWasActive;

Expand Down Expand Up @@ -133,6 +136,19 @@ vjs.MediaTechController.prototype.removeControlsListeners = function(){
this.off('mousedown');
};

/**
* Activate contols listeners handler
*/
vjs.MediaTechController.prototype.activateControls = function () {
var player;

player = this.player();

if (player.controls() && !player.usingNativeControls()) {
this.addControlsListeners();
}
};

/**
* Handle a click on the media element. By default will play/pause the media.
*/
Expand Down Expand Up @@ -218,6 +234,7 @@ vjs.MediaTechController.prototype.manualTimeUpdatesOff = function(){
var player = this.player_;

this.manualTimeUpdates = false;

this.stopTrackingCurrentTime();
this.off(player, 'play', this.trackCurrentTime);
this.off(player, 'pause', this.stopTrackingCurrentTime);
Expand All @@ -239,7 +256,8 @@ vjs.MediaTechController.prototype.stopTrackingCurrentTime = function(){
this.player().trigger('timeupdate');
};

vjs.MediaTechController.prototype.dispose = function() {
vjs.MediaTechController.prototype.dispose = function(){
this.removeControlsListeners();
Copy link
Member

Choose a reason for hiding this comment

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

This actuallyl shouldn't be needed. When you use this.off(player, 'controlsenabled', this.activateControls); it should automatically remove the activateControls listener from the player when this tech is disposed. It's a feature of the off method.

// Turn off any manual progress or timeupdate tracking
if (this.manualProgress) { this.manualProgressOff(); }

Expand All @@ -248,7 +266,7 @@ vjs.MediaTechController.prototype.dispose = function() {
vjs.Component.prototype.dispose.call(this);
};

vjs.MediaTechController.prototype.setCurrentTime = function() {
vjs.MediaTechController.prototype.setCurrentTime = function(){
// improve the accuracy of manual timeupdates
if (this.manualTimeUpdates) { this.player().trigger('timeupdate'); }
};
Expand Down