Eyevinn / webrtc-player

WebRTC (recvonly) player
MIT License
87 stars 18 forks source link

[docs] Best approach to detecting loading and start events #47

Open nigelsim opened 1 year ago

nigelsim commented 1 year ago

I'm quite new to WebRTC, so I'm trying to understand the proper way to detect all of the main state transitions, so I can keep the user informed of what is happening.

This is my rough, reverse engineered understanding of the main states, and where the existing events are emitted.

My question is, how should I detect that the video stream is about to start? Should emit events from webrtc-player, or should I be listening to the video element?

Basically, I want to show a loading elements, and bring up messages if things are taking a long time.

Once I've got a good understanding I'm happy to update the main readme file to reflect this.

bwallberg commented 1 year ago

Hi @nigelsim!

The most straightforward way to detect anything related to the playback of the video stream itself is to listen to the video element, it will emit events such as canplaythrough once it's ready to play and waiting if it's buffering ( you can read more about it here: https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement ).

A simpler, but untested, solution might be to use our https://github.com/Eyevinn/media-event-filter but I haven't tested that with WebRTC yet.

That being said there are cases, such as startup, where a combination of listening to PeerConnection and the video element would be more suitable. Eg. emit a loading event as soon as the SDP exchange is initiating and then emit a loaded event when the video element emits canplaythrough ( a bit simplified but that's the gist of it ).

We'd like to implement something like that in the player but unfortunately we don't currently have a timeline for that.