getNetworkStats()

getNetworkStats()

Compatibility:
Prebuilt
Custom

Returns the latest stats representing the current network, calculated from the WebRTC stats. These statistics are updated approximately once every two seconds. You can poll the getNetworkStats() method to continually read the current network performance.

Return type

Returns a Promise that resolves to an object with a set of the latest calculated stats, some overall call stats, and some high level assessments of the current overall network health.

If, for a given two second period, a value can not be determined, it will be set to null. This most commonly occurs for packetLoss calculations due to the values it relies upon being missing or stale, or media not being transmitted. For instance, if you join a call with audio and video off, your bitrates will be 0 and packetLoss will be null because it is unknown.

  • networkState: 'good'|'warning'|'bad'|'unknown'

    an assessment of the current network quality. The threshold value is calculated from network stats averaged over an approximately 30-second rolling window. Calculations are based on send/recv packet loss, round trip times, and availableOutgoingBitrate. In prebuilt, we lower the bandwidth used for the call when the network quality drops to warning, and we turn off the local camera when the network quality drops to bad.

  • networkStateReasons:

    an array of reasons for the current network state. Possible values are: 'sendPacketLoss', 'recvPacketLoss', 'roundTripTime', 'availableOutgoingBitrate'. If the networkState is 'good' or 'unknown', this field will be an empty array.

  • averageNetworkRoundTripTime: average round trip time over the course of the call.

  • worstAudioRecvPacketLoss: highest audioRecvPacketLoss number seen over a reporting interval during the call

  • worstAudioSendPacketLoss: highest audioSendPacketLoss number seen over a reporting interval during the call

  • worstVideoRecvPacketLoss: highest videoRecvPacketLoss number seen over a reporting interval during the call

  • worstVideoSendPacketLoss: highest videoSendPacketLoss number seen over a reporting interval during the call

  • worstVideoRecvJitter: highest videoRecvJitter value seen over a reporting interval during the call

  • worstVideoSendJitter: highest videoSendJitter value seen over a reporting interval during the call

  • worstAudioRecvJitter: highest audioRecvJitter value seen over a reporting interval during the call

  • worstAudioSendJitter: highest audioSendJitter value seen over a reporting interval during the call

  • threshold: [DEPRECATED in 0.77.0. Use networkState instead]

    'good'|'low'|'very-low', an assessment of the current network quality. The threshold value is calculated from network stats averaged over an approximately 30-second rolling window. In prebuilt, we lower the bandwidth used for the call when the network quality drops to low, and we turn off the local camera when the network quality drops to very-low.

  • quality: [DEPRECATED in 0.77.0]

    a subjective calculation of the current network quality on a scale of 1-100, suitable for display in a user interface.

  • latest: a collection of statistics from the most recent reporting interval, which occurs approximately once every two seconds. Below are the keys and descriptions of the values in the latest object:

KeyDescription
timestampa unix timestamp (seconds since the epoch), set to when the latest was calculated
recvBitsPerSecondtotal data received in the reporting interval from video and/or audio in bits per second
sendBitsPerSecondtotal data sent in the reporting interval from video and/or audio in bits per second
networkRoundTripTimeaverage latest round trip time reported from all connections
audioRecvBitsPerSecondtotal payload data from audio received in the reporting interval in bits per second
audioRecvPacketLossestimated percentage of packets lost from incoming audio over the reporting interval
audioSendBitsPerSecondtotal payload data from audio sent in the reporting interval in bits per second
audioSendPacketLossestimated percentage of packets lost from the audio being sent over the reporting interval
availableOutgoingBitrateaverage latest available outgoing bitrate reported from all connections
videoRecvBitsPerSecondtotal payload data from video received in the reporting interval in bits per second
videoRecvPacketLossestimated percentage of packets lost from incoming video over the reporting interval
videoSendBitsPerSecondtotal payload data from video sent in the reporting interval in bits per second
videoSendPacketLossestimated percentage of packets lost from the video being sent over the reporting interval
totalSendPacketLossestimated overall percentage of packets lost from the audio and video being sent over the reporting interval
totalRecvPacketLossestimated overall percentage of packets lost from the received audio and video over the reporting interval
videoRecvJitteraverage jitter across inbound video streams over the reporting interval
videoSendJitteraverage jitter across outbound video streams over the reporting interval
audioRecvJitteraverage jitter across inbound audio streams over the reporting interval
audioSendJitteraverage jitter across outbound audio streams over the reporting interval

Firefox users:

The Firefox browser does not provide adequate information to calculate send-side packet loss or jitter for audio and therefore audioSendPacketLoss and audioSendJitter will always be null. worstAudioSendJitter will report as 0. Firefox also does not provide adequate information to calculate availableOutgoingBitrate, networkRoundTripTime, or averageNetworkRoundTripTime.

Sample response

{
"networkState": "bad",
"networkStateReasons": [
"sendPacketLoss",
"recvPacketLoss"
],
"threshold": "good",
"quality": 37,
"stats": {
"averageNetworkRoundTripTime": 0.01992261904761905,
"latest": {
"audioRecvBitsPerSecond": 23050.048937297845,
"audioRecvJitter": 0.026,
"audioRecvPacketLoss": 0.15053763440860216,
"audioSendBitsPerSecond": 30177.83704675053,
"audioSendJitter": null,
"audioSendPacketLoss": null,
"availableOutgoingBitrate": 2889866,
"networkRoundTripTime": 0.02,
"recvBitsPerSecond": 1700344.1895481267,
"sendBitsPerSecond": 1724499.7493844875,
"timestamp": 1743011906315,
"totalRecvPacketLoss": 0.11670020120724346,
"totalSendPacketLoss": 0.08984375,
"videoRecvBitsPerSecond": 1567291.2594309496,
"videoRecvJitter": 0.036,
"videoRecvPacketLoss": 0.10891089108910891,
"videoSendBitsPerSecond": 1589251.349980054,
"videoSendJitter": 0.008922,
"videoSendPacketLoss": 0.08984375
},
"worstAudioRecvJitter": 0.026,
"worstAudioRecvPacketLoss": 0.23232323232323232,
"worstAudioSendJitter": 0.003166,
"worstAudioSendPacketLoss": 0.1953125,
"worstVideoRecvJitter": 0.036,
"worstVideoRecvPacketLoss": 0.10891089108910891,
"worstVideoSendJitter": 0.014355,
"worstVideoSendPacketLoss": 0.13671875
}
}

getNetworkStats() in action

We display network stats outside of the Daily iframe in our Daily Prebuilt demo: