logo
On this page

Multi-Room Login

2026-03-05

Introduction

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.

Note
  • ZEGO Express SDK has supported this feature since version 2.9.0.
  • This feature is not enabled by default. If you need 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 of multiple rooms, implementing more flexible co-hosting business. ZEGO recommends it for cross-room co-hosting and online education super small class scenarios.

  • Cross-room co-hosting

    Host A and Host B conduct cross-room co-hosting. Host A can notify all viewers in room A to log in to Host B's room to play streams, and Host B can also notify all viewers in room B to log in to Host A's room to play streams.

  • Super small class

    Teachers enter the large class room to publish streams, students all log in to the large class room to play streams, and simultaneously log in to group rooms to discuss and co-host with students in the same group. Teaching assistants log in to group rooms to maintain classroom order or answer student questions.

Download Sample Source Code

Please refer to Download Sample Source Code to obtain the source code.

For related source code, please check the files in the "/ZegoExpressExample/Examples/Others/MultipleRooms" directory.

Prerequisites

Before implementing multi-room functionality, ensure that:

  • ZEGO Express SDK (version 2.9.0 and above) has been integrated into the project, and basic real-time audio and video functionality has been implemented. For details, please refer to Quick Start - Integration and Quick Start - Implementation Process.

  • A project has been created in the ZEGOCLOUD Console, and valid AppID and AppSign have been obtained.

  • ZEGOCLOUD Technical Support has been contacted to enable the multi-room feature.

Usage Steps

Taking the same user joining two rooms as an example, the overall implementation process 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 this room.
  4. Join the second room. After successful login, you can publish streams, play streams, send and receive real-time messages in this 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

Must call the setRoomMode interface before initializing the SDK, and set the room mode to multi-room mode through the ZegoRoomMode class, that is, the "mode" value is "ZEGO_ROOM_MODE_MULTI_ROOM".

Note

If multi-room mode is set without enabling the multi-room feature, login room will fail and report an error, returning error code "1002036".

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

2 Initialize SDK

Please refer to "Create Engine" in Quick Start - Implementation Process for SDK initialization.

3 Login Room

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

  • In single-room mode, you can only log in to one room at the same time. When calling the loginRoom interface, if you have already logged in to other rooms, you will be prompted that you have logged in to the same room.
  • In multi-room mode, you can log in 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 to 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 "streamID". After exiting the specified room, the stream publishing operation for that room will be stopped.

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 "streamID". After exiting the specified room, the stream playing operation for that room will be stopped.

ZegoPlayerConfig config;
config.roomID = "room1";

// Play real-time stream
// Fill in Windows window handle
HWND playWND = ...;
ZegoCanvas canvas(playWND);
engine->startPlayingStream("streamID", &canvas, config);

6 Send/Receive Real-time Messages

The implementation of sending and receiving real-time messages in multi-room and single-room is the same. For details, please refer to Real-time Messages and Signaling.

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 "roomID".

  • Leaving a room in single-room mode will stop all publishing and playing streams at the same time.
  • Leaving a room in multi-room mode can only leave the specified room and stop publishing and playing streams for that room.
// Leave room
engine->logoutRoom("roomID");

FAQ

  • Whether the setRoomMode interface was called before initializing the SDK. In this case, error code "1001020" will be reported.
  • Whether ZEGOCLOUD Technical Support has been contacted to enable the multi-room feature.
  • Whether the correct parameters are passed in.

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

When the number of rooms logged in at the same time exceeds the maximum number of rooms, error code "1002037" will be returned. Currently, the default maximum is 5 rooms at the same time. If you have more requirements, please contact ZEGOCLOUD Technical Support for extended capabilities.

In multi-room mode, if the logged-in user information passed in 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 Messaging and Signaling

Next

Audio 3A Processing

On this page

Back to top