This topic describes how to test network quality before a call.
Feature introduction
The ARTC SDK supports testing local network quality before joining a channel to identify potential network problems and resolve them in advance. This helps prevent issues, such as stuttering, frame drops, and audio interruptions, ensuring stability and smoothness of real-time voice and video calls.
Sample code
Android: Android/ARTCExample/AdvancedUsage/src/main/java/com/aliyun/artc/api/advancedusage/PreJoinChannelTest/PreJoinChannelTestActivity.java
iOS: iOS/ARTCExample/AdvancedUsage/PreJoinChannelTest/PreJoinChannelTestVC.swift
HarmonyOS:Harmony/ARTCExample/entry/src/main/ets/pages/advancedusage/PreJoinChannelTestPage.ets
How it works
Taking the iOS platform as an example, the ARTC SDK provides the startLastmileDetect method to detect local network quality before joining a channel, and returns network quality scores and statistics. The procedure is as follows:
Before joining a channel, call
startLastmileDetectto initiate a network quality test. Configure the testing parameters inAliRtcNetworkQualityProbeConfig, including the target for testing and the expected maximum bitrate.The SDK triggers the following callbacks:
onLastmileDetectResultWithQuality: Triggered 2 seconds afterstartLastmileDetectis called. It returns scores of the upstream and downstream network, reflecting a subjective assessment.onLastmileDetectResultWithBandWidth: Triggered 30 seconds afterstartLastmileDetectis called. It returns real-time data on network conditions, including packet loss rate, network jitter, and available bandwidth, reflecting an objective assessment.
After you obtain the network quality statistics, call
stopLastmileDetectto stop the local network quality test.
Code examples
Initiate a network quality test
Android
Call the startNetworkQualityProbeTest operation:
public abstract int startNetworkQualityProbeTest(AlirtcNetworkQualityProbeConfig config);iOS
Call the startLastmileDetect operation:
- (int)startLastmileDetect:(AliRtcNetworkQualityProbeConfig *_Nonnull)config;Windows
AliRtcNetworkProbeConfig config;
config.probeUplink = true; // Test the upstream network
config.probeDownlink = true; // Test the downstream network
rtcEngine.startLastmileDetect(config);Receive callback messages
Android
onNetworkQualityProbeTest: triggered about 3 seconds after the test starts, providing initial insights into the network quality.
onNetworkQualityProbeTestResult: triggered about 30 seconds after the test starts, providing details of the network quality.
public void onNetworkQualityProbeTest(AliRtcNetworkQuality quality){}
public void onNetworkQualityProbeTestResult(int code, AliRtcEngine.AlirtcNetworkQualityProbeResult result){}iOS
onLastmileDetectResultWithQuality: triggered about 2 seconds after the test starts, providing initial insights into the network quality.
onLastmileDetectResultWithBandWidth: triggered about 30 seconds after the test starts, providing details of the network quality.
- (void)onLastmileDetectResultWithQuality:(AliRtcNetworkQuality)networkQuality;
- (void)onLastmileDetectResultWithBandWidth:(int)code result:(AliRtcNetworkQualityProbeResult* _Nonnull)result;Windows
// Handle network quality testing callback (replace onNetworkQualityChanged)
void OnLastmileDetectResultWithQuality(AliEngineNetworkQuality networkQuality) override {
std::string message = getNetworkQualityString(networkQuality);
networkTestResultText += "Network testing quality: " + message + "\n";
std::cout << "=== Network quality testing callback ===" << std::endl;
std::cout << networkTestResultText << std::endl;
}
// Handle lastmile network detection result callback
void onLastmileDetectResultWithBandWidth(int code,
const AliRtcNetworkProbeResult& result) override {
std::string message = buildNetworkTestResultMessage(code, result);
networkTestResultText += message + "\n";
std::cout << "=== Lastmile detection result callback ===" << std::endl;
std::cout << networkTestResultText << std::endl;
}Stop network quality detection
Android
Call the stopNetworkQualityProbeTest operation:
public abstract int stopNetworkQualityProbeTest();iOS
Call the stopLastmileDetect operation:
- (int)stopLastmileDetect;Windows
rtcEngine.stopLastmileDetect();