Fixes #5 Only bind to QUALITY_SELECTED once

As things turn out, the middleware constructor is called every time `setSource`
is called [1]. This was causing a new listener to get bound to
`QUALITY_SELECTED` on each change by the quality selector. :( This change makes
it so the listener is only bound on the initial creation of the player.

[1] 03529163b6/src/js/tech/middleware.js (L66)
This commit is contained in:
Ethan Smith 2017-10-18 11:54:37 -04:00
parent dedaf8e9be
commit 9dd9ca108b
3 changed files with 38 additions and 33 deletions

View file

@ -2,7 +2,8 @@
var _ = require('underscore'),
events = require('../events'),
qualityOptionFactory = require('./QualityOption');
qualityOptionFactory = require('./QualityOption'),
QUALITY_CHANGE_CLASS = 'vjs-quality-changing';
module.exports = function(videojs) {
var MenuButton = videojs.getComponent('MenuButton'),
@ -23,8 +24,14 @@ module.exports = function(videojs) {
constructor: function(player, options) {
MenuButton.call(this, player, options);
player.on(events.QUALITY_SELECTED, function(event, source) {
this.setSelectedSource(source);
// Update interface instantly so the user's change is acknowledged
player.on(events.QUALITY_SELECTED, function(event, newSource) {
this.setSelectedSource(newSource);
player.addClass(QUALITY_CHANGE_CLASS);
player.one('loadeddata', function() {
player.removeClass(QUALITY_CHANGE_CLASS);
});
}.bind(this));
// Since it's possible for the player to get a source before the selector is