logo
On this page

Manage room user attributes


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

Warning
  • 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 of Key-Value pairs cannot exceed 30. In a single Key-Value pair, the key cannot exceed 8 bytes, and the value cannot exceed 64 bytes. To increase the maximum length of a Key-Value pair, developers can contact ZEGOCLOUD technical support.

  • After a room is destroyed, the configured customized user attributes are also deleted.

Configure user attributes

Warning

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.
Sample code
const config = {
    isDeleteAfterOwnerLeft: false
};
zim.setRoomMembersAttributes({'key1': 'value1'}, ['user1', 'user2'], 'roomID', config).then(res => {
    // The service logic after the configuration result is returned. 
});
1
Copied!

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.

Sample code
 zim.queryRoomMembersAttributes['user1', 'user2'], 'roomID').then(res => {
    // The service logic after the query result is returned. 
});
1
Copied!

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.

Untitled
const config = {
    nextFlag: '',
    count: 100
}
zim.queryRoomMemberAttributesList('roomID', config).then(res => {
    // The service logic after the query result is returned.  
});
1
Copied!

User attribute change notification

When user attributes of members in a room are changed, developers can register the onRoomMemberAttributesUpdated method of the on callback API to listen for user attribute change notifications of members in the room.

Untitled
zim.on('roomMemberAttributesUpdated', (zim, data) => {
    //The service logic after user attributes of members in a room are changed.
});
1
Copied!
Note

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 callback 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).

Note

The default limit for the number of users that can be queried in bulk is 10.

The sample code is as follows:

Untitled

const userIDs = ['user1', 'user2'];

zim.queryRoomMembers(userIDs, 'roomID').then(res => {
    // Write your business logic here after receiving the query result  
});
1
Copied!

Previous

Manage room properties

Next

Manage groups