- Current user heartbeat marks the logged-in user online for user and channel presence. It is available on iOS and Android.
- Room heartbeat marks the current user as present in a live room. It is available on iOS, Android, and TypeScript.
Heartbeat intervals are controlled by server-side presence settings. The SDK sends the first heartbeat immediately, then continues on the configured cadence.
Platform Surface
| Heartbeat | TypeScript | iOS | Android | Flutter |
|---|---|---|---|---|
| Current user heartbeat | Not available | client.presence.startHeartbeat() | AmityCoreClient.presence().startHeartbeat() | Not available |
| Room heartbeat | RoomPresenceRepository.startHeartbeat(roomId) | AmityRoomPresenceRepository(roomId:) | AmityCoreClient.newRoomPresenceRepository().roomId(roomId) | Not available |
Parameters
| Operation | Platform | Parameter | Required | Description |
|---|---|---|---|---|
presence.enable / presence().enable | iOS, Android | None | No | Enables user presence for the current user. |
presence.isEnabled / presence().isEnabled | iOS, Android | None | No | Checks whether user presence is enabled for the current user. |
presence.startHeartbeat / presence().startHeartbeat | iOS, Android | None | No | Starts the current user’s network presence heartbeat. |
presence.stopHeartbeat / presence().stopHeartbeat | iOS, Android | None | No | Stops the current user’s network presence heartbeat. |
RoomPresenceRepository.startHeartbeat | TypeScript | roomId | Yes | Room ID where the current user should be counted as present. |
AmityRoomPresenceRepository(roomId:) | iOS | roomId | Yes | Room ID used to create the room presence repository. |
newRoomPresenceRepository().roomId(roomId) | Android | roomId | Yes | Room ID used to create the room presence repository. |
Start the Current User Heartbeat
Use this when your app wants the current user to appear online in user and channel presence.Start a Room Heartbeat
Use room heartbeat only while the current user is watching or participating in a live room.Lifecycle Guidance
Start heartbeat only while the surface is active
Start heartbeat only while the surface is active
Start the current user heartbeat after login when the app wants the user to appear online. Start room heartbeat only while the room screen is visible and the user should count as a viewer.
Stop heartbeat during teardown
Stop heartbeat during teardown
Stop heartbeat when the user logs out, leaves the room, dismisses the screen, or your view model is deallocated. For mobile apps, also stop or pause room heartbeat when the room screen backgrounds.
Handle disabled presence
Handle disabled presence
If presence is disabled for the network, heartbeat start calls can fail. Treat that as a configuration error and hide online-state UI instead of retrying forever.
Related Topics
User Presence
Read and sync user online state after the current user heartbeat is active.
Room Presence
Read live room viewer counts and online room users.