# Join multiple channels (/en/realtime-media/interactive-live-streaming/build/connect-across-channels/join-multiple-channels/electron)

> 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.mdx) 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 up the remote video.

```javascript
const EventHandles = {
  // Monitor remote user joining channel events
  onUserJoined: ({ channelId, localUid }, remoteUid, elapsed) => {
    console.log('Remote user ' + remoteUid + ' joined');
    // After the remote user joins the channel, set the remote video window
    rtcEngine.setupRemoteVideoEx(
      {
        sourceType: VideoSourceType.VideoSourceRemote,
        uid: remoteUid,
        view: remoteVideoContainer,
        setupMode: VideoViewSetupMode.VideoViewSetupAdd,
      },
      {
        channelId: channelId2,
        localUid: uid2,
      },
    );
  },
  // Other event callbacks
};

// Register event callback
rtcEngine.registerEventHandler(EventHandles);
```

## 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/Electron-SDK/blob/main/example/src/renderer/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/electron/4.x/API/class_irtcengineex.html#class_irtcengineex)
* [`RtcConnection`](https://api-ref.agora.io/en/video-sdk/electron/4.x/API/class_rtcconnection.html)
* [`joinChannelEx`](https://api-ref.agora.io/en/video-sdk/electron/4.x/API/class_irtcengineex.html#api_irtcengineex_joinchannelex)
* [`onUserJoined`](https://api-ref.agora.io/en/video-sdk/electron/4.x/API/class_irtcengineeventhandler.html#callback_irtcengineeventhandler_onuserjoined)

    
  
      
  
      
  
