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 the source given to Player#src before use #4030

Merged
merged 10 commits into from
Feb 6, 2017

Conversation

brandonocasey
Copy link
Contributor

Description

  • Add a util that filters all possible Tech~SourceObjects into a valid Tech~SourceObject (see tests)
  • Remove Player#sourceList_ as it is no longer in use

Requirements Checklist

  • Feature implemented / Bug fixed
  • If necessary, more likely in a feature request than a bug fix
    • Change has been verified in an actual browser (Chome, Firefox, IE)
    • Unit Tests updated or fixed
  • Reviewed by Two Core Contributors

@brandonocasey brandonocasey force-pushed the fix/better-src-function branch from 6805695 to 41fb1db Compare February 3, 2017 17:21
@brandonocasey brandonocasey force-pushed the fix/better-src-function branch 2 times, most recently from a0721c5 to 602e6ce Compare February 3, 2017 18:18
@brandonocasey brandonocasey force-pushed the fix/better-src-function branch from 602e6ce to 0fe92a8 Compare February 3, 2017 18:19
@@ -2218,27 +2219,23 @@ class Player extends Component {
* The current video source when getting
*/
src(source) {
if (source === undefined) {
Copy link
Member

Choose a reason for hiding this comment

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

why was this part removed?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I see. I think it's better to keep it. Why do extra work if we know for sure we can exit early here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I guess we can keep it to do less work, I just though it would be better to have less code. I don't think that filterSource will do anything with it other than turn it into an empty array. I guess it depends on wether or not we want to log an error if an invalid source array is passed to us vs being used as a getter.

Copy link
Member

Choose a reason for hiding this comment

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

video.js throws the following errors:

player.src([]); // No compatible source was found for this media
player.src({}); // The media could not be loaded, either because the server or network failed or because the format is not supported.

It looks like vjs 5 special cased empty arrays to have the custom object and with an empty object it basically tried to set an empty string and had it raise the error from the video element.

Copy link
Member

Choose a reason for hiding this comment

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

I think we should maintain this functionality. Though, having player.src({}) produce the same error as player.src([]) sounds fine too.

Copy link
Contributor Author

@brandonocasey brandonocasey Feb 3, 2017

Choose a reason for hiding this comment

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

Do we want to wrap the this.error call in a setTimeout like what was done in sourceList_? and also done below

Copy link
Member

Choose a reason for hiding this comment

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

Probably, yes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

src/js/player.js Outdated

this.cache_.sources = [src];
// no valid sources, return the current source
if (!src.length) {
Copy link
Member

Choose a reason for hiding this comment

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

Should we treat src([]) the same as src()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we want to exit early in the case where an empty source is passed, I could see logging an error, but not much else would be different.

import {isObject} from './obj';

/**
* Filter out single bad source objects or multiple source objects in an
Copy link
Member

Choose a reason for hiding this comment

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

I don't think it's worth handling nested arrays of sources.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will remove that from the doc comments/unit tests if you like, but the code will probably stay the same either way.

src/js/player.js Outdated
}

this.cache_.source = src;
this.cache_.sources = src;
src = src[0];
Copy link
Member

Choose a reason for hiding this comment

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

with this, we'd only ever be able to try running through the first source. See line 2247.

Copy link
Member

Choose a reason for hiding this comment

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

Or at least, we don't have the benefit of filterSource for subsequent iterations and the two arrays aren't necessary in sync.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think 2247 uses the original source object and not src

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but previously source was the source of truth for a list of sources. With the filterSource functionality, the output of filterSource became the source of truth.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see

src/js/player.js Outdated

this.cache_.source = src;
this.currentType_ = src.type;
Copy link
Member

Choose a reason for hiding this comment

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

just realized that we need to move/copy this down into line 2264

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is there any reason not to use the cache_ object here?

Copy link
Member

Choose a reason for hiding this comment

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

probably no reason not to ad that in. This was just how it used to be.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am wondering two things now:

  1. Do we need to change this.cache_.source, this.cache_.src, and this.cache_.type in the middleware.setSource callback and also above it? or an we just do it inside?
  2. Should we even cache this.cache_.src and this.cache_.type or should we just cache this.cache_.source and use that when we need to get the type or the src url

Copy link
Member

Choose a reason for hiding this comment

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

If you have a source like this:

{
  src: 'foo',
  type: 'video/foo'
}

With a middleware that returns an m3u8 for it, we want the following behavior:

player.src();
// 'http://example.com/video.m3u8'

player.currentSrc();
// 'foo'

player.currentSource();
// {src: 'foo', type: 'video/foo'}

Let me double check what we talked about for currentType previously.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, maybe we don't need to move currentType because we want it to match the type of the video returned by player.currentSrc(). So, in the above scenario, it'll be video/foo.

@brandonocasey
Copy link
Contributor Author

@gkatsev this has been updated with a lot of the things that you asked about

@@ -2385,14 +2357,7 @@ class Player extends Component {
* The current source object
*/
currentSource() {
const source = {};
const src = this.currentSrc();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code didn't make sense because this.currentSrc was looking at the same variable (this.cache_.source).

@@ -2218,37 +2219,39 @@ class Player extends Component {
* The current video source when getting
*/
src(source) {
if (source === undefined) {
Copy link
Member

Choose a reason for hiding this comment

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

I really think this should be separate and at the top here. It makes a clear delineation between when it's being called as a getter vs when it's called as a setter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added back in in the most recent commit

@@ -2415,7 +2380,7 @@ class Player extends Component {
* The source MIME type
*/
currentType() {
return this.currentType_ || '';
return this.currentSource() && this.currentSource().type || '';
Copy link
Member

Choose a reason for hiding this comment

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

any other references to this.currentType_ that need to be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

using ack and ripgrep returns no results for this.currentType_ now, so I don't think so.

src/js/player.js Outdated
@@ -2264,11 +2266,26 @@ class Player extends Component {
}

this.changingSrc_ = false;
this.cache_.src = src_.src;
this.cache_.source = src[0];
this.cache_.src = src_;
Copy link
Member

Choose a reason for hiding this comment

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

this should be src_.src.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

your right

@gkatsev
Copy link
Member

gkatsev commented Feb 6, 2017

Also, should we clear out the source caches if we error out? So, if everything worked but then you do player.src([]), player.currentSources() still returns the previously loaded sources.

@brandonocasey
Copy link
Contributor Author

brandonocasey commented Feb 6, 2017

Maybe we should reset the source cache at the top of the function if it is not being used as a getter?

Ex:

src(source) {
  if (!source) {
   return this.cache_.src;
  }

  this.cache_.src = null;
  this.cache_.source = null;
  this.cache_.sources = [];
}

Copy link
Member

@gkatsev gkatsev left a comment

Choose a reason for hiding this comment

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

Follow up from this PR is here: #4036

@gkatsev
Copy link
Member

gkatsev commented Feb 6, 2017

Making the executive decision to merge even though travis is being silly. Hopefully master will be fine.

@gkatsev gkatsev merged commit 6541467 into master Feb 6, 2017
@gkatsev gkatsev deleted the fix/better-src-function branch February 6, 2017 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants