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

> 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-2]

    Video SDK's multi-channel functionality is based on two key components:

    * `AgoraRtcConnection`

      The `AgoraRtcConnection` object identifies a connection. It contains the following information:

      * Channel name
      * User ID of the local user

      You create multiple `AgoraRtcConnection` objects, each with a different channel name and user ID. Each `AgoraRtcConnection` instance can independently publish multiple audio streams and a single video stream.

    * `AgoraRtcEngineKit(Ex)`

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

      To join multiple channels, you call `joinChannelExByToken` method in the `AgoraRtcEngineKit(Ex)` class multiple times, using a different `AgoraRtcConnection` instance each time.

    When joining multiple channels:

    * Ensure that the user ID for each `AgoraRtcConnection` object is unique and nonzero.

    * Configure publishing and subscribing options for the `AgoraRtcConnection` object in `joinChannelExByToken`.

    * Pass the `AgoraRtcEngineDelegate` object to the `delegate` parameter when calling the `joinChannelExByToken` method to receive multiple channel-related event notifications.

    ## Prerequisites [#prerequisites-2]

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

    ## Implementation [#implementation-2]

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

    1. Define an `AgoraRtcConnection` object in your project's `ViewController.swift` file.

       ```swift
       let connection1 = AgoraRtcConnection()
       ```

    2. Join the channel using a random user ID.

       ```swift
       var mediaOptions = AgoraRtcChannelMediaOptions()
       mediaOptions.autoSubscribeVideo = .of(true)
       mediaOptions.autoSubscribeAudio = .of(true)
       connection1.channelId = channelName1
       connection1.localUid = UInt.random(in: 1001...2000)
       var result = agoraKit.joinChannelEx(byToken: "your token", connection: connection1, delegate: channel1, mediaOptions: mediaOptions, joinSuccess: nil)
       channel1.channelId = channelName1
       channel1.connectionDelegate = self
       if result != 0 {
         self.showAlert(title: "Error", message: "joinChannel1 call failed: \(result), please check your params")
       }
       ```

    3. Set up the remote video in the `didJoinedOfUid` callback.

       ```swift
       func rtcEngine(_ engine: AgoraRtcEngineKit, channelId: String, didJoinedOfUid uid: UInt, elapsed: Int) {
         LogUtils.log(message: "remote user join: \(uid) \(elapsed)ms", level: .info)
         // In this operation, only one remote video view is available
         // Here, we check if there's a view tagged with that UID
         let videoCanvas = AgoraRtcVideoCanvas()
         videoCanvas.uid = uid
         // The view to be bound
         videoCanvas.view = channelId == channelName1 ? channel1RemoteVideo.videoView : channel2RemoteVideo.videoView
         videoCanvas.renderMode = .hidden
         let connection = AgoraRtcConnection()
         agoraKit.setupRemoteVideoEx(videoCanvas, connection: connection)
       }
       ```

    ## Reference [#reference-2]

    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-2]

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

    ### API reference [#api-reference-2]

    * [`AgoraRtcEngineKit`](https://api-ref.agora.io/en/video-sdk/macos/4.x/documentation/agorartckit/agorartcenginekit)
    * [`AgoraRtcConnection`](https://api-ref.agora.io/en/video-sdk/macos/4.x/documentation/agorartckit/agorartcconnection)
    * [`joinChannelExByToken` \[1/2\]](https://api-ref.agora.io/en/video-sdk/macos/4.x/documentation/agorartckit/agorartcenginekit/joinchannelex\(bytoken\:channelid\:useraccount\:delegate\:mediaoptions\:joinsuccess:\))
    * [`setupRemoteVideoEx`](https://api-ref.agora.io/en/video-sdk/macos/4.x/documentation/agorartckit/agorartcenginekit/setupremotevideoex\(_\:connection:\))

    
  
      
  
      
  
