Join multiple channels
Agora Video SDK enables you to simultaneously join multiple channels. This capability allows you to receive and publish audio and video streams across multiple channels concurrently.
Understand the tech
Video SDK's multi-channel functionality is based on two key components:
-
RtcConnection
The
RtcConnection
object identifies a connection. It contains the following information:- Channel name
- User ID of the local user
You create multiple
RtcConnection
objects, each with a different channel name and user ID. EachRtcConnection
instance can independently publish multiple audio streams and a single video stream. -
RtcEngineEx
The class contains methods tailored for interacting with a designated
RtcConnection
object.To join multiple channels, you call
joinChannelEx
method in theRtcEngineEx
class multiple times, using a differentRtcConnection
instance each time.
When joining multiple channels:
- Ensure that the user ID for each
RtcConnection
object is unique and nonzero. - Configure publishing and subscribing options for the
RtcConnection
object injoinChannelEx
.
- Pass the
IRtcEngineEventHandler
object to theeventHandler
parameter when calling thejoinChannelEx
method to receive multiple channel-related event notifications.
Prerequisites
Ensure that you have implemented the SDK quickstart in your project.
Implementation
This section explains how to join a second channel as a host after you have already joined the first channel.
-
Declare variables for
RtcEngineEx
andRtcConnection
objects. -
Initialize the engine instance.
-
Join the channel using a random user ID.
-
Listen for events in
rtcConnection2
and set up the remote video in theonUserJoined
callback.
Reference
This section contains content that completes the information on this page, or points you to documentation that explains other aspects to this product.
Sample project
Agora provides the JoinMultipleChannels open-source sample project for your reference. Download the project or view the source code for a more detailed example.