JavaScript SDK: realtime reference
Every method of the realtime service and of channels, with its signature.
RealtimeService#
| Property | Description |
|---|---|
get connectionState(): ConnectionState | Current connection state. |
get isConnected(): boolean | Whether the WebSocket is currently connected. |
| Method | Description |
|---|---|
onStateChange(callback: (state: ConnectionState) => void): () => void | Listen for connection state changes. |
onError(callback: (err: RealtimeConnectionError) => void): () => void | Listen for realtime connection transport errors. |
connect(): void | Ensure the WebSocket connection is open. |
refreshToken(token: string): void | Refresh the JWT token on an existing connection (no disconnect). |
setAuth(token?: string): void | Explicitly defines/refreshes the token used for authorization of private and broadcast channels (parity @supabase/realtime-js setAuth). |
httpBroadcast(channel: string, event: string, payload?: Record<string, unknown>, options?: HttpBroadcastOptions): Promise<AuraResponse<null>> | Sends a broadcast via HTTP (REST), without an open WebSocket connection (parity @supabase/realtime-js). |
setAutoReconnect(enabled: boolean, maxAttempts?: number): void | Enable/disable auto-reconnect (enabled by default). |
disconnect(): void | Disconnect the WebSocket and clean up all channels. |
channel(name: string, options?: ChannelConfig): AuraChannel | Create or retrieve a channel by name. |
removeChannel(channel: string | AuraChannel): void | Remove a channel by name or by AuraChannel instance. |
getChannels(): AuraChannel[] | List active channels. |
removeAllChannels(): void | Remove all channels and subscriptions. |
AuraChannel#
A realtime channel with Supabase-compatible chainable API.
| Property | Description |
|---|---|
readonly name: string | Channel name as passed to realtime.channel(name). |
get fullName(): string | Full channel name with project prefix (for server protocol) |
get isSubscribed(): boolean | Whether this channel has been subscribed. |
| Method | Description |
|---|---|
on<TRow = Record<string, unknown>>(type: 'postgres_changes', filter: PostgresChangesFilter & { event: 'INSERT'; }, callback: (payload: RealtimePostgresInsertPayload<TRow>) => void): AuraChannelSubscriptionon<TRow = Record<string, unknown>>(type: 'postgres_changes', filter: PostgresChangesFilter & { event: 'UPDATE'; }, callback: (payload: RealtimePostgresUpdatePayload<TRow>) => void): AuraChannelSubscriptionon<TRow = Record<string, unknown>>(type: 'postgres_changes', filter: PostgresChangesFilter & { event: 'DELETE'; }, callback: (payload: RealtimePostgresDeletePayload<TRow>) => void): AuraChannelSubscriptionon<TRow = Record<string, unknown>>(type: 'postgres_changes', filter: PostgresChangesFilter, callback: (payload: RealtimePostgresChangesPayload<TRow>) => void): AuraChannelSubscriptionon<TPayload = Record<string, unknown>>(type: 'broadcast', filter: BroadcastFilter, callback: (payload: RealtimeBroadcastEvent<TPayload>) => void): AuraChannelSubscriptionon(type: 'presence', filter: PresenceFilter, callback: (payload: PresenceState | RealtimeEvent | Record<string, unknown>) => void): AuraChannelSubscription | Registers a listener for PostgreSQL (CDC) events with INSERT filtering. |
off(type?: RealtimeListenType, filter?: PostgresChangesFilter | BroadcastFilter | PresenceFilter, callback?: (payload: unknown) => void): this | Removes one or more listeners from the channel without closing the channel or cutting the WebSocket. |
subscribe(callback?: SubscribeCallback, timeoutMs?: number): this | Subscribe to the channel. |
unsubscribe(): Promise<'ok'> | Unsubscribe from the channel. |
send(message: BroadcastPayload): Promise<BroadcastSendStatus> | Sends a broadcast message on the channel. |
track(state: Record<string, unknown>): Promise<'ok' | 'error'> | Track presence state for this client. |
untrack(): Promise<'ok' | 'error'> | Stop tracking presence. |
presenceState(): PresenceState | Get the current presence state for this channel. |
Generated page
This page is generated from the type declarations and comments of the SDK, so it cannot drift from the published code. For worked examples, read the guides.
@aurabase/aurabase-js@0.7.5 · aura@0.3.4↗ Report a problem