I'm trying to get general stats for my WebRTC application, including received bytes, packet loss, delay, etc. I wrote a small function to check if I can access this information:
func getInboundRTPStreamStats(peerConnection *webrtc.PeerConnection) {
stats := peerConnection.GetStats()
for k, stat := range stats {
log.Infof("Stats %v :: %v\n", k, stats)
if inboundStat, ok := stat.(webrtc.InboundRTPStreamStats); ok {
log.Infof("Bytes Received: %d, Packets Lost: %d\n",
inboundStat.BytesReceived, inboundStat.PacketsLost)
}
}
}
I run it inside peerConnection.OnTrack:
peerConnection.OnTrack(func(t *webrtc.TrackRemote, receiver *webrtc.RTPReceiver) {
// ...
go func() {
for {
time.Sleep(1 * time.Second)
getInboundRTPStreamStats(peerConnection)
}
}()
// ...
}
While I do receive some stats, I am not getting webrtc.InboundRTPStreamStats
. I wonder what the issue might be.
I would appreciate any help on this!
I tried to call peerConnection.GetStats() and expected to see InboundRTPStreamStats to be available. But it is not. I am not sure what could be the reason.