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.
- 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 ofKey
is 16 bytes, the maximum length ofValue
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.
ZIMRoomInfo zimRoomInfo = new ZIMRoomInfo();
// roomID is a string with a maximum length of 32 bytes. It only supports numbers, English characters, and the following special characters: '~', '!', ' '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '=', '-', '`', ';', '’', ',', '.', '<', '>', '/', '\'.
zimRoomInfo.roomID = "roomID";
// roomName is a string with a maximum length of 64 bytes, with no special character restrictions.
zimRoomInfo.roomName = "roomName";
Dictionary<string, string> roomAttributes = new Dictionary<string, string>();
roomAttributes.Add("test1", "test2");
ZIMRoomAdvancedConfig zimRoomAdvancedInfo = new ZIMRoomAdvancedConfig();
zimRoomAdvancedInfo.roomAttributes = roomAttributes;
ZIM.GetInstance().CreateRoom(zimRoomInfo, zimRoomAdvancedInfo, (ZIMRoomFullInfo roomInfo, ZIMError errorCode) =>
{
if (errorCode.code == ZIMErrorCode.Success)
{
// Successfully created
}
}
);
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.
ZIMRoomAttributesSetConfig config = new ZIMRoomAttributesSetConfig();
config.isUpdateOwner = false;
config.isForce = false;
config.isDeleteAfterOwnerLeft = false;
Dictionary<string, string> roomAttributes = new Dictionary<string, string>();
roomAttributes.Add("test1", "test2");
ZIM.GetInstance().SetRoomAttributes(roomAttributes, "roomID", config, (string roomID, List<string> errorKeys, ZIMError errorInfo) =>
{
if(errorInfo.code == ZIMErrorCode.Success)
{
// Set successfully.
}
}
);
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
.
List<string> attributeKeyList = new List<string>();
attributeKeyList.Add("xxxx");
ZIMRoomAttributesDeleteConfig config = new ZIMRoomAttributesDeleteConfig();
config.isForce = true;
ZIM.GetInstance().DeleteRoomAttributes(attributeKeyList, "roomID", config, (string roomID, List<string> errorKeys, ZIMError errorInfo) =>
{
}
);
Get room properties
By calling the QueryRoomAllAttributes, you can retrieve all the attributes of a room.
When logging into a room, the latest room attributes will be returned through the OnRoomAttributesUpdated, and there is no need to call QueryRoomAllAttributes.
ZIM.GetInstance().QueryRoomAllAttributes("roomID", (string roomID, Dictionary<string, string> roomAttributes, ZIMError errorInfo) =>
{
if(errorInfo.code == ZIMErrorCode.Success)
{
// Operation successful.
}
}
);
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.
ZIMRoomAttributesBatchOperationConfig operationConfig = new ZIMRoomAttributesBatchOperationConfig();
operationConfig.isForce = false;
operationConfig.isDeleteAfterOwnerLeft = true;
ZIM.GetInstance().BeginRoomAttributesBatchOperation("RoomID", operationConfig);
ZIM.GetInstance().EndRoomAttributesBatchOperation("roomID", (string roomID, ZIMError errorInfo) => { } );