SDKsReact Native
Subscribe to user online status
Subscribe to real-time online presence states for specified users with the OpenIM React Native SDK.
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
| Parameter | Type | Required | Description |
|---|---|---|---|
userIDList | string[] | Yes | Array of user IDs whose online status should be monitored. |
Return value
Resolves to an array of UserOnlineState[] representing the initial presence snapshot:
| Field | Type | Description |
|---|---|---|
userID | string | Target user ID and primary reconciliation key. |
status | OnlineState | Presence state: OnlineState.Online or OnlineState.Offline. |
platformIDs | Platform[] (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.
Was this page helpful?