onYouTubeIframeAPIReady - PeerTube equivalent function?

Hi all,

I am trying to add peertube support to our CMS. It currently supports YouTube so trying to adapt their approach to embedding youtube to peertube. Their code dynamically adds the player script to the page rather than having it present in the header statically. They use jquery to add a script tag and point the « src » attribute at the cdn. Once fully loaded the script then creates a « new YouTubePlayer() ». To do this they implement a callback function onYouTubeIframeAPIReady. I can’t seem to find an similar callback for the peertube api?

I have tried different ways to accommodate this but my JavaScript skills are not strong enough :frowning: Waiting for the script to be added to the header alone doesn’t work. (async:false,defer:false) nor does the jquery « .ready » functions after the script is added. I just get « PeerTubePlayer undefiend »

Any help appreciated.

Hello,

Did you follow https://docs.joinpeertube.org/api-embed-player?id=quick-start?

Yes, I did. I got it working by using a timeout of 3 seconds to allow the script to complete before calling « new » but its not ideal. It would be better if the script from the cdn call a predefined method in my script once it was fully loaded.

I couldn’t find an equivalent call back in the docs. Maybe I missed it?

                onYouTubeIframeAPIReady = function () {
                    ' set up youtube player
                };

Versus:

   setTimeout(function(){
                self.player = new PeerTubePlayer(document.querySelector('#video-player' + self.slide.id));

Okay thanks I think I understood. But no we don’t have such event at the end of our script: https://github.com/Chocobozzz/PeerTube/blob/develop/client/src/standalone/player/player.ts#L231

However it seems to me that’s an old way of beeing notified when the API is fully loaded. IMHO, it should be the job of the script that asynchronously loads the API, that should notify you when it’s done using the load listener :thinking:

yeah, I agree it is weird. If the feature is deemed worth looking at, using a load listener is better. Otherwise there is this global function hanging around.