getAudioStats method
Retrieves real-time audio statistics for the participant.
- This method returns metrics related to the participant’s audio stream,
such as jitter, packet loss, bitrate, and round-trip time (RTT).
Returns the most recent sample and starts fetching the next one, so call
it periodically — from a timer, for example. The first call after the
participant joins returns
null.
Returns
-
A
List<dynamic>?containing audio stream statistics objects, ornullif stats are unavailable. Each object may include:-
jitter: Represents distortion in the audio stream. -
bitrate: The bitrate at which the audio stream is being transmitted. -
totalPackets: The total number of packets transmitted for the audio stream. -
packetsLost: The total number of packets lost during transmission. -
rtt: The round-trip time (RTT) in milliseconds, representing the time taken for the stream to travel from the server to the client. -
codec: The codec used for encoding the audio stream. -
network: The network type used to transmit the stream.
-
Notes
-
Each value is the last sample taken, not an average over the room.
-
If the reported
rttis consistently greater than 300 ms, it is recommended to use a server region closer to the participant for improved performance.
Example
// Fetch audio and video stats for a participant
final audioStats = widget.participant.getAudioStats();
final videoStats = widget.participant.getVideoStats();
if (audioStats != null && audioStats.isNotEmpty) {
final stats = audioStats.first;
print('Audio Bitrate: ${stats['bitrate']}');
print('Packet Loss: ${stats['packetsLost']}');
print('RTT: ${stats['rtt']} ms');
}
Implementation
List<dynamic>? getAudioStats() => _getAudioStats();