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 Name | Return Type | Description | Version |
---|---|---|---|
CONNECTING | void | Connecting | |
CONNECTED | void | Connected | |
DISCONNECT | ErrorCode | Disconnected Note: Starting from version 5.7.0, the callback parameter type has changed from ConnectionStatus to ErrorCode | |
SUSPEND | ErrorCode | Connection abnormally disconnected (auto-reconnect) Note: Starting from version 5.7.0, the callback parameter type has changed from ConnectionStatus & ErrorCode to ErrorCode | |
MESSAGES | IMessagesEvent | Received messages | |
READ_RECEIPT_RECEIVED | IReadReceiptReceivedEvent | Received read receipt (one-to-one chat) | |
MESSAGE_RECEIPT_REQUEST | IMessageReceiptRequestEvent | Received read receipt request (group chat) | |
MESSAGE_RECEIPT_RESPONSE | IMessageReceiptResponseEvent | Received read receipt response (group chat) | |
CONVERSATION | IConversationEvent | Received conversation change notification | |
CHATROOM | IChatroomListenerData | Received chatroom change notification. Note: To listen for chatroom member changes, please submit a ticket to enable the service. | |
EXPANSION | IExpansionListenerData | Received expansion change notification | |
PULL_OFFLINE_MESSAGE_FINISHED | void | Offline message pull completed | |
TAG | void | (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_TAG | void | (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_STATUS | ITypingStatusEvent | Received typing status notification | |
MESSAGE_BLOCKED | IBlockedMessageInfo | Sensitive word callback notification. Requires submitting a ticket to enable the service. Default is off. | 5.0.2 |
ULTRA_GROUP_ENABLE | IAReceivedConversation | Ultra group conversation list synchronization completed, can call ultra group related interfaces | 5.2.0 |
OPERATE_STATUS | IOperateStatusNotify | Ultra group input status notification | 5.2.0 |
ULTRA_GROUP_MESSAGE_EXPANSION_UPDATED | IAReceivedMessage | Ultra group message expansion update notification | 5.2.0 |
ULTRA_GROUP_MESSAGE_MODIFIED | IAReceivedMessage | Ultra group message modified notification | 5.2.0 |
ULTRA_GROUP_MESSAGE_RECALLED | IAReceivedMessage | Ultra group message recalled notification | 5.2.0 |
ULTRA_GROUP_CHANNEL_TYPE_CHANGE | IUltraChannelChangeInfo | Ultra group channel type change | 5.4.2 |
ULTRA_GROUP_CHANNEL_DELETE | IUltraChannelDeleteInfo | Ultra group channel deleted | 5.4.2 |
ULTRA_GROUP_CHANNEL_USER_KICKED | IUltraChannelUserKickedInfo | Ultra group private channel member removed | 5.4.2 |
DATABASE_UPGRADE_WILL_START | void | Database upgrade will start, only supported in Electron | 5.10.4 |
DATABASE_UPGRADING | number | Database upgrading, only supported in Electron | 5.10.4 |
DATABASE_UPGRADE_DID_COMPLETE | ErrorCode | Database upgrade completed, only supported in Electron | 5.10.4 |
GROUP_OPERATION | IGroupOperationInfo | Group operation callback, can determine the operation type based on operation in IGroupOperationInfo | 5.12.0 |
GROUP_INFO_CHANGED | IGroupInfoChanged | Group information change notification | 5.12.0 |
GROUP_MEMBER_INFO_CHANGED | IGroupMemberInfoChanged | Group member information change notification | 5.12.0 |
GROUP_APPLICATION_EVENT | IGroupApplicationInfo | User application or invitation event and result notification | 5.12.0 |
GROUP_REMARK_CHANGED_SYNC | IGroupRemarkChangedSync | Group name remark update multi-device synchronization notification | 5.12.0 |
GROUP_FOLLOWS_CHANGED_SYNC | IGroupFollowsChangedSync | Group member special follow multi-device synchronization notification | 5.12.0 |
FRIEND_ADDED | IFriendAdd | Friend added notification | 5.12.0 |
FRIEND_DELETE | IFriendDelete | Friend removed notification | 5.12.0 |
FRIEND_APPLICATION_STATUS_CHANGED | IFriendApplicationStatusChange | Friend application notification | 5.12.0 |
FRIEND_CLEARED | number | Clear all friends notification, triggered by calling clear all friends via Server API | 5.12.0 |
FRIEND_INFO_CHANGED_SYNC | IFriendInfoChangedSync | Multi-device synchronization friend information change notification | 5.12.0 |