logo
On this page

Network Speed Testing

2024-01-02

Overview

ZEGO provides network speed testing functionality to detect uplink and downlink network speeds before users publish/play streams, and determine what bitrate of audio and video streams is 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 use methods such as lowering the resolution or lowering the frame rate to reduce the publishing stream bitrate to ensure normal publishing; when the downlink speed test results show a high packet loss rate, it is recommended to use the Video Advanced - Set Video Encoding Method function provided by the SDK to play low-bitrate streams to ensure normal playing.

When the following situations occur in the developer's business, ZEGO recommends using the SDK's network speed testing function:

  • In call scenarios, network quality assessment needs to be performed.

  • In education scenarios, pre-class network detection needs to be performed.

  • In live streaming scenarios, network connection speed testing needs to be performed.

The basic principle of network speed testing is shown in the following figure:

Prerequisites

Before implementing the network speed testing functionality, ensure:

Usage Steps

1 Listen to Speed Test Callbacks

Before starting the speed test, you can set up speed test related callbacks first.

// Network speed test quality callback
ZegoExpressEngine.instance().on('networkSpeedTestQualityUpdate', (quality, type) {}

// Network speed test error callback
ZegoExpressEngine.instance().on('networkSpeedTestError', (errorCode, type) {}

2 Start Speed Test

Create an instance of ZegoNetworkSpeedTestConfig network speed test configuration, set whether to perform uplink and downlink speed tests and expected bitrate according to the actual situation, and call the startNetworkSpeedTest interface to start network speed testing.

Note

After calling the startNetworkSpeedTest interface to start speed testing, it supports speed testing for 30 seconds by default (if you need to adjust the duration, please contact ZEGOCLOUD Technical Support to modify the dynamic configuration). After the timeout, the speed test will be forcibly ended. If you need to continue speed testing, please call this interface again.

let config =new ZegoNetworkSpeedTestConfig();

// Perform uplink speed test, specify expected publishing stream bitrate
config.testUplink = true;
config.expectedUplinkBitrate = ZegoExpressEngine.instance().getVideoConfig().bitrate;

// Perform downlink speed test, specify expected playing stream bitrate
config.testDownlink = true;
config.expectedDownlinkBitrate = ZegoExpressEngine.instance().getVideoConfig().bitrate;

// 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, 1500);

The speed test results will be returned in the network speed test quality ZegoNetworkSpeedTestQuality in networkSpeedTestQualityUpdate. By analyzing the parameter values, you can know whether the current network quality is good.

The parameters in ZegoNetworkSpeedTestQuality are as follows:

ParameterDescriptionExplanation
connectCostTime to connect to server, in milliseconds.If the network connection is disconnected during the speed test, it will automatically reconnect. This variable will be updated accordingly. The smaller the value, the better.
rttNetwork latency, in milliseconds.Represents the time consumed between the SDK and the server round trip. The smaller the value, the better.
packetLostRatePacket loss rate, in percentage.The value range is 0.0 - 1.0. For example, 0.5 means that out of every 10 packets sent to the server, 5 may be lost on the way.
qualityNetwork qualityRepresents the current network quality level. For details, please refer to ZegoStreamQualityLevel:
  • Excellent: Quality is excellent
  • Good: Quality is good
  • Medium: Quality is normal
  • Bad: Quality is poor
  • Die: Quality is abnormal
  • Unknown: Quality is unknown

3 Stop Speed Test

Call the stopNetworkSpeedTest interface to stop network speed testing.

After stopping the speed test, you will no longer receive networkSpeedTestQualityUpdate or networkSpeedTestError callbacks.

ZegoExpressEngine.instance().stopNetworkSpeedTest();

Previous

Call Quality Monitoring

Next

Multi-Source Capture

On this page

Back to top