Non-Drowsy Statistics

Stats. Don't worry. We're not dragging out your high school math teacher. We're talking about fun statistics! OK. Well, important ones at least.

Many people don’t realize that there's a whole lot of data about the status of WebRTC streams readily available and (this is the fun part) all it takes is a single JavaScript call.

What is this great, omniscient call, you ask; RTCRtpReceiver.getStats().

It returns a promise with an RTCStatsReport object which provides an enormous amount of information about your streams (both incoming and outgoing).

Let’s say you want to calculate the number of packets lost in a session and alert the user that they may be experiencing a bad viewing experience because of network issues. You simply need to dive into the RTCStatsReport and look at the RTCInboundRTPStreamStats. There you will find a packetsLost property which tracks (any guesses?) how much packet loss you are seeing over a period of time. If it becomes higher than let’s say 30%, you would alert your user. Convenient, right?

Since we integrated Red5 Pro with WebRTC, the same valuable stats are also accessible with our HTML5 Streaming SDK.

Once a WebRTC peer connection (either publisher or subscriber) has been properly established, you can access the underlying RTCPeerConnection using the getConnection() method on the publisher or subscriber instance. From there, you can use any of the APIs [call?] RTCPeerConnection provides to gather data you need.

As an example, our testbed publisher examples show bitrate and packet count. We are able to show this by:

  1. Accessing the RTCPeerConnection after the publisher has started a stream (link).
  2. Then accessing the data from getStats on an interval (link).

So there you have it. All the stats you need, no math needed! So what shall you do with this powerful tool? Let us know, but no matter what, we will not be held responsible for it.

Happy coding!

  • Share: