Unstable network affects the audio and video quality in a video call or a live broadcast. To ensure smooth communication under poor network conditions, Agora supports media 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 read the quickstart guides and implemented basic real-time audio and video functions in your project.
Follow these steps to enable video stream fallback:
AgoraRTCClient.enableDualStream
for all the senders in the channel to enable dual-stream mode.AgoraRTCClient.setStreamFallbackOption
to set the stream fallback option for all the receivers in the channel: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.Alternatively, after enabling dual-stream mode, you can call AgoraRTCClient.setRemoteVideoStreamType
and set streamType
as 1
for the receivers to only subscribe to the low-quality stream under any conditions.
You can monitor the switch between the audio-and-video stream and the audio-only stream by the AgoraRTCClient.on("stream-fallback")
callback; monitor the switch between the low-quality video stream and high-quality video stream by the AgoraRTCClient.on("stream-type-changed")
callback.
In the following sample code, the client
object is created by calling AgoraRTC.createClient
, and the remoteStream
object is obtained in the stream-added
event.
// Enable dual-stream mode.
client.enableDualStream().then(() => {
console.log("Enable dual stream success!")
}).catch(err => {
console,log(err)
});
// Configuration for the receivers. 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.
client.setStreamFallbackOption(remoteStream, 2);
// Configuration for the receivers. Subscribe to the low-quality stream under any conditions.
client.setRemoteVideoStreamType(remoteStream, 1);
AgoraRTCClient.enableDualStreamMode
AgoraRTCClient.setStreamFallbackOption
AgoraRTCClient.setRemoteVideoStreamType
enableDualStream
does not apply to the following scenarios:createCustomVideoTrack
.setLowStreamParameter
on iOS Safari, the browser does not support setting LowStreamParameter.bitrate
. The resolution of the low-quality stream must be proportional to the resolution of the high-quality stream.setRemoteVideoStreamType
, dual streams may not be fully compatible with the following web browsers: