From d7c7d3801e514d9cf8cf7645d95df661324a6433 Mon Sep 17 00:00:00 2001 From: benjipott Date: Wed, 11 Feb 2015 11:21:12 +0100 Subject: [PATCH 1/6] Tech change handler spam fixes #882 #1485 #1505 #1484 --- src/js/media/media.js | 46 +++++++++++++++++++++++++++++++------------ test/unit/flash.js | 1 + test/unit/media.js | 1 + 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/js/media/media.js b/src/js/media/media.js index e75a8dbcda..6fb7427543 100644 --- a/src/js/media/media.js +++ b/src/js/media/media.js @@ -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 @@ -81,6 +75,15 @@ vjs.MediaTechController.prototype.initControlsListeners = function(){ }); }; +vjs.MediaTechController.prototype.removeControlsListeners = function () { + var player; + + player = this.player(); + + this.off(player, 'controlsenabled', this.activateControls); + this.off(player, 'controlsdisabled', this.removeControlsListeners); +}; + vjs.MediaTechController.prototype.addControlsListeners = function(){ var userWasActive; @@ -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. */ @@ -215,10 +231,13 @@ vjs.MediaTechController.prototype.manualTimeUpdatesOn = function(){ }; vjs.MediaTechController.prototype.manualTimeUpdatesOff = function(){ + var player = this.player_; + this.manualTimeUpdates = false; + this.stopTrackingCurrentTime(); - this.off('play', this.trackCurrentTime); - this.off('pause', this.stopTrackingCurrentTime); + this.off(player, 'play', this.trackCurrentTime); + this.off(player, 'pause', this.stopTrackingCurrentTime); }; vjs.MediaTechController.prototype.trackCurrentTime = function(){ @@ -237,7 +256,8 @@ vjs.MediaTechController.prototype.stopTrackingCurrentTime = function(){ this.player().trigger('timeupdate'); }; -vjs.MediaTechController.prototype.dispose = function() { +vjs.MediaTechController.prototype.dispose = function(){ + this.removeControlsListeners(); // Turn off any manual progress or timeupdate tracking if (this.manualProgress) { this.manualProgressOff(); } @@ -246,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'); } }; diff --git a/test/unit/flash.js b/test/unit/flash.js index 24f5ea3e5d..9cd14a5b9b 100644 --- a/test/unit/flash.js +++ b/test/unit/flash.js @@ -105,6 +105,7 @@ test('dispose removes the object element even before ready fires', function() { tech = new vjs.Flash({ id: noop, on: noop, + off: noop, trigger: noop, options_: {} }, { diff --git a/test/unit/media.js b/test/unit/media.js index f217b22d79..f989fcfa1e 100644 --- a/test/unit/media.js +++ b/test/unit/media.js @@ -44,6 +44,7 @@ test('stops timeupdates if the tech produces them natively', function() { playHandler = handler; } }, + off: this.noop, bufferedPercent: this.noop, trigger: function(event) { if (event === 'timeupdate') { From 6bfc50e5b1daa58b99c7a4d7de1edc201409b51c Mon Sep 17 00:00:00 2001 From: benjipott Date: Wed, 11 Feb 2015 11:21:12 +0100 Subject: [PATCH 2/6] Tech change handler spam fixes #882 #1485 #1505 #1484 --- src/js/media/media.js | 40 +++++++++++++++++++++++++++++----------- test/unit/media.js | 1 + 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/js/media/media.js b/src/js/media/media.js index 80f4c18de2..6fb7427543 100644 --- a/src/js/media/media.js +++ b/src/js/media/media.js @@ -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 @@ -81,6 +75,15 @@ vjs.MediaTechController.prototype.initControlsListeners = function(){ }); }; +vjs.MediaTechController.prototype.removeControlsListeners = function () { + var player; + + player = this.player(); + + this.off(player, 'controlsenabled', this.activateControls); + this.off(player, 'controlsdisabled', this.removeControlsListeners); +}; + vjs.MediaTechController.prototype.addControlsListeners = function(){ var userWasActive; @@ -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. */ @@ -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); @@ -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(); // Turn off any manual progress or timeupdate tracking if (this.manualProgress) { this.manualProgressOff(); } @@ -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'); } }; diff --git a/test/unit/media.js b/test/unit/media.js index 04a7f20dc1..1f41f64432 100644 --- a/test/unit/media.js +++ b/test/unit/media.js @@ -45,6 +45,7 @@ test('stops timeupdates if the tech produces them natively', function() { playHandler = handler; } }, + off: this.noop, bufferedPercent: this.noop, trigger: function(event) { if (event === 'timeupdate') { From e069608e2e4e06c0cd3610a722427e93767c0957 Mon Sep 17 00:00:00 2001 From: benjipott Date: Wed, 11 Feb 2015 11:42:20 +0100 Subject: [PATCH 3/6] Fix duplicate off key --- test/unit/media.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/unit/media.js b/test/unit/media.js index 1f41f64432..04a7f20dc1 100644 --- a/test/unit/media.js +++ b/test/unit/media.js @@ -45,7 +45,6 @@ test('stops timeupdates if the tech produces them natively', function() { playHandler = handler; } }, - off: this.noop, bufferedPercent: this.noop, trigger: function(event) { if (event === 'timeupdate') { From c7443d10eba5b03ea89dfad6e88cfded5328f585 Mon Sep 17 00:00:00 2001 From: benjipott Date: Wed, 11 Feb 2015 11:43:00 +0100 Subject: [PATCH 4/6] Fix duplicate off key --- test/unit/media.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/unit/media.js b/test/unit/media.js index 1f41f64432..04a7f20dc1 100644 --- a/test/unit/media.js +++ b/test/unit/media.js @@ -45,7 +45,6 @@ test('stops timeupdates if the tech produces them natively', function() { playHandler = handler; } }, - off: this.noop, bufferedPercent: this.noop, trigger: function(event) { if (event === 'timeupdate') { From 0da0f7791df7d98bc19ad537cd0a1e5278c29ef0 Mon Sep 17 00:00:00 2001 From: benjipott Date: Thu, 12 Feb 2015 07:14:45 +0100 Subject: [PATCH 5/6] Rename disable controls method --- src/js/media/media.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/js/media/media.js b/src/js/media/media.js index 6fb7427543..2d28e4cb2f 100644 --- a/src/js/media/media.js +++ b/src/js/media/media.js @@ -75,7 +75,7 @@ vjs.MediaTechController.prototype.initControlsListeners = function(){ }); }; -vjs.MediaTechController.prototype.removeControlsListeners = function () { +vjs.MediaTechController.prototype.disableControlsListeners = function () { var player; player = this.player(); @@ -257,7 +257,7 @@ vjs.MediaTechController.prototype.stopTrackingCurrentTime = function(){ }; vjs.MediaTechController.prototype.dispose = function(){ - this.removeControlsListeners(); + this.disableControlsListeners(); // Turn off any manual progress or timeupdate tracking if (this.manualProgress) { this.manualProgressOff(); } From 0316c38e613023fed88e2534d48fab2cfd8e0d3a Mon Sep 17 00:00:00 2001 From: benjipott Date: Thu, 12 Feb 2015 07:32:00 +0100 Subject: [PATCH 6/6] Rename method to desactivateControls --- src/js/media/media.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/js/media/media.js b/src/js/media/media.js index 2d28e4cb2f..4c7a50d8c6 100644 --- a/src/js/media/media.js +++ b/src/js/media/media.js @@ -75,7 +75,7 @@ vjs.MediaTechController.prototype.initControlsListeners = function(){ }); }; -vjs.MediaTechController.prototype.disableControlsListeners = function () { +vjs.MediaTechController.prototype.desactivateControls = function () { var player; player = this.player(); @@ -257,7 +257,7 @@ vjs.MediaTechController.prototype.stopTrackingCurrentTime = function(){ }; vjs.MediaTechController.prototype.dispose = function(){ - this.disableControlsListeners(); + this.desactivateControls(); // Turn off any manual progress or timeupdate tracking if (this.manualProgress) { this.manualProgressOff(); }