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.
This feature can be used for various use cases. Here are some examples:
Before implementing the function, please make sure:
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];
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"]];
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];
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];
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"];