AirenSoft / OvenPlayer

OvenPlayer is JavaScript-based LLHLS and WebRTC Player for OvenMediaEngine.
https://OvenMediaEngine.com/ovenplayer
MIT License
505 stars 125 forks source link

Access a player callback function that indicates that streaming has started #284

Closed dprisikar closed 2 years ago

dprisikar commented 2 years ago

Hi,

I am working on a sort of a waiting room, where listeners stay until streaming is started on the other end by the author; using OvenLiveKit for the author's input media.

I have also noticed that a listener needs to reload a page with the player to connect to an already started streaming, should the listener has already pressed the "play" button before the streaming starts.

How can I access a callback function that signals that the author has started streaming to the listeners who are already waiting for the streaming (i.e., they have pressed the "play" button before the author started streaming)?

Anyone's help would be very much appreciated!

IanMitchell77 commented 2 years ago

Not a particularly nice way but the player could keep trying to play every second or so when there is an error.

getroot commented 2 years ago

OvenMediaEngine's AdmissionWebhooks allows you to receive events with callback urls when a stream starts/stops.

https://airensoft.gitbook.io/ovenmediaengine/access-control/admission-webhooks

Or you could periodically poll streams information.

https://airensoft.gitbook.io/ovenmediaengine/rest-api/v1/virtualhost/application/stream

After this, it is the role of the application.

Like OvenSpace(https://space.ovenplayer.com/) (https://github.com/AirenSoft/OvenSpace), you can periodically poll your server for stream information, or, smarter, your server can push events over WebSockets to all users. Other than that, there are many ways.

dprisikar commented 2 years ago

@IanMitchell77 and @getroot, thank you for your inputs.

@getroot is there a simpler way to accomplish this?

Say, there has to be some callback (not sure if it is accessible through the API, though) that makes the Play button spin, while awaiting the media source. Maybe I can poll that?

Or, perhaps, one can access the incoming stream directly from the browser somehow?

getroot commented 2 years ago

Accessing OvenMediaEngine's API from the client side is incorrect. Anyone with access to OvenMediaEngine's API can change your server settings.

Only your web server uses OvenMediaEngine's API, and after that, it is your web server and your client's role.

If you are looking for a simpler way, it would be better to try playing infinitely in the player and get rid of the error message that appears in the player.

getroot commented 2 years ago

I have also noticed that a listener needs to reload a page with the player to connect to an already started streaming, should the listener has already pressed the "play" button before the streaming starts.

I don't quite understand the issue you are struggling with. OvenPlayer does not need to reload the page when starting playback. All you have to do is retry in the player. See demo.ovenplayer.com or space.ovenplayer.com.

If you thought that because of this you need to know when a stream starts, this deserves a bit more explanation.

dprisikar commented 2 years ago

Thank you for your comments, @getroot.

To explain the page reload part, here is a simple case.

A listener joins a podcast, run by the author. The listener is connected to the stream. The author stops broadcasting, say accidentally reloads her page. The listener gets cut off, and would need to refresh her page to be able to join the streaming again, after the page refresh on the author's end.

I hope I've managed to explain what I mean well 😀

getroot commented 2 years ago

Sorry but I only focus on the issues with OvenMediaEngine and OvenPlayer (that alone spends all my time), so I'll make one last comment.

Take a look at the code at demo.ovenplayer.com. demo.ovenplayer.com will automatically try to reconnect if the connection is suddenly disconnected.

dprisikar commented 2 years ago

@getroot of course, and thank you very much for your input. You, guys, have built an amazing product, and I hope that, perhaps, me asking questions and making comments here would help you in your further work 😊

dprisikar commented 2 years ago

Here is what worked for me:

var player = OvenPlayer.create('player_id', {
    "mute": false,
    "volume": 100,
    "sources": [{
        "type": "webrtc",
        "file": "wss://..."
    }]
});

player.on('error', (event) => {
      reloadPlayer();   
});

function reloadPlayer(){
    player.load( 
      sources = [{
        "type": "webrtc",
         "file": "wss://..."
    }] 
    );