You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/docs/content/guides/realtime/broadcast.mdx
+30Lines changed: 30 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,27 @@ description: 'Send low-latency messages using the client libs, REST, or your Dat
6
6
7
7
You can use Realtime Broadcast to send low-latency messages between users. Messages can be sent using the client libraries, REST APIs, or directly from your database.
8
8
9
+
## How Broadcast works
10
+
11
+
The way Broadcast works changes based on the channel you are using:
12
+
13
+
- From REST API will receive an HTTP request which then will be sent via WebSocket to connected clients
14
+
- From Client libraries we have an established WebSocket connection and we use that to send a message to the server which then will be sent via WebSocket to connected clients
15
+
- From Database we add a new entry to `realtime.messages` where we have logical replication set to listen for changes which then will be sent via WebSocket to connected clients
16
+
17
+
<Admonitiontype="note">
18
+
19
+
The public flag (the last argument in `realtime.send(payload, event, topic, is_private))` only affects who can subscribe to the topic not who can read messages from the database.
20
+
21
+
- Public (false) → Anyone can subscribe to that topic without authentication
22
+
- Private (true) → Only authenticated clients can subscribe to that topic
23
+
24
+
However, regardless of whether it's public or private, the Realtime service connects to your database as the authenticated Supabase Admin role.
25
+
26
+
</Admonition>
27
+
28
+
For Authorization we do insert a message and try to read it and then we it back as way to verify that the RLS policies set by the user are being respected by the user joining the channel but this messages won't be sent to the user. You can read more about it in the [Authorization](/docs/guides/realtime/authorization) docs
29
+
9
30
## Subscribe to messages
10
31
11
32
You can use the Supabase client libraries to receive Broadcast messages.
@@ -384,6 +405,7 @@ You can use the Supabase client libraries to send Broadcast messages.
The realtime.send function in the database includes a flag that determines whether the broadcast is private or public, and client channels also have the same configuration. For broadcasts to work correctly, these settings must match a public broadcast will only reach public channels, and a private broadcast will only reach private ones.
439
+
440
+
By default, all database broadcasts are private, meaning clients must authenticate to receive them. If the database sends a public message but the client subscribes to a private channel, the message won't be delivered since private channels only accept signed, authenticated messages.
441
+
442
+
</Admonition>
443
+
414
444
It's a common use case to broadcast messages when a record is created, updated, or deleted. We provide a helper function specific to this use case, `realtime.broadcast_changes()`. For more details, check out the [Subscribing to Database Changes](/docs/guides/realtime/subscribing-to-database-changes) guide.
0 commit comments