logo
Video Call
Other Features
On this page

Login to Multiple Rooms

2026-03-05

Feature Overview

The same user can join multiple rooms at the same time, and simultaneously publish streams, play streams, send real-time messages, and receive message callbacks in multiple rooms.

Notes
  • ZEGO Express SDK has supported this feature since version 2.9.0.
  • This feature is not enabled by default. To use it, please contact ZEGOCLOUD Technical Support to enable the relevant permissions.
  • After this feature is enabled, it supports joining up to 5 rooms at the same time by default. If you have more requirements, please contact ZEGOCLOUD Technical Support for assistance.

Application Scenarios

This feature can isolate messages and callbacks from multiple rooms, enabling more flexible video call services. ZEGO recommends it for cross-room video calls and online education super small class scenarios.

  • Cross-room Video Calls

    Host A and Host B conduct a cross-room video call. Host A can notify all viewers in Room A to login to Host B's room to play streams. Host B can similarly notify all viewers in Room B to login to Host A's room to play streams.

  • Super Small Class

    The teacher enters the large class room to publish streams, and all students login to the large class room to play streams, while simultaneously logging in to group rooms to discuss and conduct video calls with students in the same group. The teaching assistant logs in to the group rooms to maintain classroom order or answer students' questions.

Prerequisites

Before implementing multi-room functionality, please ensure:

  • You have integrated ZEGO Express SDK (version 2.9.0 and above) in the project and implemented basic real-time audio and video functions. For details, please refer to Quick Start - Integration and Quick Start - Implementation Flow.
  • You have created a project in the ZEGOCLOUD Console and applied for a valid AppID and AppSign.
  • You have contacted ZEGOCLOUD Technical Support to enable the multi-room feature.

Usage Steps

Taking the same user joining two rooms as an example, the overall implementation flow is as follows:

  1. Before initializing the SDK, set the room mode to multi-room.
  2. Initialize the SDK.
  3. Join the first room. After successful login, you can publish streams, play streams, send and receive real-time messages in that room.
  4. Join the second room. After successful login, you can publish streams, play streams, send and receive real-time messages in that room.
  5. Leave the first and second rooms. There is no timing restriction on leaving rooms.

The implementation of specific functions is as follows:

Prerequisites

Before implementing multi-room functionality, please ensure:

  • You have created a project in the ZEGOCLOUD Console and applied for a valid AppID and AppSign.
  • You have integrated ZEGO Express SDK (version 2.9.0 and above) in the project and implemented basic audio and video publishing and playing functions. For details, please refer to Quick Start - Integration and Quick Start - Implementation Flow.
  • You have contacted ZEGOCLOUD Technical Support to enable the multi-room feature.

Usage Steps

Taking the same user joining two rooms as an example, the overall implementation flow is as follows:

  1. Before initializing the SDK, set the room mode to multi-room.
  2. Initialize the SDK.
  3. Join the first room. After successful login, you can publish streams, play streams, send and receive real-time messages in that room.
  4. Join the second room. After successful login, you can publish streams, play streams, send and receive real-time messages in that room.
  5. Leave the first and second rooms. There is no timing restriction on leaving rooms.

The implementation of specific functions is as follows:

1 Set Multi-Room Mode

You must call the setRoomMode interface before initializing the SDK, and set the room mode to multi-room mode through the ZegoRoomMode class, i.e., the mode value is ZEGO_ROOM_MODE_MULTI_ROOM.

Note

If you set multi-room mode without enabling the multi-room feature, logging in the room will fail and return error code "1002036".

// Set room mode to multi-room mode
ZegoExpressSDK::setRoomMode(ZegoRoomMode::ZEGO_ROOM_MODE_MULTI_ROOM)

2 Initialize SDK

Please refer to "Initialization" in Quick Start - Implementation Flow to initialize the SDK.

3 Login Room

Pass in parameters such as Room ID (roomID) and call the loginRoom interface to login the room.

  • In single-room mode, you can only login to one room at the same time. When calling the loginRoom interface, if you have already logged in to another room, you will be prompted that you are already logged in to the same room.
  • In multi-room mode, you can login to multiple rooms at the same time, and the logged in user information must be the same.
// Create user
ZegoUser user("userID", "userName");

// Start logging in the room
engine->loginRoom("roomID", user);

4 Publish Stream

Pass in parameters such as Stream ID (streamID) and Room ID (roomID), and call the startPublishingStream (with "ZegoPublisherConfig" parameter) interface to publish stream in the specified room.

Warning

In multi-room mode, you must use ZegoPublisherConfig to specify the "roomID" associated with the "streamID". After exiting the specified room, the corresponding stream publishing operation for that room will stop.

ZegoPublisherConfig config;
config.roomID = "room1";

// Start publishing stream
engine->startPublishingStream("streamID", config);

5 Play Stream

Pass in parameters such as Stream ID (streamID) and Room ID (roomID), and call the startPlayingStream (with "ZegoPlayerConfig" parameter) interface to play stream in the specified room.

Warning

In multi-room mode, you must use ZegoPlayerConfig to specify the "roomID" associated with the "streamID". After exiting the specified room, the corresponding stream playing operation for that room will stop.

ZegoPlayerConfig config;
config.roomID = "room1";

// Start playing stream
engine->startPlayingStream("streamID", nullptr, config);

6 Send/Receive Real-Time Messages

Multi-room and single-room sending and receiving real-time messages are implemented consistently. For details, please refer to Common Features - Real-Time Messages.

7 Leave Room

Pass in the Room ID (roomID) and call the logoutRoom interface to leave the room.

Note

If you want to leave all logged in rooms at once, you can directly call the logoutRoom interface without the "roomID" parameter.

  • In single-room mode, leaving the room will stop all publishing and playing streams.
  • In multi-room mode, leaving the room can only leave the specified room and stop the publishing and playing streams for that room.
// Leave room
engine->logoutRoom("roomID");

FAQ

  • Did you call the setRoomMode interface before initializing the SDK? In this case, error code "1001020" will be reported.
  • Have you contacted ZEGOCLOUD Technical Support to enable the multi-room feature?
  • Did you pass in the correct parameters?

If you set multi-room mode without enabling the multi-room feature, logging in the room will fail and return error code "1002036".

When the number of simultaneously logged in rooms exceeds the maximum number of rooms, error code "1002037" will be returned. Currently, it supports joining up to 5 rooms at the same time by default. For more requirements, please contact ZEGOCLOUD Technical Support for extended capabilities.

In multi-room mode, if the passed in login user information is not the same, error code "1002018" will be returned.

In multi-room mode, you must call the startPublishingStream interface with the "ZegoPublisherConfig" parameter to publish stream, otherwise error code "1003070" will be returned.

In multi-room mode, you must call the startPlayingStream interface with the "ZegoPlayerConfig" parameter to play stream, otherwise error code "1004070" will be returned.

Previous

Real-Time Messages and Signaling

Next

Sound Level and Audio Spectrum

On this page

Back to top