Stats for WebRTC

Sometimes you need a way to capture certain metrics related to a call. This may be helpful if you want to tailor the experience to your users or debug issues. Typical metrics of interest are audio/video bitrate, round trip time, total consumed bandwidth and packet loss. 100ms SDK provides this data via dedicated delegate callbacks found in HMSStatsObserver. These will be called with a fixed interval of one second after a room has been joined. You can get stats on a per track basis ( fun onRemoteAudioStats(audioStats: HMSRemoteAudioStats, hmsTrack: HMSTrack?, hmsPeer: HMSPeer?)) or as an overall summary (fun onRTCStats(rtcStats: HMSRTCStatsReport)).

To begin getting callbacks for statistics, call hmsSDK.addRtcStatsObserver(HMSStatsObserver) with your implementation of HMSStatsObserver.

💡 Note: Gathering stats takes several ms and can be a large operation if requested on a room with thousands of peers. Consider whether the additional load is necessary.

Here is the full list of callbacks:

/// This callback provides stats for a local audio track. fun onLocalAudioStats(audioStats: HMSLocalAudioStats, hmsTrack: HMSTrack?, hmsPeer: HMSPeer?) /// This callback provides stats for a local video track. fun onLocalVideoStats(videoStats: HMSLocalVideoStats, hmsTrack: HMSTrack?, hmsPeer: HMSPeer?) /// This callback provides stats for a remote audio track. fun onRemoteAudioStats(audioStats: HMSRemoteAudioStats, hmsTrack: HMSTrack?, hmsPeer: HMSPeer?) /// This callback provides stats for a remote video track. fun onRemoteVideoStats(videoStats: HMSRemoteVideoStats, hmsTrack: HMSTrack?, hmsPeer: HMSPeer?) /// This callback provides combined stats for the session. fun onRTCStats(rtcStats: HMSRTCStatsReport)

HMSRTCStatsReport

This class will contain the combined stats for the room.

class HMSRTCStats { // Total bytes sent in the current session. val bytesSent: Long // Total bytes received in the current session. val bytesReceived: Long // Total packets received in the current session. val packetsReceived: Long // Total packets lost in the current session. val packetsLost: Long // Total outgoing bitrate observed since previous report. val bitrateSent: Double // Total incoming bitrate observed since previous report in Kb/s. val bitrateReceived: Double // Average round trip time observed since previous report in seconds. val roundTripTime: Double } class HMSRTCStatsReport { // Combined audio + video values val combined: HMSRTCStats // Summary of all audio tracks val audio: HMSRTCStats // Summary of all video tracks val video: HMSRTCStats }

HMSLocalAudioStats

This class contains stats related to local audio track.

data class HMSLocalAudioStats( // Round trip time observed since previous report. val roundTripTime: Double?, // Total bytes sent by this track in the current session. val bytesSent: Long?, // Outgoing bitrate of this track observed since previous report in Kb/s. val bitrate: Double? ) : HMSStats.HMSLocalStats()

HMSLocalVideoStats

This class contains stats related to local video track.

data class HMSLocalVideoStats( // Round trip time observed since previous report. val roundTripTime: Double?, // Total bytes sent by this track in the current session. val bytesSent: Long?, // Outgoing bitrate of this track observed since previous report in Kb/s. val bitrate: Double?, // Resolution of video frames being sent. val resolution: HMSVideoResolution?, // Frame rate of video frames being sent (FPS). val frameRate: Double? ) : HMSStats.HMSLocalStats() data class HMSVideoResolution( var width: Int, var height: Int, )

HMSRemoteAudioStats

This class contains stats related to remote audio track.

data class HMSRemoteAudioStats( // Packet Jitter measured in seconds for this track. Calculated as defined in section 6.4.1. of RFC3550. val jitter: Double?, // Total bytes received by this track in the current session. val bytesReceived: Long?, // Incoming bitrate of this track observed since previous report in Kb/s. val bitrate: Double?, // Total packets received by this track in the current session. val packetsReceived: Long?, // Total packets lost by this track in the current session. val packetsLost: Int, ) : HMSStats.HMSRemoteStats()

HMSRemoteVideoStats

This class contains stats related to remote video track.

data class HMSRemoteVideoStats( // Packet Jitter measured in seconds for this track. Calculated as defined in section 6.4.1. of RFC3550. val jitter: Double?, // Total bytes received by this track in the current session. val bytesReceived: Long?, // Incoming bitrate of this track observed since previous report in Kb/s. val bitrate: Double?, // Total packets received by this track in the current session. val packetsReceived: Long?, // Total packets lost by this track in the current session. val packetsLost: Int? // Resolution of video frames being received. val resolution: HMSVideoResolution? // Frame rate of video frames being received (FPS). val frameRate: Double? ) : HMSStats.HMSRemoteStats()

Hierarchy

Here's the hierarchy for the sealed classes for stats

sealed class HMSStats { sealed class HMSLocalStats : HMSStats() sealed class HMSRemoteStats : HMSStats() }

Have a suggestion? Recommend changes ->

Was this helpful?

1234