Docs

JavaScript: Realtime

Listen on channels over WebSocket with automatic reconnects, publish messages, see who is online and catch up on missed messages with @sovaria/sdk.

Updated Nov 11, 2026

sovaria.realtime.channel() opens a WebSocket on a channel and keeps it open: it reconnects with backoff, gets a fresh ticket each time, and tells you its status. Channel rules decide who may subscribe and publish.

supabase-js's channel API is on the client too: sovaria.channel(name).on('broadcast' | 'presence' | 'postgres_changes', filter, callback).subscribe(), with send, track, presenceState() and removeChannel() — see the client reference and Realtime. Presence entries carry the user_id the server stamped on the message; table changes carry no row (re-read with your own query).

import { createClient } from '@sovaria/sdk'

const sovaria = createClient('https://<project-ref>.sovarias.in', '<anon-key>')

const room = sovaria.realtime.channel('room:42', {
  onMessage: (msg) => render(msg),
  onStatus: (status) => setBadge(status),   // 'connecting' | 'live' | 'reconnecting' | 'closed'
  onError: (err) => console.warn(err),
})

await room.send({ text: 'Hello!' })
// later
room.close()

#sovaria.realtime

sovaria.realtime.subscribe

Subscribe.

sovaria.realtime.subscribe(
  channel: string,
  clientId: string,
): Promise<JsonObject>

Parameters

channelstringrequired
clientIdstringrequired

Returns

Promise<JsonObject>

{
  "channel": "orders",
  "subscribed": true
}

sovaria.realtime.unsubscribe

Unsubscribe.

sovaria.realtime.unsubscribe(
  channel: string,
  clientId: string,
): Promise<JsonObject>

Parameters

channelstringrequired
clientIdstringrequired

Returns

Promise<JsonObject>

{
  "status": "ok"
}

sovaria.realtime.presence

Presence.

sovaria.realtime.presence(channel: string): Promise<JsonObject>

Parameters

channelstringrequired

Returns

Promise<JsonObject> — Who is connected to the channel right now.

{
  "channel": "doc-1234",
  "online_clients": [
    "c_7f2a91",
    "c_03bd4e"
  ],
  "count": 2
}

sovaria.realtime.channels

Channels.

sovaria.realtime.channels(): Promise<JsonObject>

Returns

Promise<JsonObject>

{
  "channels": [
    {
      "channel": "room-42",
      "scoped_channel": "b2f4a1c8…:room-42:…",
      "subscribers": 2,
      "event_count": 1834
    }
  ],
  "total": 1
}

sovaria.realtime.replay

Replay.

sovaria.realtime.replay(
  channel: string,
  after?: number = 0,
  limit?: number = 200,
): Promise<JsonObject>

Parameters

channelstringrequired
afternumberoptionaldefault 0
Sequence number of the last message you saw.
limitnumberoptionaldefault 200
Maximum messages to return.

Returns

Promise<JsonObject> — Messages after after, oldest first — use it to catch up after being offline.

{
  "channel": "room-42",
  "events": [
    {
      "channel": "room-42",
      "scoped_channel": "b2f4a1c8…:room-42:…",
      "payload": {
        "text": "Are you there?",
        "from": "grace"
      },
      "clock": {
        "pulse-1": 1833
      },
      "clock_delta": {
        "pulse-1": 1
      },
      "stream_seq": 1833
    },
    {
      "channel": "room-42",
      "scoped_channel": "b2f4a1c8…:room-42:…",
      "payload": {
        "text": "Hello!",
        "from": "ada"
      },
      "clock": {
        "pulse-1": 1834
      },
      "clock_delta": {
        "pulse-1": 1
      },
      "stream_seq": 1834
    }
  ],
  "count": 2
}

sovaria.realtime.publish

Publish.

sovaria.realtime.publish(
  channel: string,
  payload: JsonObject,
  clock?: JsonObject,
  clockDelta?: JsonObject,
): Promise<JsonObject>

Parameters

channelstringrequired
Channel name.
payloadJsonObjectrequired
JSON message.
clockJsonObjectoptional
clockDeltaJsonObjectoptional

Returns

Promise<JsonObject>

await sovaria.realtime.publish('room:42', { text: 'Server says hi' })
Response
{
  "channel": "room-42",
  "clock": {
    "pulse-1": 1834
  },
  "clock_delta": {
    "pulse-1": 1
  },
  "stream_seq": 1834,
  "published": true
}

sovaria.realtime.e2eeBootstrap

E2ee bootstrap.

sovaria.realtime.e2eeBootstrap(
  channel: string,
  ttlSeconds?: number = 86400,
  forceNew?: boolean = false,
): Promise<JsonObject>

Parameters

channelstringrequired
ttlSecondsnumberoptionaldefault 86400
forceNewbooleanoptionaldefault false

Returns

Promise<JsonObject>

{
  "channel": "room-42",
  "tenant_scope": "b2f4a1c8…:f0c3e9a2…",
  "key_id": "k_9f3a2c71",
  "key_b64": null,
  "wrapped_key_b64": "Qm9v…",
  "wrapping_alg": "RSA-OAEP-SHA256",
  "status": "active",
  "created_at_ms": 1792262400000,
  "expires_at_ms": 1792348800000
}

sovaria.realtime.e2eeRotate

E2ee rotate.

sovaria.realtime.e2eeRotate(
  channel: string,
  ttlSeconds?: number = 86400,
): Promise<JsonObject>

Parameters

channelstringrequired
ttlSecondsnumberoptionaldefault 86400

Returns

Promise<JsonObject>

{
  "channel": "room-42",
  "tenant_scope": "b2f4a1c8…:f0c3e9a2…",
  "key_id": "k_1c7e0b44",
  "key_b64": "q1Z8…",
  "wrapped_key_b64": null,
  "wrapping_alg": null,
  "status": "active",
  "created_at_ms": 1792262400000,
  "expires_at_ms": 1792348800000
}

sovaria.realtime.e2eeRevoke

E2ee revoke.

sovaria.realtime.e2eeRevoke(
  channel: string,
  keyId?: string,
  reason?: string,
): Promise<JsonObject>

Parameters

channelstringrequired
keyIdstringoptional
reasonstringoptional

Returns

Promise<JsonObject>

{
  "channel": "room-42",
  "tenant_scope": "b2f4a1c8…:f0c3e9a2…",
  "key_id": "k_9f3a2c71",
  "status": "revoked",
  "created_at_ms": 1792262400000,
  "expires_at_ms": 1792348800000,
  "revoked_at_ms": 1792266000000,
  "revocation_reason": "device lost"
}

sovaria.realtime.e2eeActiveKey

Pass your RSA-OAEP (SHA-256) public key — PEM or base64 SPKI — to get the key wrapped for you.

sovaria.realtime.e2eeActiveKey(
  channel: string,
  clientPublicKey?: string,
): Promise<JsonObject>

Parameters

channelstringrequired
clientPublicKeystringoptional

Returns

Promise<JsonObject>

  • Part of end-to-end encrypted channels; see Realtime.
{
  "channel": "room-42",
  "tenant_scope": "b2f4a1c8…:f0c3e9a2…",
  "key_id": "k_9f3a2c71",
  "key_b64": null,
  "wrapped_key_b64": "Qm9v…",
  "wrapping_alg": "RSA-OAEP-SHA256",
  "status": "active",
  "created_at_ms": 1792262400000,
  "expires_at_ms": 1792348800000
}

sovaria.realtime.e2eeGetKey

E2ee get key.

sovaria.realtime.e2eeGetKey(
  channel: string,
  keyId: string,
  clientPublicKey?: string,
): Promise<JsonObject>

Parameters

channelstringrequired
keyIdstringrequired
clientPublicKeystringoptional

Returns

Promise<JsonObject>

{
  "channel": "room-42",
  "tenant_scope": "b2f4a1c8…:f0c3e9a2…",
  "key_id": "k_9f3a2c71",
  "key_b64": null,
  "wrapped_key_b64": "Qm9v…",
  "wrapping_alg": "RSA-OAEP-SHA256",
  "status": "active",
  "created_at_ms": 1792262400000,
  "expires_at_ms": 1792348800000
}

sovaria.realtime.e2eeListKeys

E2ee list keys.

sovaria.realtime.e2eeListKeys(channel: string): Promise<JsonObject>

Parameters

channelstringrequired

Returns

Promise<JsonObject>

{
  "channel": "room-42",
  "keys": [
    {
      "channel": "room-42",
      "tenant_scope": "b2f4a1c8…:f0c3e9a2…",
      "key_id": "k_1c7e0b44",
      "status": "active",
      "created_at_ms": 1792265000000,
      "expires_at_ms": 1792351400000,
      "revoked_at_ms": null,
      "revocation_reason": null
    },
    {
      "channel": "room-42",
      "tenant_scope": "b2f4a1c8…:f0c3e9a2…",
      "key_id": "k_9f3a2c71",
      "status": "rotated",
      "created_at_ms": 1792262400000,
      "expires_at_ms": 1792348800000,
      "revoked_at_ms": null,
      "revocation_reason": null
    }
  ]
}

sovaria.realtime.wsTicket

Ws ticket.

sovaria.realtime.wsTicket(channel: string): Promise<string>

Parameters

channelstringrequired

Returns

Promise<string>

sovaria.realtime.wsUrl

Ws url.

sovaria.realtime.wsUrl(channel: string, ticket?: string): string

Parameters

channelstringrequired
ticketstringoptional

Returns

string

sovaria.realtime.wsUrlWithTicket

Ws url with ticket.

sovaria.realtime.wsUrlWithTicket(channel: string): Promise<string>

Parameters

channelstringrequired

Returns

Promise<string>

sovaria.realtime.channel

Listen on a channel over WebSocket.

sovaria.realtime.channel(
  name: string,
  handlers?: RealtimeChannelHandlers = {},
): RealtimeChannel

Reconnects with backoff (a fresh ticket each time) and hands you each message's payload. Call close() when done. ``ts const ch = sov.realtime.channel('book:42', { onMessage: (m) => console.log(m), onStatus: setStatus }) await ch.send({ type: 'typing' }) ch.close()

Parameters

namestringrequired
Channel name, e.g. room:42.
handlersRealtimeChannelHandlersoptionaldefault {}
onMessage(payload, raw), onStatus(status), onError(error), maxBackoffMs (default 15000).

Returns

RealtimeChannel — A channel with name, status, send(payload) and close().