TypeError: attempted to get private field on non-instance

See original GitHub issue

Describe 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:

  1. In a Ionic/Vue application, create a vue component which uses the OpenPlayerJS library
  2. 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
  3. 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:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
gabrieletassonicommented, May 4, 2021

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:

data() {
	return {
		$player: null
	};
}

And then use $player in other Vue methods, for example:

mounted() {
	this.$player = new OpenPlayerJS('player');
	this.$player.init();
}

Having declared the HTML template like, for example:

<template>
	<div class="block live players">
		<div class="video-wrapper">
			<video id="player" class="main op-player__media" controls playsInline autoPictureInPicture
				preload="metadata" height="360" :poster="`${currentURL}/assets/thumbnail-video.jpg`">
				<source :src="`${currentURL}/assets/placeholder.m3u8`" type="application/x-mpegURL" />
			</video>
		</div>
	</div>
</template>
1reaction
rafa8626commented, May 3, 2021

@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.player declaration, because I’ve used it in other ways and I don’t see the error

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found