The same user can join multiple rooms at the same time, and the total number of rooms that can be entered is currently at most two. After the user joins the room, he can only push the stream in the main room, but can pull the stream in all rooms, and can receive the signaling and callback of each room normally. This function can currently be used in the super small class scenes of connecting microphones across rooms and online education.
The advantage of multiple rooms is that users can join another room without leaving the current room, receive signaling and callback from another room, and play the audio and video streams of another room. This function can isolate the signaling and callbacks of the two rooms, realizing more flexible microphone connection services.
After successfully logging in to the main room through the loginRoom interface, call loginMultiRoom interface to log in to multiple rooms.
This article mainly reflects the realization of the multi-room function. For other operations, please refer to Quick Starts. It should be noted that after the streaming interface is called in the multi-room scenario, streaming will start in the main room.
// Login to the main room first
ZegoExpressSDK::getEngine()->loginRoom("test-roomid-1", ZegoUser user("test-userid-1"));
// Log in to multiple rooms later
ZegoExpressSDK::getEngine()->loginMultiRoom("test-roomid-2");
After logging in to the room, you can monitor events related to multiple rooms through the callback function.
The multiple rooms and the main room share a set of callback functions. Developers can distinguish which room related events triggered the callback through the roomID parameter in the callback function.
void onRoomStateUpdate(const std::string& roomID, ZegoRoomState state, int errorCode, const std::string& extendedData) override
{
// Room status update callback, after logging in the room, when the connection status of the room changes (such as the room disconnects, login authentication fails, etc.), the SDK will notify through the callback
}
void onRoomUserUpdate(const std::string& roomID, ZegoUpdateType updateType, const std::vector<ZegoUser>& userList) override
{
// User status update. After logging into the room, when a user is added or deleted in the room, the SDK will notify the user through the callback
}
void onRoomStreamUpdate(const std::string& roomID, ZegoUpdateType updateType, const std::vector<ZegoStream>& streamList, const std::string& extendedData) override
{
// Stream status update. After logging into the room, when the user pushes or deletes audio and video streams in the room, the SDK will notify the user through the callback
}
Multiple rooms can send and receive messages and signaling through the same set of IM interfaces and callbacks, and distinguish the rooms through the roomID parameter.
For specific operations, please refer to IM Function.
Call the logoutRoom interface to pass in the roomID when logging in to the multi-room to log out of the multi-room, the developer After calling this interface, you will receive onRoomStateUpdate Call back to notify that the room has been successfully exited.
- After logging in to a multi-room, you need to log out of the multi-room before you can log out of the main room.
- Exiting the multi-room will not stop the streaming, it will stop the streaming only after exiting the main room.
ZegoExpressSDK::getEngine()->logoutRoom("test-roomid-2");
| Method | Description |
|---|---|
| loginRoom | Login room |
| loginMultiRoom | Login to multi-room |
| logoutRoom | Exit room |
| onRoomStateUpdate | Room status Update callback |
| onRoomUserUpdate | Other user status updates in the room Callback |
| onRoomStreamUpdate | Stream status of other users in the room Update callback |
Call loginMultiRoom failed to log in to the multi-room, and onRoomStateUpdate callback returns 1002063 error code, prompt Why is there no multi-room permission?
The reason is that AppID does not enable multi-room permission, please contact ZEGO technical support to enable it.
Failed to log in to multiple rooms and returned the error code 1002061, what should I do?
Multi-room login is not supported. You need to call loginRoom before logging in to the main room.
Can streaming be pushed in multiple rooms?
Streams can only be pushed in the main room. Currently, multiple rooms only support streaming and a full set of signaling services (room callbacks, IM information sending and receiving).
After logging in to the multi-room, call logoutRoom to exit the main room and return the error 1002062 Code, what is the reason?
After logging in to a multi-room, you must log out of the multi-room before you can log out of the main room.
