Liking cljdoc? Tell your friends :D

supabase.realtime.connection

WebSocket connection lifecycle for Supabase Realtime.

Holds a single hato-backed WebSocket per connect call. State lives in one atom; mutation goes through swap!; user callbacks run outside the swap to avoid running user code under contention.

The Transport protocol is the test seam — tests substitute a recording transport (see realtime_test) without redefining hato internals.

WebSocket connection lifecycle for Supabase Realtime.

Holds a single hato-backed WebSocket per `connect` call. State lives in
one atom; mutation goes through `swap!`; user callbacks run outside the
swap to avoid running user code under contention.

The `Transport` protocol is the test seam — tests substitute a recording
transport (see `realtime_test`) without redefining hato internals.
raw docstring

add-binding!clj

(add-binding! conn topic binding)

Appends a binding to channel topic. Returns the new channel-state or nil.

Appends a binding to channel `topic`. Returns the new channel-state or nil.
sourceraw docstring

build-ws-urlclj

(build-ws-url client)
(build-ws-url client extra-params)

Returns the full Realtime WebSocket URL for client with params (default: apikey + vsn) merged into the query string.

Returns the full Realtime WebSocket URL for `client` with `params`
(default: `apikey` + `vsn`) merged into the query string.
sourceraw docstring

channel-stateclj

(channel-state conn topic)

Reads the current channel-state map for topic, or nil.

Reads the current channel-state map for `topic`, or nil.
sourceraw docstring

connectclj

(connect client)
(connect client opts)

Opens a Realtime connection for client.

Options

  • :on-error(fn [anomaly]) for async transport/server errors
  • :heartbeat-ms — heartbeat interval in ms (default 30000)
  • :params — extra query params merged into the WS URL
  • :transport-factory(fn [url headers handlers]) returning a Transport. Defaults to ws-transport. Useful for tests.

Returns a connection map: {:client :transport :state :on-error :heartbeat}, or an anomaly on failure.

Opens a Realtime connection for `client`.

## Options

  - `:on-error`           — `(fn [anomaly])` for async transport/server errors
  - `:heartbeat-ms`       — heartbeat interval in ms (default 30000)
  - `:params`             — extra query params merged into the WS URL
  - `:transport-factory`  — `(fn [url headers handlers])` returning a
                            `Transport`. Defaults to `ws-transport`.
                            Useful for tests.

Returns a connection map: `{:client :transport :state :on-error :heartbeat}`,
or an anomaly on failure.
sourceraw docstring

disconnectclj

(disconnect conn)

Closes the connection: stops the heartbeat, closes the socket, and marks state as :closed. Idempotent.

Closes the connection: stops the heartbeat, closes the socket, and marks
state as `:closed`. Idempotent.
sourceraw docstring

dispatch-frameclj

(dispatch-frame conn frame)

Routes a decoded inbound frame to the matching state-update + user callbacks. Pure mechanism; user callbacks run after state updates.

Routes a decoded inbound `frame` to the matching state-update + user
callbacks. Pure mechanism; user callbacks run after state updates.
sourceraw docstring

enqueue!clj

(enqueue! conn frame)

Buffers a frame if the socket isn't open yet, otherwise sends it now. Returns true on send, false on buffer.

Buffers a frame if the socket isn't open yet, otherwise sends it now.
Returns true on send, false on buffer.
sourceraw docstring

remove-channel!clj

(remove-channel! conn topic)

Drops topic from the channels map.

Drops `topic` from the channels map.
sourceraw docstring

Transportcljprotocol

close!clj

(close! this code reason)

Initiates an orderly close of the underlying connection.

Initiates an orderly close of the underlying connection.

send-textclj

(send-text this text)

Sends text as a single text frame. Returns truthy on success or throws/returns an exception object on failure.

Sends `text` as a single text frame. Returns truthy on success or
throws/returns an exception object on failure.
source

update-channel!clj

(update-channel! conn topic f & args)

Applies f (with extra args) to the channel-state at topic. Returns the new channel-state, or nil if the topic isn't tracked.

Applies `f` (with extra `args`) to the channel-state at `topic`. Returns
the new channel-state, or nil if the topic isn't tracked.
sourceraw docstring

upsert-channel!clj

(upsert-channel! conn topic config)

Initializes channel-state for topic if absent. Returns the updated channel-state.

Initializes channel-state for `topic` if absent. Returns the updated
channel-state.
sourceraw docstring

ws-transportclj

(ws-transport url headers handlers)

Opens a hato WebSocket to url with the given upgrade headers and handlers map. Returns a reified Transport.

handlers keys: :on-open (fn []) :on-text (fn [text]) :on-close (fn [code reason]) :on-error (fn [throwable])

Partial text frames are buffered until last? is true.

Opens a hato WebSocket to `url` with the given upgrade `headers` and
`handlers` map. Returns a reified `Transport`.

`handlers` keys:
  :on-open    (fn [])
  :on-text    (fn [text])
  :on-close   (fn [code reason])
  :on-error   (fn [throwable])

Partial text frames are buffered until `last?` is true.
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