RealtimeChannel
Constructors
Section titled “Constructors”new RealtimeChannel()
Section titled “new RealtimeChannel()”new RealtimeChannel(
url,channelName,token,config):RealtimeChannel
Parameters
Section titled “Parameters”| Parameter | Type | Default value |
|---|---|---|
url | string | undefined |
channelName | string | undefined |
token | null | string | null |
config | RealtimeChannelConfig | {} |
Returns
Section titled “Returns”Methods
Section titled “Methods”off(
event,callback):this
Remove a callback
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
event | "DELETE" | "INSERT" | "UPDATE" | "*" |
callback | RealtimeCallback |
Returns
Section titled “Returns”this
on(event, config, callback)
Section titled “on(event, config, callback)”on(
event,config,callback):this
Listen to postgres_changes with optional row-level filtering
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
event | "postgres_changes" | ’postgres_changes’ |
config | PostgresChangesConfig | Configuration including optional filter |
callback | RealtimeCallback | Function to call when changes occur |
Returns
Section titled “Returns”this
This channel for chaining
Example
Section titled “Example”channel.on('postgres_changes', { event: '*', schema: 'public', table: 'jobs', filter: 'created_by=eq.user123'}, (payload) => { console.log('Job updated:', payload)})on(event, callback)
Section titled “on(event, callback)”on(
event,callback):this
Listen to a specific event type (backwards compatibility)
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
event | "DELETE" | "INSERT" | "UPDATE" | "*" | The event type (INSERT, UPDATE, DELETE, or ’*’ for all) |
callback | RealtimeCallback | The callback function |
Returns
Section titled “Returns”this
This channel for chaining
Example
Section titled “Example”channel.on('INSERT', (payload) => { console.log('New record inserted:', payload.new_record)})on(event, config, callback)
Section titled “on(event, config, callback)”on(
event,config,callback):this
Listen to broadcast messages
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
event | "broadcast" | ’broadcast’ |
config | object | Configuration with event name |
config.event | string | - |
callback | BroadcastCallback | Function to call when broadcast received |
Returns
Section titled “Returns”this
This channel for chaining
Example
Section titled “Example”channel.on('broadcast', { event: 'cursor-pos' }, (payload) => { console.log('Cursor moved:', payload)})on(event, config, callback)
Section titled “on(event, config, callback)”on(
event,config,callback):this
Listen to presence events
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
event | "presence" | ’presence’ |
config | object | Configuration with event type (sync, join, leave) |
config.event | "sync" | "join" | "leave" | - |
callback | PresenceCallback | Function to call when presence changes |
Returns
Section titled “Returns”this
This channel for chaining
Example
Section titled “Example”channel.on('presence', { event: 'sync' }, (payload) => { console.log('Presence synced:', payload)})presenceState()
Section titled “presenceState()”presenceState():
Record<string,PresenceState[]>
Get current presence state for all users on this channel
Returns
Section titled “Returns”Record<string, PresenceState[]>
Current presence state
Example
Section titled “Example”const state = channel.presenceState()console.log('Online users:', Object.keys(state).length)send()
Section titled “send()”send(
message):Promise<"error"|"ok">
Send a broadcast message to all subscribers on this channel
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
message | BroadcastMessage | Broadcast message with type, event, and payload |
Returns
Section titled “Returns”Promise<"error" | "ok">
Promise resolving to status
Example
Section titled “Example”await channel.send({ type: 'broadcast', event: 'cursor-pos', payload: { x: 100, y: 200 }})subscribe()
Section titled “subscribe()”subscribe(
callback?,_timeout?):this
Subscribe to the channel
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
callback? | (status, err?) => void | Optional status callback (Supabase-compatible) |
_timeout? | number | Optional timeout in milliseconds (currently unused) |
Returns
Section titled “Returns”this
track()
Section titled “track()”track(
state):Promise<"error"|"ok">
Track user presence on this channel
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
state | PresenceState | Presence state to track |
Returns
Section titled “Returns”Promise<"error" | "ok">
Promise resolving to status
Example
Section titled “Example”await channel.track({ user_id: 123, status: 'online'})unsubscribe()
Section titled “unsubscribe()”unsubscribe(
timeout?):Promise<"error"|"ok"|"timed out">
Unsubscribe from the channel
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
timeout? | number | Optional timeout in milliseconds |
Returns
Section titled “Returns”Promise<"error" | "ok" | "timed out">
Promise resolving to status string (Supabase-compatible)
untrack()
Section titled “untrack()”untrack():
Promise<"error"|"ok">
Stop tracking presence on this channel
Returns
Section titled “Returns”Promise<"error" | "ok">
Promise resolving to status
Example
Section titled “Example”await channel.untrack()