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();
zimRoomInfo.roomID = roomID;
zimRoomInfo.roomName = "roomName" + roomID;
HashMap<String, String> hashMap = new HashMap<>();
hashMap.put("test1", "test2");
ZIMRoomAdvancedConfig zimRoomAdvancedInfo = new ZIMRoomAdvancedConfig();
zimRoomAdvancedInfo.roomAttributes = hashMap;
zim.createRoom(zimRoomInfo, zimRoomAdvancedInfo, new ZIMRoomCreatedCallback() {
@Override
public void onRoomCreated(ZIMRoomFullInfo roomInfo, ZIMError errorCode) {
assertSame(errorCode.code, SUCCESS);
}
});
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;
zim.setRoomAttributes(hashMap, roomID, config, new ZIMRoomAttributesOperatedCallback() {
@Override
public void onRoomAttributesOperated(String roomID, ArrayList<String> errorKeys, ZIMError errorInfo) {
}
});
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
.
ArrayList<String> attributeList = new ArrayList<>();
attributeList.add("xxxx");
ZIMRoomAttributesDeleteConfig config = new ZIMRoomAttributesDeleteConfig();
config.isForce = true;
zim.deleteRoomAttributes(keys, roomID, config, new ZIMRoomAttributesOperatedCallback() {
@Override
public void onRoomAttributesOperated(String roomID, ArrayList<String> errorKeys, ZIMError errorInfo) {
}
});
Get room properties
zim.queryRoomAllAttributes(roomID, new ZIMRoomAttributesQueriedCallback() {
@Override
public void onRoomAttributesQueried(String roomID, HashMap<String, String> roomAttributes, ZIMError errorInfo) {
}
});
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.beginRoomAttributesBatchOperation(mRoomID, operationConfig);
zim.endRoomAttributesBatchOperation(roomID, new ZIMRoomAttributesBatchOperatedCallback() {
@Override
public void onRoomAttributesBatchOperated(String roomID, ZIMError errorInfo) {
}
});