-
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
feature request: expose version from player.version() #8538
Comments
👋 Thanks for opening your first issue here! 👋 If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can. |
No, because videojs.VERSION is the version of the library, whereas the player is a component. However, it is possible to expose the version through the player instance. Here are 3 possibilities When instantiating the player const player = videojs('my-player', {
vjsVersion : videojs.VERSION
});
// Access the value
player.options().vjsVersion; Modifying the Player component prototype videojs.getComponent('Player').prototype.VJS_VERSION = videojs.VERSION;
const player = videojs('my-player');
// Access the value
player.VJS_VERSION; Modifying the Component component prototype videojs.getComponent('Component').prototype.VJS_VERSION = videojs.VERSION;
const player = videojs('my-player');
// Access the value
player.VJS_VERSION;
player.controlBar.VJS_VERSION;
// ... or any other component You can rename |
Also, are you saying that |
Thank you @amtins for nice workaround and 3 showcases. @gkatsev no, because In my case, I am developing on analytics library that works with VideoJS player. I am receiving already created instance of Until now, consumers of my library have been using CDN VideoJS integration, where I could relay on |
When using npm, videojs doesn't get added to import videojs from 'video.js';
console.log(videojs.VERSION); |
this does not work, at least package |
It definitely is there and it works. Is it a type issue you're running into maybe? See for a running example https://stackblitz.com/edit/stackblitz-starters-w9ggsk?description=React%20%20%20TypeScript%20starter%20project&file=src%2FApp.tsx,package.json&title=React%20Starter |
@gkatsev it is there, thank you very much. It was a type issue on my site , this made it work (also with version 8.6.1 I work with)
I would consider this issue as solved. But to solve my problem, may I somewhere ask for "new feature" , could |
I've definitely thought that there should be a version on the player before. And we should figure out the type issue. |
What would help me would be, if VideoJS library would also store library version to created instance of
because in my case, my analytics library I am working on, can only access that |
@Svarozic shouldn't it be the role of the analytics library to ask which version of the player is being used? Something like: class Analytics {
constructor(player, vjsVersion=videojs.VERSION){}
}
// OR
class AnalyticsAlternative {
constructor(player, params, vjsVersion=videojs.VERSION)
}
// Usage
const player = videojs('player');
new Analytics(player); // will have an implicit videojs version
new AnalyticsAlternative(player, {prop1: true, prop2: 'yes'}); // will have an implicit videojs version For comparison, here's what we do https://github.com/SRGSSR/pillarbox-web/blob/2785d8dcdefa10abc17464d53ad5479da3e48828/src/middleware/srgssr.js#L230-L235 |
@amtins this is something, what I am considering as possible solution to go with, to let consumer pass But because my analytics library was detecting that version automatically before, using only simple The solution with default value:
... can not work for me, because my library is published as independent package, without |
Perhaps another idea would be to provide a package.json {
"name": "analytics-plugin.js",
"version": "1.0.0",
"peerDependencies": {
"video.js": ">=7",
"analytics": ">=1"
}
} plugin import videojs from 'video.js';
import Analytics from 'Analytics.js';
class AnalyticsPlugin extends videojs.getPlugin('plugin') {
constructor(player, options) {
super(player, options);
this.instance = new Analytics(player, params);
}
} usage import videojs from 'video.js';
import 'analytics-plugin.js';
const player = videojs('my-player', {
plugins: {
analyticsPlugin: {
customerAccount: 'platinum',
prop1: true,
prop2: 'yes',
},
}
});
player.analyticsPlugin().instance.somePublicAPI() |
Those are great workarounds @amtins! I do think that having the version on the player instance would be useful. I've definitely wished for it previously when debugging in production. Since we add the player instance as a property of the player element, we can get the player instance easily in dev tools but getting |
@gkatsev |
@Svarozic could you reopen the issue, so we can link the PR to it? That way you'll be notified. |
Reopened and updated the issue title |
@Svarozic would you like to propose a PR for this feature? That would be a great contribution! 💯 |
I am using videojs via NPM https://videojs.com/getting-started/#install-via-npm and I cant find a way, how to access
videojs.VERSION
that would be normally available, if I would use videojs via CDN.Is it possible to get version of video JS from
Player
instance https://docs.videojs.com/player ?Steps to reproduce:
The text was updated successfully, but these errors were encountered: