logo
On this page

Manage room properties


ZEGOCLOUD's In-app Chat (the ZIM SDK) provides the capability of room property management, allowing you to customize the properties of a specified room.

With this feature, you can build your app to meet different requirements of various scenarios: customize the in-room properties in a live audio streaming or live chatroom, manage your speaker seats in a live audio room, mark player role and the latest facts and figures in an online Werewolf and other online board games.

Set room properties

To set room properties, set them when you call the createRoom method to create a room.

Warning
  • Up to 20 room properties can be set in a room. The room property is stored in the format of Key-Value. The maximum length of Key is 16 bytes, the maximum length of Value is 1024 bytes, and the total length of all properties must not exceed 5120 bytes. For more customizable room properties, contact ZEGOCLOUD Technical Support.
  • The customized room properties you set will be cleared after the room is destroyed.
Sample code
zim::ZIMRoomInfo room_info;

room_info.roomID = "room_id";
room_info.roomName = "room_name";

zim::ZIMRoomAdvancedConfig advanced_info;
advanced_info.roomAttributes.emplace("key", "value");

zim_->createRoom(
    room_info, advanced_info, [=](zim::ZIMRoomFullInfo roomInfo,
                                 zim::ZIMError errorInfo) {
});
1
Copied!

Modify room properties

The room properties you set are stored as key-value.

  • When Key does not exist: Setting room property means adding room property.
  • When the Key already exists: Setting the room property means updating the value of the existing room property.
Sample code
std::unordered_map<std::string, std::string> roomAttributes;
roomAttributes.emplace("key", "value");
    
zim->setRoomAttributes(roomAttributes, room_id, nullptr, [=](const std::string &roomID, const std::vector<std::string> &errorKeyList,const ZIMError &errorInfo){});
1
Copied!

Delete room properties

Generally, you can only delete the room properties that you own. You can also delete the room properties created by others by setting the isForce value in config.

Sample code
std::vector<std::string> keys;
keys.push_back("key");

zim->deleteRoomAttributes(keys, room_id, nullptr, [=](const std::string &roomID, const std::vector<std::string> &errorKeyList,const ZIMError &errorInfo){});
1
Copied!

Get room properties

Sample code
zim->queryRoomAllAttributes(room_id,[=](const std::string &roomID, const std::unordered_map<std::string, std::string> &roomAttributes,const ZIMError &errorInfo){});
1
Copied!

Combined room properties operation

The merge operation means that you can combine multiple operations within the same room into one operation using the beginRoomAttributesBatchOperation and endRoomAttributesBatchOperation methods. This is typically used when you want to perform consecutive operations without being interrupted by other users' operations.

Sample code
std::unordered_map<std::string, std::string> roomAttributes;
std::vector<std::string> keys;

auto config = zim::ZIMRoomAttributesBatchOperationConfig{true, true, true};
zim_->BeginRoomAttributesBatchOperation(utf8_room_id, &config);

zim_->BeginRoomAttributesBatchOperation(room_id, &config);
zim->setRoomAttributes(roomAttributes, room_id, nullptr, [=](const std::string &roomID, const std::vector<std::string> &errorKeyList,const ZIMError &errorInfo){});
zim->deleteRoomAttributes(keys, room_id, nullptr, [=](const std::string &roomID, const std::vector<std::string> &errorKeyList,const ZIMError &errorInfo){});
zim->endRoomAttributesBatchOperation(room_id,[=](const std::string &roomID, const ZIMError &errorInfo){});
1
Copied!

Previous

Manage room info

Next

Room user attributes