-
Notifications
You must be signed in to change notification settings - Fork 53
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,18 +54,35 @@ module.exports = function(videojs) { | |
this.update(); | ||
}, | ||
|
||
orderSources: function(a, b) { | ||
if (a.res && b.res) { | ||
return parseFloat(a.res) - parseFloat(b.res); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor suggestion, we prefer to start comments with |
||
singleTypeSources = sources.filter(function(item) { | ||
return item.type === player.currentType(); | ||
}); | ||
|
||
/* sort sources by res attributed if exist */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a typo, |
||
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, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
orderSources
, perhaps it would be more appropriate to make it a locally-scoped anonymous function like the one in.filter
on line 74.res
attribute toresolution
will help clarify its purpose.resolution
attribute, we should keep the sources in the same order.