Network Testing
Feature Overview
This document is not currently applicable to the Web platform.
ZEGOCLOUD provides network speed testing functionality, which can detect uplink and downlink network speeds before users publish/play streams, to determine the bitrate of audio and video streams suitable for publishing/playing under the current network environment.
When the uplink speed test results show a high packet loss rate, it is recommended to reduce the publishing bitrate by lowering the resolution or frame rate to ensure normal publishing; when the downlink speed test results show a high packet loss rate, it is recommended to use the Advanced Features - Set Video Encoding feature provided by the SDK to pull low-bitrate streams to ensure normal playing.
ZEGO recommends using the SDK's network speed testing feature in the following business scenarios:
-
In call scenarios, network quality assessment is required.
-
In education scenarios, pre-class network detection is required.
-
In live streaming scenarios, network connection speed testing is required.
The basic principle of network speed testing is shown in the following figure:

Prerequisites
Before implementing the network speed testing feature, ensure that:
- The ZEGO Express SDK has been integrated into your project and basic real-time audio and video functions have been implemented. For details, please refer to Quick Start - Integration and Quick Start - Implementation.
- A project has been created in the ZEGOCLOUD Console, and a valid AppID and AppSign have been obtained. For details, please refer to Console - Project Information.
Usage Steps
1 Listen to Speed Test Callbacks
Before starting the speed test, you can set up speed test-related callbacks first.
-
Under normal speed test circumstances, the onNetworkSpeedTestQualityUpdate callback is triggered when network speed quality updates.
-
When an error occurs during the speed test, the onNetworkSpeedTestError callback is triggered.
// Network speed test quality callback
ZegoExpressEngine.onNetworkSpeedTestQualityUpdate = (ZegoNetworkSpeedTestQuality quality, ZegoNetworkSpeedTestType type) {
};
// Network speed test error callback
ZegoExpressEngine.onNetworkSpeedTestError = (int errorCode, ZegoNetworkSpeedTestType type) {
};2 Start Speed Test
Create an instance of ZegoNetworkSpeedTestConfig for network speed test configuration, set whether to perform uplink and downlink speed tests and expected bitrates according to the actual situation, and call the startNetworkSpeedTest interface to start the network speed test.
After calling the startNetworkSpeedTest interface to start the speed test, the default support is speed testing for 30 seconds (if you need to adjust the duration, please contact ZEGO technical support to modify the dynamic configuration). The speed test will be forcibly terminated after timeout. If you need to continue the speed test, please call this interface again.
var videoConfig = await ZegoExpressEngine.instance.getVideoConfig();
// Perform uplink speed test, specify expected publishing bitrate
bool testUplink = true;
int expectedUplinkBitrate = videoConfig.bitrate;
// Perform downlink speed test, specify expected playing bitrate
bool testDownlink = true;
int expectedDownlinkBitrate = videoConfig.bitrate;
var config =ZegoNetworkSpeedTestConfig(testUplink, expectedUplinkBitrate, testDownlink, expectedDownlinkBitrate);
// Start speed test, default callback interval is 3 seconds
ZegoExpressEngine.instance.startNetworkSpeedTest(config);
// If you need to set the callback interval, you can refer to the following call (taking 1.5 seconds as an example)
ZegoExpressEngine.instance.startNetworkSpeedTest(config, interval: 1500);The speed test results will be returned in onNetworkSpeedTestQualityUpdate through ZegoNetworkSpeedTestQuality (Network Speed Test Quality). By analyzing the parameter values, you can determine whether the current network quality is good.
The parameters in ZegoNetworkSpeedTestQuality are as follows:
| Parameter | Description | Explanation |
|---|---|---|
| connectCost | Time spent connecting to the server, in milliseconds. | If the network connection is interrupted during the speed test, reconnection will be initiated automatically. This variable will be updated accordingly. The smaller the value, the better. |
| rtt | Network latency, in milliseconds. | Represents the time consumed between the SDK and the server round trip. The smaller the value, the better. |
| packetLostRate | Packet loss rate, in percentage. | The value range is 0.0 - 1.0. For example, 0.5 means that 5 out of every 10 data packets sent to the server may be lost on the way. |
| quality | Network quality | Represents the current network quality level. For details, please refer to ZegoStreamQualityLevel:
|
3 Stop Speed Test
Call the stopNetworkSpeedTest interface to stop the network speed test.
After stopping the speed test, you will no longer receive onNetworkSpeedTestQualityUpdate or onNetworkSpeedTestError callbacks.
ZegoExpressEngine.instance.stopNetworkSpeedTest();