Liking cljdoc? Tell your friends :D

supabase.realtime

Public API for Supabase Realtime: WebSocket-based postgres_changes, broadcast, and presence subscriptions.

Quick start

(require '[supabase.core.client :as sc]
         '[supabase.realtime :as rt])

(def client (sc/make-client "https://abc.supabase.co" "anon-key"))
(def conn   (rt/connect client {:on-error println}))

(def ch (rt/channel conn "room:lobby"
                    {:config {:broadcast {:self false}}}))

(rt/on ch :postgres-changes
       {:event :insert :schema "public" :table "users"}
       (fn [payload] (println "row" payload)))

(rt/on ch :broadcast {:event "typing"}
       (fn [payload] (println "typing" payload)))

(rt/subscribe ch)
(rt/broadcast ch "typing" {:user "alice"})
(rt/track    ch {:online_at (System/currentTimeMillis)})

(rt/unsubscribe ch)
(rt/disconnect conn)

v0.1.0 scope

In: postgres_changes, broadcast send/receive, basic presence, manual set-auth, heartbeat, multi-channel per connection.

Out (deferred): auto-reconnect, broadcast ack/wait_for_ack, HTTP fallback, binary v2 protocol, exponential backoff, auto token refresh.

Public API for Supabase Realtime: WebSocket-based postgres_changes,
broadcast, and presence subscriptions.

## Quick start

    (require '[supabase.core.client :as sc]
             '[supabase.realtime :as rt])

    (def client (sc/make-client "https://abc.supabase.co" "anon-key"))
    (def conn   (rt/connect client {:on-error println}))

    (def ch (rt/channel conn "room:lobby"
                        {:config {:broadcast {:self false}}}))

    (rt/on ch :postgres-changes
           {:event :insert :schema "public" :table "users"}
           (fn [payload] (println "row" payload)))

    (rt/on ch :broadcast {:event "typing"}
           (fn [payload] (println "typing" payload)))

    (rt/subscribe ch)
    (rt/broadcast ch "typing" {:user "alice"})
    (rt/track    ch {:online_at (System/currentTimeMillis)})

    (rt/unsubscribe ch)
    (rt/disconnect conn)

## v0.1.0 scope

In:  postgres_changes, broadcast send/receive, basic presence,
     manual `set-auth`, heartbeat, multi-channel per connection.

Out (deferred): auto-reconnect, broadcast ack/wait_for_ack, HTTP fallback,
     binary v2 protocol, exponential backoff, auto token refresh.
raw docstring

broadcastclj

(broadcast ch event payload)

Sends a broadcast message on ch. Buffered until the channel joins. Returns ch.

Sends a broadcast message on `ch`. Buffered until the channel joins.
Returns `ch`.
sourceraw docstring

channelclj

(channel conn topic)
(channel conn topic opts)

Returns a channel value bound to conn + topic. No network I/O.

opts may include :config (broadcast/presence/private). The channel is registered in connection state so subsequent on / subscribe calls can find it. Returns the channel map or an anomaly.

Returns a channel value bound to `conn` + `topic`. No network I/O.

`opts` may include `:config` (broadcast/presence/private). The channel
is registered in connection state so subsequent `on` / `subscribe` calls
can find it. Returns the channel map or an anomaly.
sourceraw docstring

connectclj

(connect client)
(connect client opts)

Opens a Realtime connection for client. See supabase.realtime.connection/connect for options.

Opens a Realtime connection for `client`. See
`supabase.realtime.connection/connect` for options.
sourceraw docstring

disconnectclj

(disconnect c)

Closes the connection. Idempotent.

Closes the connection. Idempotent.
sourceraw docstring

onclj

(on ch binding-type filter callback)

Registers a binding on ch. Returns the channel value (for threading) or an anomaly on validation failure.

Binding types: :postgres-changes — filter {:event :insert/:update/:delete/:all :schema "public" :table "users" :filter "id=eq.42" (optional)} :broadcast — filter {:event "typing"} (use "*" for all) :presence — filter {:event :sync | :join | :leave}

Must be called BEFORE subscribe for postgres_changes — server-side binding ids are correlated at join time.

Registers a binding on `ch`. Returns the channel value (for threading)
or an anomaly on validation failure.

Binding types:
  :postgres-changes  — filter `{:event :insert/:update/:delete/:all
                                :schema "public" :table "users"
                                :filter "id=eq.42" (optional)}`
  :broadcast         — filter `{:event "typing"}` (use `"*"` for all)
  :presence          — filter `{:event :sync | :join | :leave}`

Must be called BEFORE `subscribe` for postgres_changes — server-side
binding ids are correlated at join time.
sourceraw docstring

presence-stateclj

(presence-state ch)

Returns the latest presence map captured for ch. Empty if no presence_state received yet.

Returns the latest presence map captured for `ch`. Empty if no
`presence_state` received yet.
sourceraw docstring

set-authclj

(set-auth ch-or-conn token)

Refreshes the auth token for a channel or every joined channel on a connection. Sends an access_token event per joined channel.

Refreshes the auth token for a channel or every joined channel on a
connection. Sends an `access_token` event per joined channel.
sourceraw docstring

subscribeclj

(subscribe ch)

Sends phx_join for ch and transitions to :joining. The channel receives :joined asynchronously when the server replies. Returns ch.

Sends `phx_join` for `ch` and transitions to `:joining`. The channel
receives `:joined` asynchronously when the server replies. Returns `ch`.
sourceraw docstring

trackclj

(track ch state)

Sends a presence track message with state. Returns ch.

Sends a presence `track` message with `state`. Returns `ch`.
sourceraw docstring

unsubscribeclj

(unsubscribe ch)

Sends phx_leave and transitions to :leaving. Channel state is removed when the server acks.

Sends `phx_leave` and transitions to `:leaving`. Channel state is removed
when the server acks.
sourceraw docstring

untrackclj

(untrack ch)

Sends a presence untrack message. Returns ch.

Sends a presence `untrack` message. Returns `ch`.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close