EVENT

List of events that need to be listened for and processed on the access side. The events are described as follows:

Members

(static) SDK_READY

This event is triggered when the SDK enters the ready state. When detecting this event during listening, the access side can call SDK APIs such as the message sending API to use various features of the SDK.

Note: The SDK will not trigger the SDK_READY event until login is successful.

Example
let onSdkReady = function(event) {
  let message = tim.createTextMessage({ to: 'user1', conversationType: 'C2C', payload: { text: 'Hello world!' }});
  tim.sendMessage(message);
};
tim.on(TIM.EVENT.SDK_READY, onSdkReady);

(static) SDK_NOT_READY

This event is triggered when the SDK enters the not ready state. When this event occurs, the access side cannot use SDK features such as message sending.
To resume the SDK features, the access side needs to call the login API to drive the SDK to enter the ready state.

Note: In the scenario of force offline due to same-account multi-device login, do not call tim.login in SDK_NOT_READY. Otherwise, circular force offline may occur.

Example
let onSdkNotReady = function(event) {
  // To use features such as message sending, the access side needs to drive the SDK to enter the ready state and then calls the login API again as follows:
  // tim.login({userID: 'your userID', userSig: 'your userSig'});
};
tim.on(TIM.EVENT.SDK_NOT_READY, onSdkNotReady);

(static) MESSAGE_RECEIVED

This event is triggered when the SDK receives a newly pushed one-to-one message, group message, group notification, or group system message. When this event occurs, the access side can traverse event.data to obtain the message list and render it to the UI.

Example
let onMessageReceived = function(event) {
  // event.data - An array that stores the Message objects - [Message]
};
tim.on(TIM.EVENT.MESSAGE_RECEIVED, onMessageReceived);

(static) MESSAGE_MODIFIED

This event is triggered when the SDK receives a notification for message modifications by a third-party callback. When this event occurs, the message sender can traverse event.data to obtain the message list and update the content of the message with the same ID on the UI.
Sample use cases:
1. A one-to-one chat user or group member sends a "Hello World" message, and the message is displayed on the screen. Then the SDK receives a notification indicating that the message has been modified by a third-party callback (for example, the message is changed to "Hello China", and the message received by the peer end or other group members is "Hello China"). In this case, the SDK triggers the MESSAGE_MODIFIED event.
2. The access side traverses the modified message in the event callback, replaces the content of the message with the same ID on the UI (replaces "Hello World" with "Hello China"), and renders and displays the message again.

Note: Before using this event, you need to upgrade your SDK to v2.12.1 or later.

Example
let onMessageModified = function(event) {
  // event.data - An array that stores the Message objects modified by a third-party callback - [Message]
};
tim.on(TIM.EVENT.MESSAGE_MODIFIED, onMessageModified);

(static) MESSAGE_REVOKED

This event is triggered when the SDK receives a notification indicating that messages are recalled. When this event occurs, the access side can traverse event.data to obtain data of the message recall list and renders the recalled messages to the UI. For example, "The peer party has recalled a message" can be displayed if a message is recalled during a one-to-one conversation, and "XXX has recalled a message" can be displayed if a message is recalled during a group conversation.

Note: Before using this event, you need to upgrade your SDK to v2.4.0 or later.

Example
let onMessageRevoked = function(event) {
  // event.data - An array that stores the Message objects - [Message] - The isRevoked value of each Message object is true.
};
tim.on(TIM.EVENT.MESSAGE_REVOKED, onMessageRevoked);

(static) MESSAGE_READ_BY_PEER

This event is triggered when the SDK receives a notification (read receipt) indicating that the peer end has read the message. When this event occurs, the access side can traverse event.data to obtain data of the message recall list and render the recalled messages to the UI. For example, for a one-to-one conversation, the status of the message sent by the current party can be changed from Unread to Read.

Note: Before using this event, you need to upgrade your SDK to v2.7.0 or later. This event is supported only for one-to-one conversations.

Example
let onMessageReadByPeer = function(event) {
  // event.data - An array that stores the Message objects - [Message] - The isPeerRead value of each Message object is true.
};
tim.on(TIM.EVENT.MESSAGE_READ_BY_PEER, onMessageReadByPeer);

(static) CONVERSATION_LIST_UPDATED

This event is triggered when the conversation list is updated. event.data is an array that stores the Conversation objects.

Example
let onConversationListUpdated = function(event) {
  console.log(event.data); // Array that stores Conversation instances
};
tim.on(TIM.EVENT.CONVERSATION_LIST_UPDATED, onConversationListUpdated);

(static) GROUP_LIST_UPDATED

This event is triggered when the SDK group list is updated. The access side can traverse event.data to obtain the group list and render it to the UI.

Example
let onGroupListUpdated = function(event) {
   console.log(event.data);// Array that stores Group instances
};
tim.on(TIM.EVENT.GROUP_LIST_UPDATED, onGroupListUpdated);

(static) GROUP_ATTRIBUTES_UPDATED

This event is triggered when group properties are updated. The access side can traverse event.data to obtain the updated group properties. This event is supported from v2.14.0.

