Reputation: 71
I’ve been looking for a simple answer for quite a while now. I searched through so many websites and examples and I still dont understand how the getStats() can provide the data I am looking for. Unfortunately, this stuff is still (!) not well documented.
I simply want to read data like - packetloss - bitsReceived - bitsSent - frameRate
I am quite new to WebRTC so please forgive me. I was already able to look intro chrome’s webrtc internals.
Let’s say I have my object
peerConnection
How can I get now these numbers? For example, I am able to read the connection status:
peerConnection.IceConnectionState
and this just works “out of the box” and I see the status of the connection.
When I logged the following:
console.log(peerConnection.getStats());
Then I got some strange object I could not read it at all and didn’t know how to use it, either.
Then I read somewhere that I have to pass in the video track (for example) so that getStats() knows what object I am looking the statistics of. I did something like:
track = stream.getVideoTracks()[0]; console.log(peerConnection.getStats(track));
It again returned an object, but another one this time. Again, no clue what to do with it.
How hard can it be to measure the other data from getStats()? Can anyone please give me a very simple example starting with the object peerConnection? It is really frustrating...:-/
Upvotes: 0
Views: 3939
Reputation: 637
RTCStatsReport
object is not print directly because it is a map object, and try it:
peerConnection.getStats().then(stats => {
console.log([...stats.entries()]);
});
Upvotes: 0
Reputation: 17305
the sample at https://webrtc.github.io/samples/src/content/peerconnection/constraints/ has a bunch of code related to getStats, dumping the whole resulting object. The getStats method is not synchronous and returns a Promise which resolves with a Map object. You can then iterate that map object with a forEach loop and look for the information you want.
The different types of stats reports (check the type property) and their members are described in the specification.
Upvotes: 1