# Join multiple channels (/en/realtime-media/video/build/join-and-manage-channels/join-multiple-channels/windows)

> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).

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 [#understand-the-tech-3]

    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. Each `RtcConnection` instance can independently publish multiple audio streams and a single video stream.

    * `IRtcEngineEx`

      The class contains methods tailored for interacting with a designated `RtcConnection` object.

      To join multiple channels, you call `joinChannelEx` method in the `IRtcEngineEx` class multiple times, using a different `RtcConnection` 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 in `joinChannelEx`.

    * Pass the `IRtcEngineEventHandler` object to the `eventHandler` parameter when calling the `joinChannelEx` method to receive multiple channel-related event notifications.

    ## Prerequisites [#prerequisites-3]

    Ensure that you have implemented the [SDK quickstart](/en/realtime-media/video/get-started-sdk) in your project.

    ## Implementation [#implementation-3]

    This section explains how to join a second channel as a host after you have already joined the first channel.

    1. Define a connection and join the channel using a random user ID.

       ```cpp
       agora::rtc::ChannelMediaOptions options2;
       options2.autoSubscribeAudio = false;
       options2.autoSubscribeVideo = false;
       options2.publishAudioTrack = false;
       options2.publishCameraTrack = false;
       options2.publishSecondaryCameraTrack = true;
       options2.clientRoleType = CLIENT_ROLE_BROADCASTER;
       // Define the connection
       connection.localUid = generateUid();
       connection.channelId = szChannelId.data();
       // Join the channel
       int ret = m_rtcEngine->joinChannelEx(APP_TOKEN, connection, options2, &m_camera2EventHandler);
       ```

    2. Listen for the `onUserJoined` callback and set up the remote video.

       ```cpp
       // Listen for the onUserJoined callback
       void CAGEngineEventHandler::onUserJoined(uid_t uid, int elapsed) {
         LPAGE_USER_JOINED lpData = new AGE_USER_JOINED;

         lpData->uid = uid;
         lpData->elapsed = elapsed;

         if (m_hMainWnd != NULL)
           ::PostMessage(m_hMainWnd, WM_MSGID(EID_USER_JOINED), (WPARAM)lpData, 0);
       }
       ```

    3. Set up the remote video

       ```cpp
       VideoCanvas canvas;
       canvas.renderMode = RENDER_MODE_FIT;
       canvas.uid = 123;
       canvas.view = videoWnd.GetSafeHwnd();

       connection.localUid = 123;
       connection.channelId = "channel123";

       // Set up the remote video
       rtcEngine->setupRemoteVideoEx(canvas, connection);
       ```

    ## Reference [#reference-3]

    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 [#sample-project-3]

    Agora provides the [MultiChannels](https://github.com/AgoraIO/API-Examples/tree/main/windows/APIExample/APIExample/Advanced/MultiChannel) open-source sample project for your reference. Download the project or view the source code for a more detailed example.

    ### API reference [#api-reference-3]

    * [`RtcEngineEx`](https://api-ref.agora.io/en/video-sdk/cpp/4.x/API/class_irtcengineex.html#class_irtcengineex)
    * [`RtcConnection`](https://api-ref.agora.io/en/video-sdk/cpp/4.x/API/class_rtcconnection.html)
    * [`joinChannelEx`](https://api-ref.agora.io/en/video-sdk/cpp/4.x/API/class_irtcengineex.html#api_irtcengineex_joinchannelex)
    * [`setupRemoteVideoEx`](https://api-ref.agora.io/en/video-sdk/cpp/4.x/API/class_irtcengineex.html#api_irtcengineex_setupremotevideoex)

    
  
      
  