Example
let onGroupAttributesUpdated = function(event) {
   const groupID = event.data.groupID // Group ID
   const groupAttributes = event.data.groupAttributes //Updated group properties
   console.log(event.data);
};
tim.on(TIM.EVENT.GROUP_ATTRIBUTES_UPDATED, onGroupAttributesUpdated);

(static) PROFILE_UPDATED

This event is triggered when the profile of the current user or profiles of friends are changed. event.data is an array that stores Profile objects.

Example
let onProfileUpdated = function(event) {
  console.log(event.data); // Array that stores Profile objects
};
tim.on(TIM.EVENT.PROFILE_UPDATED, onProfileUpdated);

(static) BLACKLIST_UPDATED

This event is triggered when the SDK blocklist is updated.

Example
let onBlacklistUpdated = function(event) {
  console.log(event.data); // Your blocklist. The value is an array that stores userIDs.
};
tim.on(TIM.EVENT.BLACKLIST_UPDATED, onBlacklistUpdated);

(static) FRIEND_LIST_UPDATED

This event is triggered when the friend list is updated.

Example
let onFriendListUpdated = function(event) {
  console.log(event.data);
}
tim.on(TIM.EVENT.FRIEND_LIST_UPDATED, onFriendListUpdated);

(static) FRIEND_GROUP_LIST_UPDATED

This event is triggered when the friend group list is updated.

Example
let onFriendGroupListUpdated = function(event) {
  console.log(event.data);
}
tim.on(TIM.EVENT.FRIEND_GROUP_LIST_UPDATED, onFriendGroupListUpdated);

(static) FRIEND_APPLICATION_LIST_UPDATED

This event is triggered when the SDK friend request list is updated.

Example
let onFriendApplicationListUpdated = function(event) {
  // friendApplicationList - Friend request list - [FriendApplication]
  // unreadCount - Unread friend request count
  const { friendApplicationList, unreadCount } = event.data;
  // Friend requests received by me (friend requests that are sent to you by others)
  const applicationSentToMe = friendApplicationList.filter((friendApplication) => friendApplication.type === TIM.TYPES.SNS_APPLICATION_SENT_TO_ME);
  // Friend requests sent by me (friend requests that you send to others)
  const applicationSentByMe = friendApplicationList.filter((friendApplication) => friendApplication.type === TIM.TYPES.SNS_APPLICATION_SENT_BY_ME);
};
tim.on(TIM.EVENT.FRIEND_APPLICATION_LIST_UPDATED, onFriendApplicationListUpdated);

(static) KICKED_OUT

This event is triggered when the current user is kicked offline.

Example
let onKickedOut = function(event) {
  console.log(event.data.type);
  // TIM.TYPES.KICKED_OUT_MULT_ACCOUNT: the user is kicked offline because the same account logs in from multiple pages on the web client.
  // TIM.TYPES.KICKED_OUT_MULT_DEVICE: the user is kicked offline because the same account logs in from multiple terminals.
  // TIM.TYPES.KICKED_OUT_USERSIG_EXPIRED: the user is kicked offline because the signature expires. Before using this event, you need to upgrade your SDK to v2.4.0 or later.
};
tim.on(TIM.EVENT.KICKED_OUT, onKickedOut);

(static) ERROR

This event is triggered when the SDK encounters an error.

Example
let onError = function(event) {
  // event.data.code - Error code
  // event.data.message - Error message
};
tim.on(TIM.EVENT.ERROR, onError);

(static) NET_STATE_CHANGE

This event is triggered when the network status changes.

Example
let onNetStateChange = function(event) {
  // Supported from v2.5.0
  // event.data.state indicates the current network status. The enumerated values are described as follows:
  // TIM.TYPES.NET_STATE_CONNECTED: already connected to the network
  // TIM.TYPES.NET_STATE_CONNECTING: connecting. This often occurs when the SDK must reconnect due to network jitter. The message "The current network is unstable" or "Connecting..." can be displayed at the access side based on this status.
  // TIM.TYPES.NET_STATE_DISCONNECTED: disconnected. The message "The current network is unavailable" can be displayed at the access side based on this status. The SDK will continue to try to reconnect. If the user network recovers, the SDK will automatically synchronize messages.
};
tim.on(TIM.EVENT.NET_STATE_CHANGE, onNetStateChange);

(static) SDK_RELOAD

This event is triggered when the SDK needs to be reloaded to sync status and messages with the IM server in cases where the network was reconnected after a long disconnection or the Mini Program switched to the foreground after running in the background for a long time. When reloading is completed in such scenarios, the SDK will automatically log the current user in. If the current user has joined an audio-video group (AVChatRoom) before the reloading, the SDK will add the user to audio-video group again after the reloading is successful.
Generally, the access side does not need to listen for and process this event. If the access side needs to pull the messages that are sent or received when the network is disconnected or the Mini Program switched to the background, it can listen for this event and use the getMessageList API to proactively pull historical messages.

Example
// Supported from v2.7.7
let onSDKReload = function(event) {
};
tim.on(TIM.EVENT.SDK_RELOAD, onSDKReload);