Unstable network affects the audio and video quality in a video call or interactive live video streaming. To ensure smooth communication under poor network conditions, Agora supports video stream fallback. When the network condition deteriorates, the SDK automatically switches from the high-quality video stream to the low-quality video stream, or disables the video to ensure the audio quality under extremely poor network conditions.
Before proceeding, ensure that you have implemented interactive live video streaming or a video call in your project. See Start Live Interactive Video Streaming or Start a Call for details.
Follow these steps to enable video stream fallback:
Call enableDualStreamMode
to enable dual-stream mode for the senders.
Call Client.setStreamFallbackOption
to set the stream fallback option for the receivers.
fallbackType
as 1
: Automatically subscribe to the low-quality video stream under poor network conditions.fallbackType
as 2
: Subscribe to the low-quality video stream when the network conditions worsen, and subscribe to audio only when the conditions become too poor to support video transmission.You can monitor the switch between the audio-and-video stream and the audio-only stream by the Client.on("stream-fallback")
callback; monitor the switch between the low-quality video stream and high-quality video stream by the Client.on("stream-type-changed")
callback.
// Enable dual-stream mode for the sender.
client.enableDualStream(function () {
console.log("Enable dual stream success!");
}, function (err) {
console.log(err);
});
// Configuration for the receiver. When the network condition is poor, receive audio only.
client.setStreamFallbackOption(remoteStream, 2);
Agora does not recommend using the track methods (addTrack/removeTrack/replaceTrack) on dual streams, which may cause different performance in the high-quality and low-quality video streams.
The following scenarios do not support dual-stream mode: