Skip to main content
A heartbeat tells social.plus that the current user is still active. There are two heartbeat surfaces:
  • 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

HeartbeatTypeScriptiOSAndroidFlutter
Current user heartbeatNot availableclient.presence.startHeartbeat()AmityCoreClient.presence().startHeartbeat()Not available
Room heartbeatRoomPresenceRepository.startHeartbeat(roomId)AmityRoomPresenceRepository(roomId:)AmityCoreClient.newRoomPresenceRepository().roomId(roomId)Not available

Parameters

OperationPlatformParameterRequiredDescription
presence.enable / presence().enableiOS, AndroidNoneNoEnables user presence for the current user.
presence.isEnabled / presence().isEnablediOS, AndroidNoneNoChecks whether user presence is enabled for the current user.
presence.startHeartbeat / presence().startHeartbeatiOS, AndroidNoneNoStarts the current user’s network presence heartbeat.
presence.stopHeartbeat / presence().stopHeartbeatiOS, AndroidNoneNoStops the current user’s network presence heartbeat.
RoomPresenceRepository.startHeartbeatTypeScriptroomIdYesRoom ID where the current user should be counted as present.
AmityRoomPresenceRepository(roomId:)iOSroomIdYesRoom ID used to create the room presence repository.
newRoomPresenceRepository().roomId(roomId)AndroidroomIdYesRoom 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.
let isEnabled = try await client.presence.isEnabled()
if !isEnabled {
    try await client.presence.enable()
}

try await client.presence.startHeartbeat()

// Call when the user should no longer appear online.
client.presence.stopHeartbeat()

Start a Room Heartbeat

Use room heartbeat only while the current user is watching or participating in a live room.
let roomPresence = AmityRoomPresenceRepository(roomId: roomId)

try await roomPresence.startHeartbeat()

// Call when the viewer leaves the room.
roomPresence.stopHeartbeat()

Lifecycle Guidance

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 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.
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.

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.