Call Stats

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 HMSStatsListener. 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 ( onRemoteAudioStats) or as an overall summary (onRTCStats)

HMSStatsListener callbacks

Here is the full list of callbacks:

/// This callback provides stats for a local audio track. void onLocalAudioStats({required HMSLocalAudioStats hmsLocalAudioStats, required HMSLocalAudioTrack track, required HMSPeer peer}) /// This callback provides stats for a local video track with all the available layers. void onLocalVideoStats({required List<HMSLocalVideoStats> hmsLocalVideoStats, required HMSLocalVideoTrack track, required HMSPeer peer}) /// This callback provides stats for a remote audio track. void onRemoteAudioStats({required HMSRemoteAudioStats hmsRemoteAudioStats, required HMSRemoteAudioTrack track, required HMSPeer peer}) /// This callback provides stats for a remote video track. void onRemoteVideoStats({required HMSRemoteVideoStats hmsRemoteVideoStats, required HMSRemoteVideoTrack track, required HMSPeer peer}) /// This callback provides combined stats for the session. void onRTCStats({required HMSRTCStatsReport hmsrtcStatsReport})

To listen to these callbacks we will need to attach HMSStatsListener and override the above methods. Let's see how we can listen to these callbacks:

Implement HMSStatsListener in a Class

class StatsReport implements HMSStatsListener{}

Call addStatsListener

Call addStatsListener on the hmsSDK instance without which by default RTC Stats will not be sent to the app.

//hmsStatsListener is an instance of HMSStatsListener hmsSDK.addStatsListener(listener: hmsStatsListener);

Implement HMSStatsListener Methods

class StatsReport implements HMSStatsListener{ void onLocalAudioStats( {required HMSLocalAudioStats hmsLocalAudioStats, required HMSLocalAudioTrack track, required HMSPeer peer}) {} void onLocalVideoStats( {required List<HMSLocalVideoStats> hmsLocalVideoStats, required HMSLocalVideoTrack track, required HMSPeer peer}) {} void onRemoteAudioStats( {required HMSRemoteAudioStats hmsRemoteAudioStats, required HMSRemoteAudioTrack track, required HMSPeer peer}) {} void onRemoteVideoStats( {required HMSRemoteVideoStats hmsRemoteVideoStats, required HMSRemoteVideoTrack track, required HMSPeer peer}) {} void onRTCStats({required HMSRTCStatsReport hmsrtcStatsReport}) {} }

Remove the listener when not required

To stop listening to updates or while leaving the room we will need to remove this listener as:

//hmsStatsListener is an instance of HMSStatsListener which we passed in addStatsListener hmsSDK.removeStatsListener(listener: hmsStatsListener);

Supplementary bytes

HMSRTCStatsReport

This class will contain the combined stats for the room.

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

HMSLocalAudioStats

This class contains stats related to the local audio track.

class HMSLocalAudioStats { // Round trip time observed since the previous report double roundTripTime; // Total bytes sent by this track in the current session int bytesSent; // Outgoing bitrate of this track observed since the previous report in Kb/s double bitrate; }

HMSLocalVideoStats

This class contains stats related to local video track.

class HMSLocalVideoStats { // Round trip time observed since the previous report. double roundTripTime; // Total bytes sent by this track in the current session. int bytesSent; // Outgoing bitrate of this track observed since the previous report in Kb/s. double bitrate; // Resolution of video frames being sent. double frameRate; // Frame rate of video frames being sent (FPS). HMSResolution resolution; ///Reason for quality limitations HMSQualityLimitationReasons? hmsQualityLimitationReasons; ///Simulcast Layer HMSSimulcastLayer? hmsLayer; }

HMSRemoteAudioStats

This class contains stats related to the remote audio track.

class HMSRemoteAudioStats { // Packet Jitter measured in seconds for this track. Calculated as defined in section 6.4.1. of RFC3550. double jitter; // Total bytes received by this track in the current session. int bytesReceived; // Incoming bitrate of this track observed since the previous report in Kb/s. double bitrate; // Total packets received by this track in the current session. int packetsReceived; // Total packets lost by this track in the current session. int packetsLost; }

HMSRemoteVideoStats

This class contains stats related to the remote video track.

class HMSRemoteVideoStats { // Packet Jitter measured in seconds for this track. Calculated as defined in section 6.4.1. of RFC3550. double jitter; // Total bytes received by this track in the current session. int bytesReceived; // Incoming bitrate of this track observed since the previous report in Kb/s. double bitrate; // Total packets received by this track in the current session. int packetsReceived; // Total packets lost by this track in the current session. int packetsLost; // Resolution of video frames being received. HMSResolution resolution; // Frame rate of video frames being received (FPS). double frameRate; }

Have a suggestion? Recommend changes ->

Was this helpful?

1234