Browse SDKs · React Native
Platform
SDKsReact Native

Subscribe to user online status

Subscribe to real-time online presence states for specified users with the OpenIM React Native SDK.

Copy

Subscribe to real-time online presence states for target users. Limit subscriptions to currently visible contacts or active chat peers to minimize bandwidth:

const userIDs = [...new Set(visibleUserIDs.filter(Boolean))];
const states = await OpenIMSDK.subscribeUsersStatus(userIDs);

Parameters

ParameterTypeRequiredDescription
userIDListstring[]YesArray of user IDs whose online status should be monitored.

Return value

Resolves to an array of UserOnlineState[] representing the initial presence snapshot:

FieldTypeDescription
userIDstringTarget user ID and primary reconciliation key.
statusOnlineStatePresence state: OnlineState.Online or OnlineState.Offline.
platformIDsPlatform[] (optional)Array of platform clients currently connected for this user.

Online status reflects an active WebSocket connection to OpenIMServer; it does not indicate whether the user is actively viewing a specific screen.

Listen for status changes

When a subscribed user connects, disconnects, or changes platforms, the SDK emits OnUserStatusChanged:

const handleStatusChanged = (state: UserOnlineState) => {
  // Update UI presence indicator matching state.userID
};

// Register listener
OpenIMSDK.on(OpenIMEvent.OnUserStatusChanged, handleStatusChanged);

// Remove listener
OpenIMSDK.off(OpenIMEvent.OnUserStatusChanged, handleStatusChanged);

When navigating away or logging out, unsubscribe and remove the listener.