Listen to Chatroom Events
The chatroom service supports client apps to monitor the following types of chatroom operation events: status changes of chatroom rooms and local chatroom-related operations, user join/exit status in current and other clients, member join/exit event notifications in chatrooms, as well as information related to member muting and banning in chatrooms.
Setting Up Chatroom Operation Listeners
You can set up listeners via addEventListener.
Example call: addEventListener(Events.CHATROOM, listener)
const listener = (event) => {
if (event.rejoinedRoom) {
console.log('SDK internal chatroom reconnection info:', event.rejoinedRoom)
}
if (event.updatedEntries) {
console.log('Detected chatroom KV updates:', event.updatedEntries)
}
if (event.userChange) {
console.log('User join/exit notifications:', event.userChange)
}
if (event.chatroomDestroyed) {
console.log('Chatroom destruction:', event.chatroomDestroyed)
}
/* since 5.7.9 */
if (event.chatroomNotifyMultiLoginSync) {
console.log('Multi-device sync notifications for join/exit:', event.chatroomNotifyMultiLoginSync)
}
/* since 5.7.9 */
if (event.chatroomNotifyBlock) {
console.log('Chatroom user ban notifications:', event.chatroomNotifyBlock)
}
/* since 5.7.9 */
if (event.chatroomNotifyBan) {
console.log('Chatroom user mute notifications:', event.chatroomNotifyBan)
}
}
RongIMLib.addEventListener(Events.CHATROOM, listener)
Chatroom Destruction Event
The following lists the chatroom destruction event.
| Event | Trigger Condition | Description |
|---|---|---|
event.chatroomDestroyed | When the current user is online and the chatroom they're in gets destroyed | Returns data including: chatroom ID. |
Chatroom Member Change Events
The event.userChange event is triggered by default when local users join or exit a chatroom.
To monitor join/exit actions of other members in the chatroom, you can enable this feature in the Service Configuration page of the IM service in the RC Console under Chatroom > Chatroom Member Change Monitoring.
| Event | Trigger Condition | Description |
|---|---|---|
event.userChange | When users join or exit a chatroom | IChatroomUserChangeInfo encapsulates information about members who joined or exited the current chatroom. If the current user gets disconnected from the chatroom due to network issues, join/exit behaviors of other members during the disconnection period cannot be monitored. |
Multi-Device Login Event Notifications
SDK versions 5.4.5 and above support monitoring the following event notifications.
When a user logs in on multiple devices and joins/exits a chatroom on another client, the event.chatroomNotifyMultiLoginSync event is triggered. For detailed data definitions, see IChatroomNotifyMultiLoginSync.
| Trigger Scenario | Notification Scope | Description |
|---|---|---|
| Multi-device logged-in user joins a chatroom on one device | The joining user | When the current user joins a chatroom on one device, online devices on other ends will receive notifications, while offline devices won't. Returns data including: chatroom ID, join time. |
| Multi-device logged-in user exits a chatroom on one device | The exiting user | When the current user exits a chatroom on one device, online devices on other ends will receive notifications, while offline devices won't. Returns data including: chatroom ID, exit time. |
| Multi-device logged-in user already in a chatroom gets kicked from previous chatroom when joining a new one | Current user and all members of the kicked chatroom | If Single User Joins Multiple Chatrooms is enabled in the console, no notification will be sent. Returns data including: chatroom ID, kick time. |
Ban-Related Event Notifications
SDK versions 5.4.5 and above support monitoring the following event notifications.
When ban/unban events occur in the user's chatroom and the relevant Server API is called with notification specified (setting needNotify to true), the event.chatroomNotifyBlock event is triggered. For detailed data definitions, see IChatroomNotifyBlock.
| Trigger Scenario | Notification Scope | Description |
|---|---|---|
| Ban Chatroom User | All chatroom members | Returns data including: chatroom ID, list of banned member user IDs, ban time and duration, additional information. |
| Unban Chatroom User | The unbanned member | Returns data including: chatroom ID, current user ID, additional information. |
Mute-Related Event Notifications
SDK versions 5.4.5 and above support monitoring the following event notifications.
When mute/unmute events occur in the user's chatroom and the relevant Server API is called with notification specified (setting needNotify to true), the event.chatroomNotifyBan event is triggered. For detailed data definitions, see IChatroomNotifyBan.
| Trigger Scenario | Notification Scope | Description |
|---|---|---|
| Mute Specified Chatroom User | All chatroom members | Returns data including: chatroom ID, list of muted member user IDs, mute time and duration, additional information. |
| Unmute Specified Chatroom User | All chatroom members | Returns data including: chatroom ID, list of unmuted member user IDs, unmute time, additional information. |
| Set Chatroom-Wide Mute | All chatroom members | Returns data including: chatroom ID, mute time, additional information. |
| Cancel Chatroom-Wide Mute | All chatroom members | Returns data including: chatroom ID, unmute time, additional information. |
| Add to Chatroom-Wide Mute Allowlist | All chatroom members | Returns data including: chatroom ID, list of user IDs added to allowlist, allowlist setting time, additional information. |
| Remove from Chatroom-Wide Mute Allowlist | All chatroom members | Returns data including: chatroom ID, list of user IDs removed from allowlist, removal time, additional information. |
| Global User Mute | The globally muted user | Returns data including: chatroom ID, mute time and duration, additional information. |
| Cancel Global User Mute | The globally unmuted user | Returns data including: chatroom ID, unmute time, additional information. |