Dev's NoxDev's Nox
Protocol

WebSocket

The client channel — envelopes, subscriptions, and every frame a node may emit

Browsers and relays connect to the native gateway advertised by GET /.well-known/nox (gateway.ws):

wss://<node>/api/ws?token=<session token>

A relay connects with its own credentials and stays on the relay protocol (see Relay). This page covers the client traffic: frames a node pushes to a signed-in user's sockets.

Two envelopes

Every frame is one of two shapes. The shape tells you whether the server required a subscription.

ShapeEmissionJSON
roomws.emit(name, data){ "type": "event", "payload": { "name": "<frame>", "data": … } }
targetedws.emitToUser(id, name, data){ "type": "<frame>", "payload": … }
  • room frames only reach sockets that called subscribe for that room name.
  • targeted frames reach every socket of that user, whatever they subscribed to — that is how a page gets a notification about itself without joining a room.

A frame may also carry an id, echoing the one the client sent: that is how a request/response pair is matched (ping → pong, a relay request → response).

Subscriptions

// client → server
{ "type": "subscribe",   "payload": { "events": ["world.updated", "user.presence"] } }
{ "type": "unsubscribe", "payload": { "events": ["world.updated"] } }

// server → client
{ "type": "subscribed",   "payload": { "subscribed": ["world.updated"] } }
{ "type": "unsubscribed", "payload": { "unsubscribed": ["world.updated"] } }

Access is decided server-side: each frame may declare a guard with @OnWebsocketEventRegister(frame) (for example server_logs and activity are administrator only). A refused name is not in subscribed — it is not an error.

Session lifecycle

FrameWhen
helloright after the handshake: { mode }, plus user (ApiCurrentUser) for a signed-in client or relayId for a relay
errora frame was refused: { code, message } — the socket stays open
ponganswer to a ping, { time, received }

mode is guest, user or relay. A guest owns no user id, so it can never receive a targeted frame — only the rooms it is allowed to join.

Subscriptions are not persisted: re-subscribe after a reconnect (the front's WsProvider keeps a ref-counted list and replays it).

Frame catalogue

Users

FrameShapePayload
current.changedtargetedthe private view of the signed-in user (ApiCurrentUser)
user.changedtargeted{ user, out, in, entity? }
user.relationtargeted{ user, out, in } — "follow" | "request" | null
relation.changedtargeted{ target, type } — follow / request / unfollow
user.presenceroom + targeted{ user, status, text, locations }
notificationtargeted{ type, key, from, data }

current.changed is the only pushed frame that carries private data (email, methods…): it is sent to the account's own connections and nobody else's. (hello.user carries the same private view once, at connection time.)

user.changed is what a relation receives when a profile it displays was saved. It carries the public view — built without a viewer, so relations and the viewer-scoped presence are null — and the two sides of the relation:

{
  "type": "user.changed",
  "payload": {
    "user": "42@nox.example",
    "out": true,
    "in": false,
    "entity": { "id": 42, "username": "alice", "relations": null, "…": "ApiUser" }
  }
}
  • out — the recipient follows that user.
  • in — that user follows the recipient.
  • entity — the public profile; absent when the node could not build it, in which case the client refetches GET /api/users/:id.

A mutual follow receives the frame once, with both sides set.

Presence

user.presence has two audiences, because the payload is not the same for both:

AudienceShapelocations
the room (any subscriber)roomonly when the status is visible to everyone (event, public), null otherwise
the user's friends (mutual follows)targetedwhenever the status grants friends access — online is friend-scoped
{ "type": "user.presence", "payload": {
    "user": "42@nox.example", "status": "online", "text": null,
    "locations": ["w:12@nox.example"] } }

locations is null — never an empty array — when the viewer is not allowed to know: an empty array means "allowed, and the user is nowhere". A location flagged ?private is only ever shown to the user themself, whatever the audience. The friend list is resolved from the relation table page by page (AUDIENCE_PAGE = 1000) and each page is emitted before the next is read, chunked again into bus messages of WS_USER_BATCH = 250 ids: a presence change never holds a friend list in memory and never fans out to a follower count.

When a friendship forms or breaks, the profile is refetched (user.changed / user.relation), and presence comes with it — the presence frame is only a live update of an already-known audience.

Assets

One trio per kind (world, mod, avatar…), derived from the registered @AssetControllers:

FrameShapePayload
<kind>.created / .updatedroomthe sanitised entity (IApiAsset)
<kind>.removedroom{ type, id, time }
<kind>.releases.created / .updatedroomthe sanitised release
<kind>.files.created / .updatedroomthe sanitised file, status included
asset.changedtargeted{ type, id } — refetch fallback
relation.changedtargeted{ target, type } — the viewer's own follow

A follower of an asset receives the same <kind>.updated frame a page subscribed to the kind gets: the follower list is resolved server-side and the entity is pushed at them, they are not expected to watch the kind's room. asset.changed is only used when the view could not be built (a racing delete) or when a peer sent an update without one — the page then refetches.

Jobs, instances, relays

FrameNote
job.updatedbackground work (IApiJob), admin-scoped payload on GET /api/jobs/:id
instance.created / .updated / .removed / .lifecycleinstance lifecycle
relay.*relay protocol state, see Relay
server_logsadmin only
activityadmin only

Delivery guarantees

  • At most once, and only while connected. Nothing is queued for an offline socket: a page reconciles on its next request. That is why every targeted frame either carries the entity or is a signal the client knows how to resolve.
  • One socket, one process. With several api processes, every emission is republished on the cache bus (ws:frames): each process delivers to the sockets it hosts and ignores its own echo.
  • Batched. A frame addressed to a whole audience travels as one bus message per WS_USER_BATCH (250) ids; recipients with no connection are skipped by each gateway.
  • No audience in updates. The list of ids is never sent inside an entity frame — see Protocol overview.

Implementing a client

  1. Open the socket, wait for hello, then subscribe to the rooms the page needs.
  2. Treat <kind>.updated / user.changed as a cache write — the payload is the entity.
  3. Keep what the frame cannot know: a sanitised entity has relations and following at null, so merge the values the page already resolved instead of resetting them.
  4. When only a signal arrives (asset.changed, or user.changed without entity), refetch the resource with a normal GET.
  5. Re-subscribe on reconnect; the server keeps no subscription state.

On this page