-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
Loop through sources then techs #2844
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 |
---|---|---|
|
@@ -1700,36 +1700,26 @@ class Player extends Component { | |
* @method selectSource | ||
*/ | ||
selectSource(sources) { | ||
// Loop through each playback technology in the options order | ||
for (var i=0,j=this.options_.techOrder;i<j.length;i++) { | ||
let techName = toTitleCase(j[i]); | ||
let tech = Tech.getTech(techName); | ||
// Support old behavior of techs being registered as components. | ||
// Remove once that deprecated behavior is removed. | ||
if (!tech) { | ||
tech = Component.getComponent(techName); | ||
} | ||
// Check if the current tech is defined before continuing | ||
if (!tech) { | ||
log.error(`The "${techName}" tech is undefined. Skipped browser support check for that tech.`); | ||
continue; | ||
} | ||
|
||
// Check if the browser supports this technology | ||
if (tech.isSupported()) { | ||
// Loop through each source object | ||
for (var a=0,b=sources;a<b.length;a++) { | ||
var source = b[a]; | ||
|
||
// Check if source can be played with this technology | ||
if (tech.canPlaySource(source)) { | ||
return { source: source, tech: techName }; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
// Get only the techs that exist and are supported by the current platform | ||
let techs = | ||
this.options_.techOrder | ||
.map(toTitleCase) | ||
.map(techName => Tech.getTech(techName) || Component.getComponent(techName) || | ||
log.error(`The "${techName}" tech is undefined. Skipped browser support check for that tech.`)) | ||
.filter(tech => tech && tech.isSupported()); | ||
|
||
// Depending on the truthiness of options.sourceOrder, we swap the order of techs and sources | ||
// to select from them based on their priority. | ||
let combinedSources = this.options_.sourceOrder ? | ||
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. This is very cool. I wonder if we can somehow combine the two very similar reduces here.. 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. You can take my changes/some ideas from this PR since you've done most of the work. |
||
sources.reduce((acc, source) => acc.concat(techs.map(tech => ({source, tech}))), []) : | ||
techs.reduce((acc, tech) => acc.concat(sources.map(source => ({source, tech}))), []); | ||
|
||
let matchedSource = combinedSources | ||
.find(({source, tech}) => tech.canPlaySource(source)); | ||
|
||
return matchedSource ? | ||
{ source: matchedSource.source, tech: matchedSource.tech.name } : | ||
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. I decided against using the For instance: Tech.registerTech('TotallyNotFoo', Foo); Would have a name of |
||
false; | ||
} | ||
|
||
/** | ||
|
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.
While this was clever, I decided to make it more explicit since I wanted to add the comments from the old function back.