From a3753ddb650d17ecb86e5744ea4cd7076618ad74 Mon Sep 17 00:00:00 2001 From: Matt Luedke Date: Wed, 20 Nov 2019 10:24:02 -0500 Subject: [PATCH] fix: Update menu when sources are set after player is ready (#47) Fixes #47 --- src/js/components/QualitySelector.js | 5 +++++ src/js/events.js | 1 + src/js/middleware/SourceInterceptor.js | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/src/js/components/QualitySelector.js b/src/js/components/QualitySelector.js index 9f439da..f1f8681 100644 --- a/src/js/components/QualitySelector.js +++ b/src/js/components/QualitySelector.js @@ -34,6 +34,11 @@ module.exports = function(videojs) { }); }.bind(this)); + // Update the list of menu items only when the list of sources change + player.on(events.PLAYER_SOURCES_CHANGED, function() { + this.update(); + }.bind(this)); + player.on(events.QUALITY_SELECTED, function(event, newSource) { // Update the selected source with the source that was actually selected this.setSelectedSource(newSource); diff --git a/src/js/events.js b/src/js/events.js index fb25fdf..d358e4d 100644 --- a/src/js/events.js +++ b/src/js/events.js @@ -4,5 +4,6 @@ module.exports = { QUALITY_REQUESTED: 'qualityRequested', QUALITY_SELECTED: 'qualitySelected', + PLAYER_SOURCES_CHANGED: 'playerSourcesChanged', }; diff --git a/src/js/middleware/SourceInterceptor.js b/src/js/middleware/SourceInterceptor.js index c231d91..c34b350 100644 --- a/src/js/middleware/SourceInterceptor.js +++ b/src/js/middleware/SourceInterceptor.js @@ -17,6 +17,11 @@ module.exports = function(videojs) { player._qualitySelectorSafeSeek.onPlayerSourcesChange(); } + if (!_.isEqual(sources, player._qualitySelectorPreviousSources)) { + player.trigger(events.PLAYER_SOURCES_CHANGED, sources); + player._qualitySelectorPreviousSources = sources; + } + // There are generally two source options, the one that videojs // auto-selects and the one that a "user" of this plugin has // supplied via the `selected` property. `selected` can come from