Realtime

Plugin for interacting with the supabase realtime api

To use it you need to install it to the SupabaseClient:

val supabase = createSupabaseClient(supabaseUrl, supabaseKey) {
install(Realtime)
}

You can then create a channel:

val channel = supabase.realtime.channel("channelId")

Then listen to events on the channel:

val productChangeFlow = channel.postgrestChangeFlow<PostgrestAction.Insert>(schema = "public") {
table = "products"
}.map { it.decodeRecord<Product>() }

And at last you have to subscribe to the channel:

channel.subscribe()

Types

Link copied to clipboard
Link copied to clipboard
data class Config(var websocketConfig: WebSockets.Config.() -> Unit = {}, var secure: Boolean? = null, var heartbeatInterval: Duration = 15.seconds, var reconnectDelay: Duration = 7.seconds, var disconnectOnSessionLoss: Boolean = true, var connectOnSubscribe: Boolean = true, var websocketFactory: RealtimeWebsocketFactory? = null, var disconnectOnNoSubscriptions: Boolean = true) : MainConfig, CustomSerializationConfig
Link copied to clipboard

The current status of the realtime connection

Properties

Link copied to clipboard
abstract val apiVersion: Int
Link copied to clipboard
abstract val config: Realtime.Config
Link copied to clipboard
abstract val pluginKey: String
Link copied to clipboard
Link copied to clipboard
abstract val status: StateFlow<Realtime.Status>

The current status of the realtime connection

Link copied to clipboard

A map of all active the subscriptions

Link copied to clipboard

Functions

Link copied to clipboard
abstract fun Realtime.addChannel(channel: RealtimeChannel)
Link copied to clipboard
abstract suspend fun block()

Blocks your current coroutine until the websocket connection is closed

Link copied to clipboard
inline fun Realtime.channel(channelId: String, builder: RealtimeChannelBuilder.() -> Unit = {}): RealtimeChannel

Creates a new RealtimeChannel

Link copied to clipboard
open suspend fun close()
Link copied to clipboard
abstract suspend fun connect()

Connects to the realtime websocket. The url will be taken from the custom provided Realtime.Config.customUrl or SupabaseClient

Link copied to clipboard
abstract fun disconnect()

Disconnects from the realtime websocket

Link copied to clipboard
open fun init()
Link copied to clipboard
abstract suspend fun parseErrorResponse(response: HttpResponse): RestException
Link copied to clipboard
abstract suspend fun removeAllChannels()

Unsubscribes and removes all channels from the subscriptions

Link copied to clipboard
abstract suspend fun removeChannel(channel: RealtimeChannel)

Unsubscribes and removes a channel from the subscriptions

Link copied to clipboard
open fun resolveUrl(path: String): String
Link copied to clipboard
abstract suspend fun send(message: RealtimeMessage)

Sends a message to the realtime websocket