Manage room user attributes
This document is applicable to the following platforms of Unity framework: iOS, Android, macOS, and Windows.
Overview
The In-app Chat SDK provides the feature of configuring user attributes of users in a room, that is, customizing user attributes of users in a room. This feature applies to the following scenarios:
- Configure roles of room members, such as setting the room owner, administrator, participant, and participant level.
- Turn on/off the camera, turn on/off the microphone, mute/unmute a user, and enable/disable whiteboard sharing.
Implementation process
-
User attributes of up to 500 users can be configured in each room, and the user attributes are stored in
Key-Value
format. To increase the maximum number of user attributes that can be configured in each room, developers can contact ZEGOCLOUD technical support. -
The total length of user attribute
Key-Value
pairs of each user in a room cannot exceed 144 bytes, and the number ofKey-Value
pairs cannot exceed 30. In a singleKey-Value
pair, the key cannot exceed 8 bytes, and the value cannot exceed 64 bytes. To increase the maximum length of aKey-Value
pair, developers can contact ZEGOCLOUD technical support. -
After a room is destroyed, the configured customized user attributes are also deleted.
Configure user attributes
The operator and the user whose attributes are configured or modified must be users in the room.
Developers can call the setRoomMembersAttributes API to configure user attributes of users in a room. Configured user attributes are stored in Key-Value
format.
- When a key does not exist, configuring user attributes indicates adding a user attribute.
- When a key already exists, configuring user attributes indicates updating the value of an existing attribute.
Dictionary<string, string> attributes = new Dictionary<string, string>();
attributes.Add("key1", "value1");
List<string> userIDs = new List<string>();
userIDs.Add("userID1");
ZIMRoomMemberAttributesSetConfig setConfig = new ZIMRoomMemberAttributesSetConfig();
setConfig.isDeleteAfterOwnerLeft = true;
ZIM.GetInstance().SetRoomMembersAttributes(attributes, userIDs, "roomID",
setConfig,
(string roomID, List<ZIMRoomMemberAttributesOperatedInfo> infos, List<string> errorUserList, ZIMError errorInfo) =>
{
// The service logic after the configuration result is returned.
}
);
Query user attributes of some users
Users in a room can call the queryRoomMembersAttributes API to query the user attributes of some users in the room.
List<string> userIDs = new List<string>();
userIDs.Add("userID1");
ZIM.GetInstance().QueryRoomMembersAttributes(userIDs, "roomID", (string roomID, List<ZIMRoomMemberAttributesInfo> infos, ZIMError errorInfo) =>
{
//The service logic after the query result is returned.
}
);
Query user attributes of all users
Users in a room can call the queryRoomMemberAttributesList API to query the user attributes of all users in the room.
ZIMRoomMemberAttributesQueryConfig queryConfig = new ZIMRoomMemberAttributesQueryConfig();
queryConfig.count = 100;
queryConfig.nextFlag = "";
ZIM.GetInstance().QueryRoomMemberAttributesList(
"roomID", queryConfig, (string roomID, List<ZIMRoomMemberAttributesInfo> infos, string nextFlag, ZIMError errorInfo) =>
{
if (nextFlag == "")
{
// All user room user attributes have been queried
}
else
{
// Continue querying the next page.
}
}
);
User attribute change notification
When user attributes of members in a room are changed, you can register the OnRoomMemberAttributesUpdated
callback API to listen for user attribute change notifications of members in the room.
ZIM.GetInstance().onRoomMemberAttributesUpdated = (
ZIM zim, List<ZIMRoomMemberAttributesUpdateInfo> infos,
ZIMRoomOperatedInfo operatedInfo, string roomID) =>
{
// The service logic after user attributes of members in a room are changed.
};
When a user in a room calls the setRoomMembersAttributes API:
-
If the number of users in the room is less than or equal to 500, all users in the room will receive the user attribute change notification.
-
If the number of users in the room exceeds 500, only the operator and the user whose attribute is configured or modified will receive the user attribute change notification.
To increase the maximum number of users in the room who can receive the user attribute change notification, developers can contact ZEGOCLOUD technical support.
Batch query room user information
Developers can use the queryRoomMembers interface to query the information of users in a room in bulk by passing the roomID and an array of userIDs. After a successful API call, the ZIMRoomMembersQueriedCallback will return the userList of successfully queried users (which can be used to confirm if the target users are in the room), as well as the errorUserList of failed queries (which can be used to confirm if the target users are not in the room).
The default limit for the number of users that can be queried in bulk is 10.
The sample code is as follows:
string userIdA = "UserIdA";
string userIdB = "UserIdB";
List<string> userIDs = new List<string>();
userIDs.Add(userIdA);
userIDs.Add(userIdB);
ZIM.GetInstance().QueryRoomMembers(userIDs, "roomID", (string roomID, List<ZIMRoomMemberInfo> memberList, List<ZIMErrorUserInfo> errorUserList, ZIMError errorInfo)=>{
if (errorInfo.code == ZIMErrorCode.Success){
// Operation successful.
}
});