Kotlin: Realtime
Join channels, send and receive messages, follow connection status and catch up after a reconnect with the Kotlin SDK.
Join channels, send and receive messages, follow connection status and catch up after a reconnect. Every call runs as the client's signed-in user, so your project's policies and row-level security apply. Types and members are listed in source order; each one links to its HTTP endpoint where it maps to one.
#Types and members
RealtimeStatus
The same states as the TypeScript and Dart clients: CONNECTING (first attempt), LIVE, RECONNECTING (dropped, retrying with backoff) and CLOSED (closed by you, or refused: signed out, not allowed, misconfigured).
enum class RealtimeStatusValues: CONNECTING, LIVE, RECONNECTING, CLOSED.
RealtimeStatus.OPEN
A property.
val OPEN: RealtimeStatus get()SovariaRealtime
Realtime channels. publish and presence work over HTTP; channel(…) opens a WebSocket that delivers messages and reconnects with backoff. The token never goes in the URL — a one-time ticket does.
class SovariaRealtime(private val client: Sovaria)SovariaRealtime.channel
catchUp: after a reconnect, deliver the messages published while the socket was down (from the channel's replay history) — in order, once each — before new ones.
fun channel(
name: String,
onMessage: (Map<String, Any?>) -> Unit,
onStatus: ((RealtimeStatus) -> Unit)? = null,
catchUp: Boolean = true,
onGap: ((RealtimeGap) -> Unit)? = null,
): RealtimeChannelonGap: messages that were missed and can't be recovered (older than the retained history, or the history couldn't be read).
SovariaRealtime.publish
Publish to a channel over HTTP (no socket needed).
suspend fun publish(channel: String, payload: Map<String, Any?>)SovariaRealtime.replay
Messages after after (by stream_seq), oldest first: {events: [...]}.
suspend fun replay(channel: String, after: Long = 0, limit: Int = 200): Any?SovariaRealtime.presence
Who is in a channel right now.
suspend fun presence(channel: String): Any?SovariaRealtime.closeAll
fun closeAll()RealtimeChannel
One open realtime channel. Reconnects on drop with capped backoff until close().
class RealtimeChannel internal constructor(
private val realtime: SovariaRealtime,
val name: String,
private val onMessage: (Map<String, Any?>) -> Unit,
private val onStatus: ((RealtimeStatus) -> Unit)?,
private val maxBackoffSeconds: Double = 15.0,
private val catchUp: Boolean = true,
private val onGap: ((RealtimeGap) -> Unit)? = null,
)RealtimeChannel.send
Publish a message to everyone on the channel.
suspend fun send(payload: Map<String, Any?>)RealtimeChannel.close
fun close()RealtimeGap
Messages fromSeq..toSeq (by stream_seq) were missed and can't be recovered; toSeq is null when the history couldn't be read. reason: not_retained or replay_failed. Reload state from the source of truth.
data class RealtimeGap(val fromSeq: Long, val toSeq: Long?, val reason: String)