Listen to Chatroom Events
The chatroom business supports client apps to monitor the following types of chatroom operation events: status changes of the chatroom room and local chatroom-related operations, user status changes when joining or exiting the chatroom on the current and other clients, notifications of members entering or exiting the chatroom, as well as information related to muting and banning members in the chatroom.
Setting Up a Chatroom Operation Listener
You can set up a listener using addEventListener.
Example call: addEventListener(Events.CHATROOM, listener)
const listener = (event) => {
if (event.rejoinedRoom) {
console.log('SDK internal reconnection to chatroom 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 destroyed:', event.chatroomDestroyed)
}
/* since 5.7.9 */
if (event.chatroomNotifyMultiLoginSync) {
console.log('Multi-device login sync notifications:', 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
Below are the chatroom destruction events.
Event | Trigger Condition | Description |
---|---|---|
event.chatroomDestroyed | The current user is online and the chatroom they are in is destroyed | Returns data including: chatroom ID. |
Chatroom Member Change Event
The event.userChange
event is triggered by default when the local user joins or exits a chatroom.
To monitor changes of other members in the chatroom, you need to enable the service. Please submit a ticket to apply for enabling Chatroom Member Change Monitoring.
Event | Trigger Condition | Description |
---|---|---|
event.userChange | User joins or exits the chatroom | IChatroomUserChangeInfo encapsulates the information of members who joined or exited the chatroom. If the current user is disconnected from the chatroom due to network issues, the join/exit behaviors of other members during the disconnection period will not be monitored. |
Multi-Device Login Event Notification
The SDK supports monitoring the following event notifications starting from version 5.4.5.
When a user is logged in on multiple devices and joins or exits a chatroom on one device, the event.chatroomNotifyMultiLoginSync
event is triggered. For detailed definitions of the returned data, refer to IChatroomNotifyMultiLoginSync.
Trigger Scenario | Notification Scope | Description |
---|---|---|
User logs in on multiple devices and joins a chatroom on one device | The user who joined | When the current user joins a chatroom on one device, other online devices will receive the notification, while offline devices will not. Returns data including: chatroom ID, join time. |
User logs in on multiple devices and exits a chatroom on one device | The user who exited | When the current user exits a chatroom on one device, other online devices will receive the notification, while offline devices will not. Returns data including: chatroom ID, exit time. |
User logs in on multiple devices and is already in a chatroom, joining a new chatroom causes them to be kicked out of the previous chatroom | The current user and all members of the chatroom they were kicked out of | If Single User Joins Multiple Chatrooms is enabled in the Console, no notification will be sent. Returns data including: chatroom ID, kick-out time. |
Ban-Related Event Notifications
The SDK supports monitoring the following event notifications starting from version 5.4.5.
When a ban or unban event occurs in the chatroom the user is in, and the relevant Server API is called with the needNotify
parameter set to true
, the event.chatroomNotifyBlock
event is triggered. For detailed definitions of the returned data, refer to IChatroomNotifyBlock.
Trigger Scenario | Notification Scope | Description |
---|---|---|
Ban Chatroom User | All members of the chatroom | Returns data including: chatroom ID, list of banned user IDs, ban time and duration, additional information. |
Unban Chatroom User | The unblocked member | Returns data including: chatroom ID, current user ID, additional information. |
Mute-Related Event Notifications
The SDK supports monitoring the following event notifications starting from version 5.4.5.
When a mute or unmute event occurs in the chatroom the user is in, and the relevant Server API is called with the needNotify
parameter set to true
, the event.chatroomNotifyBan
event is triggered. For detailed definitions of the returned data, refer to IChatroomNotifyBan.
Trigger Scenario | Notification Scope | Description |
---|---|---|
Mute a Specific Chatroom User | All members of the chatroom | Returns data including: chatroom ID, list of muted user IDs, mute time and duration, additional information. |
Unmute a Specific Chatroom User | All members of the chatroom | Returns data including: chatroom ID, list of unmuted user IDs, unmute time, additional information. |
Set Chatroom-Wide Mute | All members of the chatroom | Returns data including: chatroom ID, mute time, additional information. |
Cancel Chatroom-Wide Mute | All members of the chatroom | Returns data including: chatroom ID, unmute time, additional information. |
Add to Chatroom-Wide Mute Allowlist | All members of the chatroom | Returns data including: chatroom ID, list of user IDs added to the allowlist, allowlist setting time, additional information. |
Remove from Chatroom-Wide Mute Allowlist | All members of the chatroom | Returns data including: chatroom ID, list of user IDs removed from the allowlist, removal time, additional information. |
Global Mute User | The globally muted user | Returns data including: chatroom ID, mute time and duration, additional information. |
Cancel Global Mute User | The globally unmuted user | Returns data including: chatroom ID, unmute time, additional information. |