Use Broadcast to send ephemeral messages
mainBroadcast allows sending low-latency, ephemeral messages between clients.
Configuration Options:
ack(bool): Iftrue, thesend_broadcastcall will resolve once the server acknowledges receipt.self(bool): Iftrue, the client that sent the message will also receive it.private(bool): Iftrue, Row Level Security (RLS) is used to determine connection permissions.
API Methods:
channel.on_broadcast(event, callback): Register a listener for a specific event name.channel.send_broadcast(event, payload): Send a message with a specific event name and JSON payload.
# Example setup
channel = client.channel(
"broadcast-test", {"config": {"broadcast": {"ack": False, "self": False}}}
)
# Listen for events
await channel.on_broadcast("some-event", lambda payload: print(payload)).subscribe()
# Send events
await channel.send_broadcast("some-event", {"hello": "world"})