Skip to main content

Event Listening

Adding Listeners

The addEventListener method is used to receive various event notifications from within IMLib. Multiple listener functions can be added for the same event type. For events that should only be bound once, you can use onceEventListener.

const Events = RongIMLib.Events
RongIMLib.addEventListener(Events.MESSAGES, (evt) => {
console.log(evt.messages)
})

Removing Listeners

It is important for the business layer to use removeEventListener or removeEventListeners to remove listeners for specific events when necessary to avoid memory leaks. The removeEventListeners method will remove all listener functions for a particular event.

const Events = RongIMLib.Events

const listener = (evt) => console.log(evt.messages)

// Add a specific event listener
RongIMLib.addEventListener(Events.MESSAGES, listener)

// Remove a specific event listener
RongIMLib.removeEventListener(Events.MESSAGES, listener)

// Remove all listeners for a specific event
RongIMLib.removeEventListeners(Events.MESSAGES)

Events

Event NameReturn TypeDescriptionVersion
CONNECTINGvoidConnecting
CONNECTEDvoidConnected
DISCONNECTErrorCodeDisconnected Note: Starting from version 5.7.0, the callback parameter type has changed from ConnectionStatus to ErrorCode
SUSPENDErrorCodeConnection abnormally disconnected (auto-reconnect) Note: Starting from version 5.7.0, the callback parameter type has changed from ConnectionStatus & ErrorCode to ErrorCode
MESSAGESIMessagesEventReceived messages
READ_RECEIPT_RECEIVEDIReadReceiptReceivedEventReceived read receipt (one-to-one chat)
MESSAGE_RECEIPT_REQUESTIMessageReceiptRequestEventReceived read receipt request (group chat)
MESSAGE_RECEIPT_RESPONSEIMessageReceiptResponseEventReceived read receipt response (group chat)
CONVERSATIONIConversationEventReceived conversation change notification
CHATROOMIChatroomListenerDataReceived chatroom change notification. Note: To listen for chatroom member changes, please submit a ticket to enable the service.
EXPANSIONIExpansionListenerDataReceived expansion change notification
PULL_OFFLINE_MESSAGE_FINISHEDvoidOffline message pull completed
TAGvoid(Applicable to multi-device login scenarios) Received tag list notification, indicating that the user may have created, removed, or edited a tag on another device. Upon receiving this notification, you should actively call getTags to retrieve all tags to update UI rendering. This tag list includes all tags used to mark conversations.
CONVERSATION_TAGvoid(Applicable to multi-device login scenarios) Received conversation tag change notification, indicating that the user may have modified the tags on a conversation on another device. Upon receiving this notification, you should actively call getTagsFromConversation for each conversation in the locally rendered conversation list to update UI rendering.
TYPING_STATUSITypingStatusEventReceived typing status notification
MESSAGE_BLOCKEDIBlockedMessageInfoSensitive word callback notification. Requires submitting a ticket to enable the service. Default is off. 5.0.2
ULTRA_GROUP_ENABLEIAReceivedConversationUltra group conversation list synchronization completed, can call ultra group related interfaces5.2.0
OPERATE_STATUSIOperateStatusNotifyUltra group input status notification5.2.0
ULTRA_GROUP_MESSAGE_EXPANSION_UPDATEDIAReceivedMessageUltra group message expansion update notification5.2.0
ULTRA_GROUP_MESSAGE_MODIFIEDIAReceivedMessageUltra group message modified notification5.2.0
ULTRA_GROUP_MESSAGE_RECALLEDIAReceivedMessageUltra group message recalled notification5.2.0
ULTRA_GROUP_CHANNEL_TYPE_CHANGEIUltraChannelChangeInfoUltra group channel type change5.4.2
ULTRA_GROUP_CHANNEL_DELETEIUltraChannelDeleteInfoUltra group channel deleted5.4.2
ULTRA_GROUP_CHANNEL_USER_KICKEDIUltraChannelUserKickedInfoUltra group private channel member removed5.4.2
DATABASE_UPGRADE_WILL_STARTvoidDatabase upgrade will start, only supported in Electron5.10.4
DATABASE_UPGRADINGnumberDatabase upgrading, only supported in Electron5.10.4
DATABASE_UPGRADE_DID_COMPLETEErrorCodeDatabase upgrade completed, only supported in Electron5.10.4
GROUP_OPERATIONIGroupOperationInfoGroup operation callback, can determine the operation type based on operation in IGroupOperationInfo5.12.0
GROUP_INFO_CHANGEDIGroupInfoChangedGroup information change notification5.12.0
GROUP_MEMBER_INFO_CHANGEDIGroupMemberInfoChangedGroup member information change notification5.12.0
GROUP_APPLICATION_EVENTIGroupApplicationInfoUser application or invitation event and result notification5.12.0
GROUP_REMARK_CHANGED_SYNCIGroupRemarkChangedSyncGroup name remark update multi-device synchronization notification5.12.0
GROUP_FOLLOWS_CHANGED_SYNCIGroupFollowsChangedSyncGroup member special follow multi-device synchronization notification5.12.0
FRIEND_ADDEDIFriendAddFriend added notification5.12.0
FRIEND_DELETEIFriendDeleteFriend removed notification5.12.0
FRIEND_APPLICATION_STATUS_CHANGEDIFriendApplicationStatusChangeFriend application notification5.12.0
FRIEND_CLEAREDnumberClear all friends notification, triggered by calling clear all friends via Server API5.12.0
FRIEND_INFO_CHANGED_SYNCIFriendInfoChangedSyncMulti-device synchronization friend information change notification5.12.0