# Join multiple channels (/en/realtime-media/broadcast-streaming/build/connect-across-channels/join-multiple-channels/react-native)

> 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

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`.

* Use the `connection` parameter in each callback to identify the corresponding channel.

## Prerequisites

Ensure that you have implemented the [SDK quickstart](../../index) in your project.

## Implementation

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

1. Join the second channel

Call `joinChannelEx` to join a secondary channel by specifying the `RtcConnection` object and using a random user ID.

```javascript
let token2 = "token2";
const channelId2 = "channel2";
let uid2 = 321;

// Join multiple channels
rtcEngine.joinChannelEx(
  token2,
  // RtcConnection
  {
    channelId: channelId2,
    localUid: uid2,
  },
  // ChannelMediaOptions
  {
    clientRoleType: ClientRoleType.ClientRoleBroadcaster,
    publishMicrophoneTrack: false,
    publishCameraTrack: false,
    autoSubscribeAudio: false,
    autoSubscribeVideo: false,
    publishSecondaryCameraTrack: true,
  }
);
```

2. Set up remote user video

Listen to the `onUserJoined` callback and set the remote video.

```tsx
// Register callback for when a remote user joins the current channel
agoraEngine.registerEventHandler(
  {
    onUserJoined: (_connection: RtcConnection, uid: number) => {
      showMessage("remote user " + uid + " added");
      setRemoteUid(uid);
    },
  }
);

// Creating a Remote View Using RtcSurfaceView
<RtcSurfaceView
  canvas={
    {
      uid: remoteUid,
      sourceType: VideoSourceType.VideoSourceRemote,
    }
  }
  style={styles.videoView}
/>;
```

## 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 [JoinMultipleChannel](https://github.com/AgoraIO-Extensions/react-native-agora/blob/main/example/src/examples/advanced/JoinMultipleChannel/JoinMultipleChannel.tsx) open-source sample project for your reference. Download the project or view the source code for a more detailed example.

### API reference

* [`IRtcEngineEx`](https://api-ref.agora.io/en/video-sdk/react-native/4.x/API/class_irtcengineex.html#class_irtcengineex)
* [`RtcConnection`](https://api-ref.agora.io/en/video-sdk/react-native/4.x/API/class_rtcconnection.html)
* [`joinChannelEx`](https://api-ref.agora.io/en/video-sdk/react-native/4.x/API/class_irtcengineex.html#api_irtcengineex_joinchannelex)
* [`onUserJoined`](https://api-ref.agora.io/en/video-sdk/react-native/4.x/API/class_irtcengineeventhandler.html#callback_irtcengineeventhandler_onuserjoined)

    
  
      
  
