- Documentation
- Video Call
- Upgrade using advanced features
- Distincitve features
- Join multiple rooms
Join multiple rooms
Introduction
The same user can join multiple rooms at the same time, and publish streams, play streams, send real-time messages and receive message callbacks in multiple rooms at the same time.
- ZEGO Express SDK supports this function since version 2.9.0.
- You need to contact ZEGOCLOUD technical support to activate the multiple rooms function.
- A maximum of 5 rooms can be joined at the same time by default. If you need more, please contact ZEGOCLOUD technical support to provide expansion capabilities.
This feature can be used for various use cases. Here are some examples:
- Cross-room interactions in live streaming
- Breakout rooms in virtual classrooms
Prerequisites
Before you begin, make sure you complete the following:
Create a project in ZEGOCLOUD Admin Console and get the AppID and AppSign of your project.
Refer to the Quick Start doc to complete the SDK integration and basic function implementation.
Setting up multi-room mode
Before initializing the SDK, call the setRoomMode interface, and set the room mode to multi-room mode through the ZegoRoomMode class, that is, the "mode" value is "MULTI_ROOM".
// Set room mode to multi-room mode
ZegoExpressEngine.setRoomMode(ZegoRoomMode.MULTI_ROOM);
Log in to rooms
Enter the roomID and other parameters, and call the loginRoom interface to log in to the 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.
ZegoUser user = new ZegoUser("user1");
engine.loginRoom("room1", user);
Publish streams
Pass in the streamID, roomID and other parameters, and call the startPublishingStream (with "ZegoPublisherConfig" parameter) interface to publish streams in the specified room.
In multi-room mode, you must use ZegoPublisherConfig to specify the "roomID" associated with the "streamID". After exiting the specified room, the publish streams operation corresponding to the room will be stopped.
ZegoPublisherConfig config = new ZegoPublisherConfig();
config.roomID = "room1";
engine.startPublishingStream("stream1", config, ZegoPublishChannel.MAIN);
Play streams
Pass in the streamID, roomID and other parameters, and call the startPlayingStream (with "ZegoPlayerConfig" parameter) interface to play streams in the specified room.
In multi-room mode, you must use ZegoPlayerConfig to specify the "roomID" associated with the "streamID". After exiting the specified room, the play streams operation corresponding to the room will be stopped.
ZegoPlayerConfig config = new ZegoPlayerConfig();
config.roomID = "room1";
engine.startPlayingStream("stream1", new ZegoCanvas(play_view), config);
Log out from rooms
Pass in the roomID and call the logoutRoom interface to exit the room.
If you want to log out of all logged-in rooms at once, you can directly call the logoutRoom interface without "roomID".
engine.logoutRoom("room1");