Supabase allows broadcasting custom events to clients subscribed to a channel. What happens when you broadcast a custom event on a channel?
Think about how broadcasting works in a chat room: everyone in the room hears the message.
Broadcasting a custom event sends the event and its payload to all clients subscribed to the same channel, enabling real-time communication.
Choose the correct JavaScript code to broadcast a custom event 'update' with payload {count: 5} on a Supabase channel named 'my-channel'.
Look for the method that explicitly means sending to all subscribers.
The broadcast method sends a custom event to all clients subscribed to the channel. Other methods like send, emit, or push are not valid for broadcasting in Supabase.
In a system using Supabase real-time channels, which architecture pattern best ensures that custom broadcast events are reliably delivered to all clients even if some disconnect temporarily?
Think about how to handle clients that disconnect and reconnect.
Supabase channels support reconnection, but to ensure no events are missed, server-side logging and replay on reconnect is needed. Broadcasting only once without retries risks lost events. HTTP requests are not real-time broadcasts. Multiple channels per client add complexity without improving reliability.
When broadcasting custom events on Supabase channels, what is the main security risk to consider?
Consider who can listen to the events and what data they get.
If channel subscriptions are not properly secured, unauthorized clients can listen to sensitive broadcast events. Malformed events or delays are less critical security issues. Duplicate events affect user experience but not security.
To maintain clarity and avoid conflicts, what is the best practice for naming custom events broadcasted on Supabase channels?
Think about readability and consistency in naming conventions.
Descriptive, lowercase names with underscores improve readability and reduce naming conflicts. Generic or random names are confusing. Uppercase with spaces can cause parsing issues.
