By default, Broadcast and Presence are enabled for all projects.
Presence is automatically enabled when you attach presence callbacks (on_presence_sync(), on_presence_join(), or on_presence_leave()). If you add presence callbacks to an already joined channel, the channel will automatically resubscribe with presence enabled.
By default, listening to database changes is disabled for new projects due to database performance and security concerns. You can turn it on by managing Realtime's replication.
You can receive the "previous" data for updates and deletes by setting the table's REPLICA IDENTITY to FULL (e.g., ALTER TABLE your_table REPLICA IDENTITY FULL;).
Row level security is not applied to delete statements. When RLS is enabled and replica identity is set to full, only the primary key is sent to clients.
Examples
Listen to broadcast messages
channel = supabase.channel("room1")
def on_subscribe(status, err):
if status == RealtimeSubscribeStates.SUBSCRIBED:
asyncio.create_task(channel.send_broadcast(
"cursor-pos",
{"x": random.random(), "y": random.random()}
))
def handle_broadcast(payload):
print("Cursor position received!", payload)
await channel.on_broadcast(event="cursor-pos", callback=handle_broadcast).subscribe(on_subscribe)