RealtimeChannel
A channel is the basic building block of Realtime and narrows the scope of data flow to subscribed clients. You can think of a channel as a chatroom where participants are able to see who's online and send and receive messages.
§Constructors
Creates a channel that can broadcast messages, sync presence, and listen to Postgres changes.
The topic determines which realtime stream you are subscribing to. Config options let you enable acknowledgement for broadcasts, presence tracking, or private channels.
import RealtimeClient from '@supabase/realtime-js'
const client = new RealtimeClient('https://xyzcompany.supabase.co/realtime/v1', {
params: { apikey: 'public-anon-key' },
})
const channel = new RealtimeChannel('realtime:public:messages', { config: {} }, client)
§Properties
§Methods
Sends a broadcast message explicitly via REST API.
This method always uses the REST API endpoint regardless of WebSocket connection state. Useful when you want to guarantee REST delivery or when gradually migrating from implicit REST fallback.
The name of the broadcast event
Payload to be sent (required)
Options including timeout
Promise resolving to object with success status, and error details if failed
Creates an event handler that listens to changes.
The following is placed here to display on supabase.com/docs/reference/javascript/subscribe.
One of "broadcast", "presence", or "postgres_changes".
Custom object specific to the Realtime feature detailing which payloads to receive.
Function to be invoked when event handler is triggered.
Returns the current presence state for this channel.
The shape is a map keyed by presence key (for example a user id) where each entry contains the tracked metadata for that user.
Sends a message into the channel.
Arguments to send to channel
The type of event to send
The name of the event being sent
Payload to be sent
Options to be used during the send process
Subscribe registers your client with the server
Sends the supplied payload to the presence tracker so other subscribers can see that this
client is online. Use untrack to stop broadcasting presence for the same key.
Leaves the channel.
Unsubscribes from server events, and instructs channel to terminate on server. Triggers onClose() hooks.
To receive leave acknowledgements, use the a receive hook to bind to the server ack, ie:
channel.unsubscribe().receive("ok", () => alert("left!") )
Removes the current presence state for this client.