TypeError: attempted to get private field on non-instance
See original GitHub issueDescribe the bug Using the library in a Ionic/Vue application, with 2.7.2 as openplayerjs, results in that error, in console, which prevents from the player to switch to another source. Using 2.6 version works, but I need to use the latest version for some improvements released in 2.7.2.
To Reproduce Steps to reproduce the behavior:
- In a Ionic/Vue application, create a vue component which uses the OpenPlayerJS library
- The openplayerjs initialization works and the m3u8 source set from the
<video><source>tag works, but as soon as I try to set the player source to another stream, like:this.player.src = {src: src, type: "application/x-mpegURL"};it fails with the error in the title - It’s not clear, for me, from the documentation pointed from here what I have to change in my code to be compliant with 2.7+ version of the library, not being typescript expert is non trivial to find the solution.
Expected behavior When the source is set on an initialized player, it must change the source to the new one.
Desktop (please complete the following information):
- OS:Ubuntu Budgie 20.10
- Browser: Chrome
- Version: 90.0.4430.93 (Official Build) (64-bit)
Maybe a working example in the page linked for a 2.6 to 2.7 migration would help better understand how to integrate the library and not have this braking problem.
Thank you very much, Gabriele
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Why is "attempted to set private field on non-instance only ...
It seems that I can't use my init() method on this. foo which is declared in my vue data member, but I can...
Read more >TypeError: attempted to get private field on non-instance
After upgrading an external library, pdfjs-dist the following error occurs: Uncaught TypeError TypeError: attempted to get private field on ...
Read more >TypeScript: ECMAScript Private Fields for Hard Privacy in ...
In the constructor of the Friend class the private field ... throw new TypeError("attempted to get private field on non-instance"); } return ...
Read more >Private fields incompatible with JS Proxy · Issue #1969 - GitHub
The fundamental problem is not that the proxy is attempting to reference a private member; the data property is public. The problem occurs...
Read more >Why does a JavaScript class getter for a private field fail using ...
It nearly works, but the issue is that the key will be leaked by Object.getOwnPropertySymbols(new A()) , so it's not truly private. There...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Understood! Maybe this can be put in documentation if someone wants to use openplayerjs in a Vue.js application:
With 2.7 releases of openplayerjs, the private methods and properties are actually more private than before, this means that, with Vue.js 3, which observes *.vue template variables, by adding reactivity to them, the variable which is used to hold the OpenPlayerJS object is Proxied by Vue’s observers, so, the call to player’s methods, like play(), init(), pause(), etc. are not called on the player object directly, but are called by the reactivity Proxy in a way not compatible with 2.7+ versions of OpenplayerJS. The solution is to assign the OpenPlayerJS instantiation to a non-reactive (so un-Proxied) variable, to do so, Vue.js allows to declare $ variables (variables starting with $) which are not observed by the reactivity Proxy. Thus, going to the point, to use OpenPlayerJS in a Vue Application, you have to declare the object holder like:
And then use
$playerin other Vue methods, for example:Having declared the HTML template like, for example:
@gabrieletassoni if you can prepare a CodePen or similar where I can dig more into this error I’d appreciate it. I have the suspicion that it has to do with
this.playerdeclaration, because I’ve used it in other ways and I don’t see the error