Skip to main content

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.

EventTrigger ConditionDescription
event.chatroomDestroyedWhen the current user is online and the chatroom they're in gets destroyedReturns data including: chatroom ID.

Chatroom Member Change Events

The event.userChange event is triggered by default when local users join or exit a chatroom.

tip

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.

EventTrigger ConditionDescription
event.userChangeWhen users join or exit a chatroomIChatroomUserChangeInfo 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

tip

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 ScenarioNotification ScopeDescription
Multi-device logged-in user joins a chatroom on one deviceThe joining userWhen 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 deviceThe exiting userWhen 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 oneCurrent user and all members of the kicked chatroomIf Single User Joins Multiple Chatrooms is enabled in the console, no notification will be sent. Returns data including: chatroom ID, kick time.
tip

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

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