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:
-
RtcConnectionThe
RtcConnectionobject identifies a connection. It contains the following information:- Channel name
- User ID of the local user
You create multiple
RtcConnectionobjects, each with a different channel name and user ID. EachRtcConnectioninstance can independently publish multiple audio streams and a single video stream. -
RtcEngineExThe class contains methods tailored for interacting with a designated
RtcConnectionobject.To join multiple channels, you call
joinChannelExmethod in theRtcEngineExclass multiple times, using a differentRtcConnectioninstance each time.
When joining multiple channels:
- Ensure that the user ID for each
RtcConnectionobject is unique and nonzero. - Configure publishing and subscribing options for the
RtcConnectionobject injoinChannelEx. - Pass the
IRtcEngineEventHandlerobject to theeventHandlerparameter when calling thejoinChannelExmethod to receive multiple channel-related event notifications.
Prerequisites
Ensure that you have implemented the SDK quickstart in your project.
Implementation
To implement multi-channel functionality, set up each channel as follows:
-
Declare variables for
RtcEngineExandRtcConnectionobjects. -
Initialize the engine instance.
-
Join the channel using a random user ID.
-
Listen for events in
rtcConnection2and set up the remote video in theonUserJoinedcallback.
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.