Skip to content

RealtimeChannel

new RealtimeChannel(url, channelName, token, config): RealtimeChannel

ParameterTypeDefault value
urlstringundefined
channelNamestringundefined
tokennull | stringnull
configRealtimeChannelConfig{}

RealtimeChannel

off(event, callback): this

Remove a callback

ParameterType
event"DELETE" | "INSERT" | "UPDATE" | "*"
callbackRealtimeCallback

this


on(event, config, callback): this

Listen to postgres_changes with optional row-level filtering

ParameterTypeDescription
event"postgres_changes"’postgres_changes’
configPostgresChangesConfigConfiguration including optional filter
callbackRealtimeCallbackFunction to call when changes occur

this

This channel for chaining

channel.on('postgres_changes', {
event: '*',
schema: 'public',
table: 'jobs',
filter: 'created_by=eq.user123'
}, (payload) => {
console.log('Job updated:', payload)
})

on(event, callback): this

Listen to a specific event type (backwards compatibility)

ParameterTypeDescription
event"DELETE" | "INSERT" | "UPDATE" | "*"The event type (INSERT, UPDATE, DELETE, or ’*’ for all)
callbackRealtimeCallbackThe callback function

this

This channel for chaining

channel.on('INSERT', (payload) => {
console.log('New record inserted:', payload.new_record)
})

on(event, config, callback): this

Listen to broadcast messages

ParameterTypeDescription
event"broadcast"’broadcast’
configobjectConfiguration with event name
config.eventstring-
callbackBroadcastCallbackFunction to call when broadcast received

this

This channel for chaining

channel.on('broadcast', { event: 'cursor-pos' }, (payload) => {
console.log('Cursor moved:', payload)
})

on(event, config, callback): this

Listen to presence events

ParameterTypeDescription
event"presence"’presence’
configobjectConfiguration with event type (sync, join, leave)
config.event"sync" | "join" | "leave"-
callbackPresenceCallbackFunction to call when presence changes

this

This channel for chaining

channel.on('presence', { event: 'sync' }, (payload) => {
console.log('Presence synced:', payload)
})

presenceState(): Record<string, PresenceState[]>

Get current presence state for all users on this channel

Record<string, PresenceState[]>

Current presence state

const state = channel.presenceState()
console.log('Online users:', Object.keys(state).length)

send(message): Promise<"error" | "ok">

Send a broadcast message to all subscribers on this channel

ParameterTypeDescription
messageBroadcastMessageBroadcast message with type, event, and payload

Promise<"error" | "ok">

Promise resolving to status

await channel.send({
type: 'broadcast',
event: 'cursor-pos',
payload: { x: 100, y: 200 }
})

subscribe(callback?, _timeout?): this

Subscribe to the channel

ParameterTypeDescription
callback?(status, err?) => voidOptional status callback (Supabase-compatible)
_timeout?numberOptional timeout in milliseconds (currently unused)

this


track(state): Promise<"error" | "ok">

Track user presence on this channel

ParameterTypeDescription
statePresenceStatePresence state to track

Promise<"error" | "ok">

Promise resolving to status

await channel.track({
user_id: 123,
status: 'online'
})

unsubscribe(timeout?): Promise<"error" | "ok" | "timed out">

Unsubscribe from the channel

ParameterTypeDescription
timeout?numberOptional timeout in milliseconds

Promise<"error" | "ok" | "timed out">

Promise resolving to status string (Supabase-compatible)


untrack(): Promise<"error" | "ok">

Stop tracking presence on this channel

Promise<"error" | "ok">

Promise resolving to status

await channel.untrack()