- 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 implementing the function, please make sure:
- ZEGO Express SDK has been integrated into the project to implement basic real-time audio and video functions. For details, please refer to Quick start .
- A project has been created in ZEGOCLOUD Console and applied for a valid AppID and AppSign. For details, please refer to Console - Project Information .
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 "ZegoRoomModeMultiRoom".
// Set room mode to multi-room mode
[ZegoExpressEngine setRoomMode:ZegoRoomModeMultiRoom];
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.
[[ZegoExpressEngine sharedEngine] loginRoom:@"multi_room_01" user:[ZegoUser userWithUserID:@"multi_room_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 = [[ZegoPublisherConfig alloc] init];
config.roomID = @"multi_room_01";
[[ZegoExpressEngine sharedEngine] startPublishingStream:@"multi_room_publish_01" config:config channel:ZegoPublishChannelMain];
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 = [[ZegoPlayerConfig alloc] init];
config.roomID = @"multi_room_01";
[[ZegoExpressEngine sharedEngine] startPlayingStream:@"multi_room_player_01" canvas:[ZegoCanvas canvasWithView:self.playView] config: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".
[[ZegoExpressEngine sharedEngine] logoutRoom:@"multi_room_01"];