-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Conversation
6805695
to
41fb1db
Compare
a0721c5
to
602e6ce
Compare
602e6ce
to
0fe92a8
Compare
@@ -2218,27 +2219,23 @@ class Player extends Component { | |||
* The current video source when getting | |||
*/ | |||
src(source) { | |||
if (source === undefined) { |
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.
why was this part removed?
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.
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?
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.
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.
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.
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.
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.
I think we should maintain this functionality. Though, having player.src({})
produce the same error as player.src([])
sounds fine too.
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.
Do we want to wrap the this.error
call in a setTimeout
like what was done in sourceList_
? and also done below
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.
Probably, yes.
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.
done
src/js/player.js
Outdated
|
||
this.cache_.sources = [src]; | ||
// no valid sources, return the current source | ||
if (!src.length) { |
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.
Should we treat src([])
the same as src()
?
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.
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 |
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.
I don't think it's worth handling nested arrays of sources.
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.
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]; |
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.
with this, we'd only ever be able to try running through the first source. See line 2247.
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.
Or at least, we don't have the benefit of filterSource
for subsequent iterations and the two arrays aren't necessary in sync.
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.
I think 2247 uses the original source
object and not src
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.
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.
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.
I see
src/js/player.js
Outdated
|
||
this.cache_.source = src; | ||
this.currentType_ = src.type; |
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.
just realized that we need to move/copy this down into line 2264
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.
is there any reason not to use the cache_
object here?
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.
probably no reason not to ad that in. This was just how it used to be.
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.
I am wondering two things now:
- Do we need to change
this.cache_.source
,this.cache_.src
, andthis.cache_.type
in themiddleware.setSource
callback and also above it? or an we just do it inside? - Should we even cache
this.cache_.src
andthis.cache_.type
or should we just cachethis.cache_.source
and use that when we need to get thetype
or thesrc
url
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.
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.
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.
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
.
@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(); |
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.
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) { |
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.
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.
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.
ok
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.
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 || ''; |
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.
any other references to this.currentType_
that need to be removed?
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.
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_; |
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.
this should be src_.src
.
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.
your right
Also, should we clear out the source caches if we error out? So, if everything worked but then you do |
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 = [];
} |
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.
Follow up from this PR is here: #4036
Making the executive decision to merge even though travis is being silly. Hopefully master will be fine. |
Description
Tech~SourceObjects
into a validTech~SourceObject
(see tests)Player#sourceList_
as it is no longer in useRequirements Checklist