-
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
feat: allow embeds via <video-js> element #4640
Conversation
src/js/setup.js
Outdated
@@ -31,6 +31,7 @@ const autoSetup = function() { | |||
// through each list of elements to build up a new, combined list of elements. | |||
const vids = document.getElementsByTagName('video'); | |||
const audios = document.getElementsByTagName('audio'); | |||
const divs = document.getElementsByTagName('div'); |
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 allows for using data-setup
with divs. Though, this seems a bit generic, should we use a different trigger with divs?
@@ -0,0 +1,165 @@ | |||
<!DOCTYPE html> |
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 file will get autocopied into sandbox/embeds.html
on the first npm start
run by the user.
It has 18 different video.js embeds grouped by whether data-setup is used or not, how the source is added, and the 3 different embed types: video, video+player div wrapper, just div.
|
||
if (divEmbed) { | ||
el = this.el_ = tag; | ||
tag = this.tag = document.createElement('video'); |
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.
we probably should try to be smarted about this. Maybe we need an audio element instead but we might not have a source at this point. Probably more than good enough for first release.
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.
Isn't it possible that the div will contain a video element already?
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.
Missed this previously. Yes but I will say it's misconfigured in that case.
So, other than adding a lot of tests, we should decide if we're ok with using |
} | ||
|
||
.wrapper { | ||
display: grid; |
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.
In a grooming discussion, we talked about the |
Is the div embed meant to take over as the primary embed method or is it an optional feature for React-like situations?
What I'd really love to see is a videojs web component instead of a div, if that at all makes sense to do here. |
Haven't thought about whether this should be the default yet. The current pain-point is that if you use the video tag, you end up quickly flashing the default video element before video.js gets initialized. So, this will solve it. However, this will also work better for the react-like situations compared to what we currently have with the "ingested player div". I do like the idea of a web-component, but I think that isn't necessarily equivalent to a div embed. Maybe just a custom element? However, native custom element support is pretty small right now and I would prefer not to have to include a polyfill for it. |
I'm in favor of using |
|
The broken PR was interesting because it revealed that IE9 doesn't allow using a source element outside of a video element. We'd want to make sure that this is documented well before this PR is merged. |
At the video.js TSC meeting, we talked about whether we can just use a |
I thought custom elements were basically just renamed divs unless you
subclassed a native element.
|
Oh, I think I figured out my issue. I hadn't updated the code to look for |
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.
So, with these changes, you can now use a video-js
element! And also vjs-source
elements (this mostly as a workaround for IE9).
moved things left to do to the top post
src/js/player.js
Outdated
@@ -374,6 +375,8 @@ class Player extends Component { | |||
|
|||
this.el_ = this.createEl(); | |||
|
|||
this.options_.sources = Player.getTagSettings(this.tag).sources || this.options_.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.
we might want to just update getTagSettings
to know about vjs-source
as well, instead of this, though, this seems to work.
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 breaks some tests, so, removing and updating getTagSettings
.
@@ -31,6 +31,7 @@ const autoSetup = function() { | |||
// through each list of elements to build up a new, combined list of elements. | |||
const vids = document.getElementsByTagName('video'); | |||
const audios = document.getElementsByTagName('audio'); | |||
const divs = document.getElementsByTagName('video-js'); |
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.
we now look for video-js
elements for data-setup
, and so we definitely can keep data-setup
now.
@videojs/core-committers Should we only allow |
<video-js>
element
<video-js>
elementThere 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.
Looks good overall. I wonder if some of the variable names should be changed so they're not called div
s... although, I can't think of a better option off the top of my head!
Also, do we want the elements to be called |
Custom element names should contain a hyphen for namespacing.
|
Yup, probably best to keep the hyphen, though it isn't technically a real custom element. |
@@ -0,0 +1,83 @@ | |||
# How to Embed the Video.js player |
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.
after I added this page I remember that we have the setup.md
file. This page can probably stay as is but setup.md
probably should be updated a bit as well and point to this page.
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.
Linked from setup.md
now.
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.
Some minor grammatical points and one question about class
.
docs/guides/embeds.md
Outdated
@@ -0,0 +1,85 @@ | |||
# How to Embed the Video.js player | |||
|
|||
Video.js is meant to be an ehnacement to the video element in HTML5 so for years, it's embed code has been just a `<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.
Typo ehnacement
and it's
should be its
docs/guides/embeds.md
Outdated
Video.js is meant to be an ehnacement to the video element in HTML5 so for years, it's embed code has been just a `<video>` element. | ||
Video.js then wraps the video element in a div that is used for us to place controls and anything else that's required for the player. | ||
|
||
For a long time this was enough. In 2016, a "div ingest" which allows the developer to give Video.js a player div to use instead of making it's own. |
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.
Second sentence is incomplete. Maybe needs was added
somewhere?
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.
oops, yes, something like that.
docs/guides/embeds.md
Outdated
|
||
```html | ||
<!-- via data-setup --> | ||
<video-js id="vid1" class="video-js" data-setup='{}'> |
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 you need the class="video-js"
? Could we add that if it's missing?
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.
Could make sense to add it for the video-js
element. Adding it unconditionally could potentially cause stylistic bugs.
docs/guides/embeds.md
Outdated
- IE9 doesn't support having `source` elements outside of the `video` element, thus, the `video-js` embed will not work there. Though, if the source is set later, it should still work. | ||
|
||
## data-setup | ||
This is an ease-of-use method for having Video.js set up the player automatically. It is an html attribute and it takes a JSON string representation of the [player options](/docs/guides/options.md) as the value. |
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.
html
should be all caps.
QA-LGTM |
src/js/player.js
Outdated
|
||
if (el.className.indexOf('video-js') === -1) { | ||
el.className += ' video-js'; | ||
} |
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 use dom.hasClass()
here? Wouldn't this leave room for false positives like if it had video-js-xyz
?
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.
And addClass()
maybe?
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, yeah, I forgot we had helpers for this. Didn't use the player methods because it isn't quite available yet.
A we retained a lot of references to DOM elements in various components. Here we clear it up. Also, make sure that we remove unused listeners as they can retain objects as well. Update evented mixin to null out the eventBusEl_ after the component is disposed. Add a feature for components, to tell it not to auto-initialize the evented mixin. Re-enable the tests that were removed in #4640.
Description
Add the ability to initialize Video.js with an element named
video-js
. This is because sometimes, seeing the native element is undesirable, plus, it's cool to have our own element.Can be used just like the
video
embed. For IE9-only we have avjs-source
element that's copied to asource
element because IE9 is strict about keepingsource
elements inside ofvideo
elements.TODO
vjs-source
element?Player.getTagSettings
instead of my workaround for sources to work properly withvjs-source
.vjs-track
as well for IE9.