Skip to main content

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.

EventTrigger ConditionDescription
event.chatroomDestroyedThe current user is online and the chatroom they are in is destroyedReturns 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.

tip

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.

EventTrigger ConditionDescription
event.userChangeUser joins or exits the chatroomIChatroomUserChangeInfo 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

tip

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 ScenarioNotification ScopeDescription
User logs in on multiple devices and joins a chatroom on one deviceThe user who joinedWhen 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 deviceThe user who exitedWhen 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 chatroomThe current user and all members of the chatroom they were kicked out ofIf Single User Joins Multiple Chatrooms is enabled in the Console, no notification will be sent. Returns data including: chatroom ID, kick-out time.
tip

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 ScenarioNotification ScopeDescription
Ban Chatroom UserAll members of the chatroomReturns data including: chatroom ID, list of banned user IDs, ban time and duration, additional information.
Unban Chatroom UserThe unblocked memberReturns data including: chatroom ID, current user ID, additional information.
tip

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 ScenarioNotification ScopeDescription
Mute a Specific Chatroom UserAll members of the chatroomReturns data including: chatroom ID, list of muted user IDs, mute time and duration, additional information.
Unmute a Specific Chatroom UserAll members of the chatroomReturns data including: chatroom ID, list of unmuted user IDs, unmute time, additional information.
Set Chatroom-Wide MuteAll members of the chatroomReturns data including: chatroom ID, mute time, additional information.
Cancel Chatroom-Wide MuteAll members of the chatroomReturns data including: chatroom ID, unmute time, additional information.
Add to Chatroom-Wide Mute AllowlistAll members of the chatroomReturns data including: chatroom ID, list of user IDs added to the allowlist, allowlist setting time, additional information.
Remove from Chatroom-Wide Mute AllowlistAll members of the chatroomReturns data including: chatroom ID, list of user IDs removed from the allowlist, removal time, additional information.
Global Mute UserThe globally muted userReturns data including: chatroom ID, mute time and duration, additional information.
Cancel Global Mute UserThe globally unmuted userReturns data including: chatroom ID, unmute time, additional information.