-
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
Allow to use custom Player class #3458
Conversation
@gkatsev Use case for this PR. I`m currently working on upgrading video.js from version 4 to version 5 in a project. Player was extended and replaced with code like this: const {Player} = videojs;
videojs.Player = Player.extend({
init(player, opts, ready) {
Player.call(this, player, options, ready);
}
}); Main reason for this PR is ability to use custom player class via standard In this project player is embedded in many places and i would rather avoid situation in which update player would involve modifying code to create player instance. At first i tried to replace only |
Thanks for the details, @adam187. Seems like this is a simple enough change for a lot of benefit. @videojs/core-committers thoughts? |
Yeah, I don't see any down sides. |
LGTM. |
LGTM |
1 similar comment
LGTM |
Would you be able to rebase this? |
@gkatsev Done. |
Awesome, thanks! |
Just tested it locally. One thing that I realized could potentially be an issue is that you're no longer able to access the original Player object. |
@gkatsev Well, in my use case i'm changing player before any instance of videojs is initialized. But isn't this an potential issue with other components replaced via |
@adam187 Yup, it's definitely an issue. Though, the Player component is the main piece of the videojs and we've previously not officially recommended replacing existing components via |
@gkatsev Yes, i`m fully understand your your concern. We could throw error when |
hm... |
I think that throwing would be an option in the case you outlined @gkatsev. It's not a breaking change, either, because this wasn't previously allowed. Perhaps it should throw if you're attempting to |
Throwing early is probably good, and we could always loosen it later if we necessary. @adam187 would you be able to add that in? Also, looks like there's a conflict, probably because of the new hooks feature. |
to allow to extend player class
04f23ce
to
b391c39
Compare
@gkatsev Take a look. |
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.
@adam187 thanks!
Description
Allow to use custom player class
Specific Changes proposed
This change will allow to use custom player class. In version 4 new player instance was created from
vjs.Player
https://github.com/videojs/video.js/blob/release/4.2.0/src/js/core.js#L52 so it was possible to override Player witch custom class. Right now it's not possible since player is created directly fromPlayer
import. UsingComponent.getComponent('Player')
will alllow to use custom player class that can be registered viaComponent.registerComponent
same as current player is registered right now https://github.com/videojs/video.js/blob/master/src/js/player.js#L2979Requirements Checklist