To check if the uplink network condition is good enough to support the audio bitrate or target bitrate of the chosen video profile, you can conduct a last-mile network quality test before joining the channel.
This function particularly applies to scenarios which have high requirements on the network quality.
Before conducting the last-mile test, ensure that you have implemented the basic real-time communication functions in your project. For details, see the following documents:
Call the StartLastmileProbeTest
method before joining a channel to get the uplink and downlink last-mile network statistics, including the bandwidth, packet loss, jitter, and round-trip time (RTT).
Once this method is enabled, the SDK triggers the following callbacks:
OnLastmileQualityHandler
: Triggered 2 seconds after the StartLastmileProbeTest
method is called. This callback rates the network conditions with a score and is more closely linked to the user experience.OnLastmileProbeResultHandler
: Triggered 30 seconds after the StartLastmileProbeTest
method is called. This callback returns the real-time statistics of the network conditions and is more objective.Call the StopLastmileProbeTest
method to stop the last-mile network probe test.
Refer to the following diagram to implement the last-mile test in your project.
Refer to the following code to implement the last-mile test in your project.
// Registers the callback events.
// Triggered 2 seconds after starting the last-mile test.
void OnLastmileQualityHandler(int quality)
{
}
// Triggered 30 seconds after starting the last-mile test.
void OnLastmileProbeResultHandler(LastmileProbeResult result)
{
// (1) Stops the test. Agora recommends not calling any other API method before the test ends.
mRtcEngine.StopLastmileProbeTest();
}
mRtcEngine.OnLastmileQuality = OnLastmileQualityHandler;
mRtcEngine.OnLastmileProbeResult = OnLastmileProbeResultHandler;
// Configures a LastmileProbeConfig instance.
LastmileProbeConfig config = new LastmileProbeConfig();
// Probes the uplink network quality.
config.probeUplink = true;
// Probes the downlink network quality.
config.probeDownlink = true;
// The expected uplink bitrate (bps). The value range is [100000, 5000000].
config.expectedUplinkBitrate = 100000;
// The expected downlink bitrate (bps). The value range is [100000, 5000000].
config.expectedDownlinkBitrate = 100000;
// Starts the last-mile network test before joining the channel.
mRtcEngine.StartLastmileProbeTest(config);
// (2) Stops the test in an alternate place. Agora recommends not calling any other API method before the test ends.
mRtcEngine.StopLastmileProbeTest();
OnLastmileQualityHandler
callback may return UNKNOWN
the first time it is triggered. Subsequent callbacks will return the test results.