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

Filter sources type and sort by resolution #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
23 changes: 20 additions & 3 deletions src/js/components/QualitySelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,35 @@ module.exports = function(videojs) {
this.update();
},

orderSources: function(a, b) {
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Instead of using a public sort method for orderSources, perhaps it would be more appropriate to make it a locally-scoped anonymous function like the one in .filter on line 74.
  2. For readability, renaming the res attribute to resolution will help clarify its purpose.
  3. If one or more sources do not have the resolution attribute, we should keep the sources in the same order.

if (a.res && b.res) {
return parseFloat(a.res) - parseFloat(b.res);
Copy link
Contributor

Choose a reason for hiding this comment

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

By default, can the sort order be descending with the largest resolution at the top? Thanks!

}
return;
},

/**
* @inheritdoc
*/
createItems: function() {
var player = this.player(),
sources = player.currentSources();
sources = player.currentSources(),
singleTypeSources,
orderedSources;

/* filter sources by the current type on the player */
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor suggestion, we prefer to start comments with // instead of using /* */. Thanks!

singleTypeSources = sources.filter(function(item) {
return item.type === player.currentType();
});

/* sort sources by res attributed if exist */
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a typo, by res attributed if exist can be changed to by resolution attribute if it exists

orderedSources = singleTypeSources.sort(this.orderSources);

if (!sources || sources.length < 2) {
if (!orderedSources || orderedSources.length < 2) {
return [];
}

return _.map(sources, function(source) {
return _.map(orderedSources, function(source) {
return new QualityOption(player, {
source: source,
selected: source.src === this.selectedSrc,
Expand Down