diff --git a/apps/docs/content/guides/realtime/authorization.mdx b/apps/docs/content/guides/realtime/authorization.mdx index 437dd724acc..a10121f12ed 100644 --- a/apps/docs/content/guides/realtime/authorization.mdx +++ b/apps/docs/content/guides/realtime/authorization.mdx @@ -183,6 +183,19 @@ Then, to join a topic with RLS enabled, instantiate the Channel with the `privat print("Connected!") ``` + + + ```kotlin + val channel = supabase.channel("room-1") { + isPrivate = true + } + channel.broadcastFlow(event = "test").onEach { + println(it) + }.launchIn(scope) // launch in your coroutine scope + channel.subscribe(blockUntilSubscribed = true) + println("Connected!") + ``` + ```py diff --git a/apps/docs/spec/supabase_kt_v3.yml b/apps/docs/spec/supabase_kt_v3.yml index 76b31398e9a..b375a697e46 100644 --- a/apps/docs/spec/supabase_kt_v3.yml +++ b/apps/docs/spec/supabase_kt_v3.yml @@ -4643,8 +4643,6 @@ functions: }.launchIn(coroutineScope) // launch a new coroutine to collect the flow channel.subscribe(blockUntilSubscribed = true) - - channel.broadcast(event = "message", Message("I joined!", "John")) ``` - id: listen-to-presence-updates name: Listen to presence updates @@ -4830,7 +4828,41 @@ functions: You have two methods you can use if you want to listen for updates on a specific database row: - `postgresSingleDataFlow` fetches the initial data matching the filter and then emits updates based on realtime events. - `postgresChangeFlow` emits the raw data received by realtime. To filter the realtime queries, use the `filter` method. - + - id: broadcast-message + title: broadcastMessage() + description: | + Broadcast a message to all connected clients to a channel. + notes: | + - When using REST you don't need to subscribe to the channel + $ref: '@supabase/realtime-js.RealtimeChannel.send' + examples: + - id: send-a-message + name: Send a message via websocket + isSpotlight: true + code: | + ```kotlin + val channel = supabase.channel("room1") + channel.subscribe(blockUntilSubscribed = true) + channel.broadcast("cursor-pos", message = buildJsonObject { + put("x", 10) + put("y", 20) + }) + ``` + response: | + ``` + ok | timed out | error + ``` + - id: send-a-message-via-rest + name: Send a message via REST + isSpotlight: true + code: | + ```kotlin + val channel = supabase.channel("room1") + channel.broadcast("cursor-pos", message = buildJsonObject { + put("x", 10) + put("y", 20) + }) + ``` - id: remove-channel description: | Unsubscribes and removes Realtime channel from Realtime client.