# `Arc.Plug.Hub`
[🔗](https://github.com/Cratis/Arc.Elixir/blob/main/lib/arc/plug/hub.ex#L4)

The multiplexed WebSocket hub at `/.cratis/queries/ws`.

One connection carries many observable-query subscriptions. Messages share an envelope with a
PascalCase `type` (`Subscribe`, `Unsubscribe`, `QueryResult`, `Unauthorized`, `Error`, `Ping`,
`Pong`, `Connected`), a client-assigned `queryId`, an optional `revision` and a `payload`.

A connection opens with `Connected`, whose payload is the server-assigned connection id. Each
subscription is authorized independently by the ordinary query pipeline: a denied
subscription ends with `Unauthorized` for its `queryId` without disturbing the others.

Revisions order operations for one `queryId`: a stale message is ignored, a duplicate is
idempotent, and an unsubscribe is remembered so a delayed subscribe cannot resurrect it.

Each subscription's `transferMode` shapes its emissions (see `Arc.Plug.HubSession`): `full` sends
snapshots, `delta` a snapshot and then change sets, anything else both on every emission.
The same protocol is served over Server-Sent Events by `Arc.Plug.SseHub`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
