RealtimeChannel

sealed interface RealtimeChannel(source)

Represents a realtime channel

Types

Link copied to clipboard
object Companion
Link copied to clipboard

Represents the status of a channel

Properties

Link copied to clipboard
Link copied to clipboard
abstract val realtime: Realtime

The realtime instance

Link copied to clipboard
abstract val status: StateFlow<RealtimeChannel.Status>

The status of the channel as a StateFlow

Link copied to clipboard
Link copied to clipboard
abstract val topic: String

The topic of the channel

Functions

Link copied to clipboard
Link copied to clipboard
abstract suspend fun broadcast(event: String, message: JsonObject)

Sends a message to everyone who joined the channel. Can be used even if you aren't connected to the channel.

Link copied to clipboard
inline suspend fun <T : Any> RealtimeChannel.broadcast(event: String, message: T)

Sends a message to everyone who joined the channel. Can be used even if you aren't connected to the channel.

Link copied to clipboard
inline fun <T : Any> RealtimeChannel.broadcastFlow(event: String): Flow<T>

Broadcasts can be messages sent by other clients within the same channel under a specific event.

Link copied to clipboard
abstract fun <T : Any> RealtimeChannel.broadcastFlowInternal(type: KType, event: String): Flow<T>

Non-inline variant of broadcastFlow for implementation and mocking purposes

Link copied to clipboard
inline fun <T : PostgresAction> RealtimeChannel.postgresChangeFlow(schema: String, noinline filter: PostgresChangeFilter.() -> Unit = {}): Flow<T>

Listen for postgres changes in a channel.

Link copied to clipboard
abstract fun <T : PostgresAction> RealtimeChannel.postgresChangeFlowInternal(action: KClass<T>, schema: String, filter: PostgresChangeFilter.() -> Unit = {}): Flow<T>

Non-inline variant of postgresChangeFlow for implementation and mocking purposes

Link copied to clipboard
inline fun <Data : Any> RealtimeChannel.postgresListDataFlow(schema: String = "public", table: String, filter: FilterOperation? = null, primaryKey: PrimaryKey<Data>): Flow<List<Data>>
inline fun <Data : Any> RealtimeChannel.postgresListDataFlow(schema: String = "public", table: String, filter: FilterOperation? = null, primaryKeys: List<PrimaryKey<Data>>): Flow<List<Data>>
@JvmName(name = "postgresListDataFlowMultiplePks")
inline fun <Data : Any, Value> RealtimeChannel.postgresListDataFlow(schema: String = "public", table: String, filter: FilterOperation? = null, primaryKeys: List<KProperty1<Data, Value>>): Flow<List<Data>>
inline fun <Data : Any, Value> RealtimeChannel.postgresListDataFlow(schema: String = "public", table: String, filter: FilterOperation? = null, primaryKey: KProperty1<Data, Value>): Flow<List<Data>>

This function retrieves the initial data from the table and then listens for changes. It automatically handles inserts, updates and deletes.

Link copied to clipboard
inline suspend fun <Data : Any> RealtimeChannel.postgresSingleDataFlow(schema: String = "public", table: String, primaryKey: PrimaryKey<Data>, crossinline filter: PostgrestFilterBuilder.() -> Unit): Flow<Data>
inline suspend fun <Data, Value> RealtimeChannel.postgresSingleDataFlow(schema: String = "public", table: String, primaryKey: KProperty1<Data, Value>, crossinline filter: PostgrestFilterBuilder.() -> Unit): Flow<Data>

This function retrieves the initial data for a single value and then listens for changes on that value. It automatically handles updates and closes the flow on the delete event.

Link copied to clipboard
abstract fun presenceChangeFlow(): Flow<PresenceAction>

Listen for clients joining / leaving the channel using presences

Link copied to clipboard

Listens for presence changes and caches the presences based on their keys. This function automatically handles joins and leaves.

Link copied to clipboard
Link copied to clipboard
abstract suspend fun subscribe(blockUntilSubscribed: Boolean = false)

Subscribes to the channel

Link copied to clipboard
abstract suspend fun track(state: JsonObject)

Store an object in your presence's state. Other clients can get this data when you either join or leave the channel. Use this method again to update the state.

Link copied to clipboard
inline suspend fun <T : Any> RealtimeChannel.track(state: T)

Store an object in your presence's state. Other clients can get this data when you either join or leave the channel. Use this method again to update the state.

Link copied to clipboard
abstract suspend fun unsubscribe()

Unsubscribes from the channel

Link copied to clipboard
abstract suspend fun untrack()

Removes the object from your presence's state

Link copied to clipboard
abstract suspend fun updateAuth(jwt: String)

Updates the JWT token for this client

Link copied to clipboard
abstract fun updateStatus(status: RealtimeChannel.Status)