Browse SDKs · React Native
SDKsReact Native

Events overview

Understand the OpenIM React Native SDK event model, event categories, and listener lifecycle.

Copy

Event model

The OpenIM React Native SDK uses OpenIMEvent to define event names and a shared listener interface to report connection state, data changes, and business signaling.

Call OpenIMSDK.on() to register a listener and OpenIMSDK.off() to remove it. Event names can use enum values from OpenIMEvent or the corresponding event strings. When using a string, it must exactly match the event name defined by the SDK.

function handleEvent(payload: unknown) {
  // Update application state from the event payload.
}

// Set listener
OpenIMSDK.on(OpenIMEvent.OnConversationChanged, handleEvent);
// Or use the event string
OpenIMSDK.on("onConversationChanged", handleEvent);

// Remove listener
OpenIMSDK.off(OpenIMEvent.OnConversationChanged, handleEvent);
// Or use the event string
OpenIMSDK.off("onConversationChanged", handleEvent);

The callback parameter for each event is defined by the SDK declaration. It can be an entity, an array, a progress value, or error information. See the corresponding feature page for the exact parameter format and handling example.

Event categories

React Native SDK events are grouped by business domain:

Event categoryTypical eventsDescription
Connection and sign-in stateOnConnecting, OnConnectSuccess, OnConnectFailed, OnKickedOffline, OnUserTokenExpired, OnUserTokenInvalidConnection, connection failure, forced sign-out, and token state changes.
Initial synchronizationOnSyncServerStart, OnSyncServerProgress, OnSyncServerFinish, OnSyncServerFailedThe lifecycle of server data synchronization after sign-in.
Users and online statusOnSelfInfoUpdated, OnUserStatusChangedChanges to the current user's profile and user online status.
Friends and blacklistOnFriendAdded, OnFriendDeleted, OnFriendInfoChanged, OnFriendApplicationAdded, OnBlackAddedChanges to friend relationships, friend applications, and the blacklist.
Conversations and unread stateOnNewConversation, OnConversationChanged, OnTotalUnreadMessageCountChanged, OnInputStatusChangedConversation list, unread count, and typing state changes.
Conversation groupsOnConversationGroupAdded, OnConversationGroupChanged, OnConversationGroupDeletedConversation groups and their membership changes.
Groups and membersOnGroupInfoChanged, OnGroupMemberAdded, OnGroupMemberDeleted, OnGroupApplicationAdded, OnJoinedGroupAddedGroup profile, member, application, and joined-group changes.
MessagesOnRecvNewMessage, OnMsgDeleted, OnNewRecvMessageRevoked, OnMessageModified, OnRecvC2CReadReceiptNew messages, deletions, revocations, modifications, and one-to-one read receipts.
File uploadsUploadOnProgress, UploadCompleteFile upload progress and completion.
Audio and video callsOnReceiveNewInvitation, OnInviteeAccepted, OnInvitationCancelled, OnHangUp, OnReceiveCustomSignalCall invitations, participant state, and call signaling changes.
Custom business messagesOnRecvCustomBusinessMessageCustom business messages.

Registration timing and lifecycle

The React Native SDK allows global listeners to be registered at any time. It starts delivering connection, synchronization, and business data events after initSDK() and sign-in; register listeners before the operation whose events you need to receive.

The React Native SDK supports multiple listeners for the same event. Every registered listener receives the event, unlike the single-listener mechanism in the Flutter and Android SDKs, where a later listener replaces the earlier one. Even though multiple listeners are supported, register and manage callbacks centrally in the application so that rendering or re-entering a component does not register the same business handler repeatedly.

Keep listener functions in stable references. When logging out, switching accounts, or destroying related state, call off() with the same event name and function reference used for registration.

Connection and initial synchronization events

Connection events report the SDK connection state:

EventDescription
OnConnectingThe SDK starts connecting to the server.
OnConnectSuccessThe SDK connects successfully.
OnConnectFailedThe connection fails and error information is provided.
OnKickedOfflineThe current account signs in on another client or is forced offline by the server.
OnUserTokenExpiredThe current login token has expired.
OnUserTokenInvalidThe current login token is invalid.

After sign-in, the SDK reports initial synchronization through these events:

EventDescription
OnSyncServerStartSynchronization starts.
OnSyncServerProgressThe current synchronization progress.
OnSyncServerFinishThe current synchronization completes.
OnSyncServerFailedThe current synchronization fails.

After synchronization completes, query the data needed by the current interface again. Later user, friend, conversation, group, message, and call changes are reported by the corresponding business events.

Handle events by domain

The feature pages below provide complete parameter descriptions and listener examples: