The Agora Web SDK provides APIs for you to get the audio and video statistics reflecting the overall quality of a call. The statistics include:
Before proceeding, ensure that you have read the quickstart guides and implemented basic real-time audio and video functions in your project.
Call AgoraRTCClient.getRTCStats to get the statistics of the session. For the statistics description, see AgoraRTCStats.
The client
object in the following sample code is created by calling AgoraRTC.createClient
.
const stats = client.getRTCStats();
Call LocalAudioTrack.getStats to get the statistics of a local audio track, and call LocalVideoTrack.getStats to get the statistics of a local video track. For the statistics description, see LocalAudioTrackStats and LocalVideoTrackStats.
const audioTrackStats = localAudioTrack.getStats();
const videoTrackStats = localVideoTrack.getStats();
Call RemoteAudioTrack.getStats to get the statistics of a remote audio track, and call RemoteVideoTrack.getStats to get the statistics of a remote video track. For the statistics description, see RemoteAudioTrackStats and RemoteVideoTrackStats.
const audioTrackStats = remoteAudioTrack.getStats();
const videoTrackStats = remoteVideoTrack.getStats();
After the local user joins the channel, the SDK triggers the network-quality
callback once every two seconds to report the uplink and downlink network conditions of the local user.
downlinkNetworkQuality
: The downlink network quality.uplinkNetworkQuality
: The uplink network quality.Quality Rating Table
Rating | Description |
---|---|
0 | The network quality is unknown. |
1 | The network quality is excellent. |
2 | The network quality is good, but the bitrate may be slightly lower than optimal. |
3 | Users experience slightly impaired communication. |
4 | Users cannot communicate smoothly. |
5 | The network is so poor that users can barely communicate. |
6 | The network is down and users cannot communicate at all. |
client.on("network-quality", (stats) => {
console.log("downlinkNetworkQuality", stats.downlinkNetworkQuality);
console.log("uplinkNetworkQuality", stats.uplinkNetworkQuality);
});
The SDK reports exception events in the channel by triggering the exception
callback. Exceptions are not errors, but usually indicate quality issues. This callback also reports recovery from an exception.
code
: The event code.msg
: The event message.uid
: The uid of the user who experiences the exception or recovery event.client.on("exception", function(evt) {
console.log(evt.code, evt.msg, evt.uid);
})
Each exception event has a corresponding recovery event. See the table below for details.
All the above methods must be called after joining the channel.