WebRTC, HTML5, JavaScript
For example there is a WebRTC video call between users User1 and User2. Imagine User2 hits some mute button (which does something like localStream.getAudioTracks()[0].enabled=false). On client side of User1 there is now no audio, however video is still going (which is good).
I would like to detect if audio or video is not received anymore by User1 from User1 without any additional signaling. I cannot see any API to detect something like getBytesLoaded for audio or/and video tracks to detect the loss and show appropriate message. I also cannot find even a function to detect if audio or/and video was stopped.
Note: I don't think it is related to stop/pause events
Using the WebRTC getStats API, you can call the method getStats
in a peerConnection instance periodically , and pass a callback function that will be called with the stats object.
In that object you can find statistics about the current audioOutputLevel
, and if you watch the values returned when the the sender mutes the mic (disables the audioTrack), you'll see lower values.
Using the number of packets or the number of bytes will not provide very useful information, because WebRTC implements the Comfort Noise, and so you'll see many packets arriving.
To sum up, without sending any signalling information, the only way to do that is using stats, and you'll have to dig and find a pattern that works, because you won't find any state change.