Skip to content

Event Feed

github-actions[bot] edited this page Dec 6, 2026 · 1 revision

Event Feed

GET /events is a live feed of what the engine is doing, as Server-Sent Events. It is meant for dashboards and monitoring tools that would otherwise poll /engine, /streams and each stream's /status and /peers. The Dashboard holds one subscription per engine and passes it on to browsers. It's available in edge, not yet in a numbered release.

The feed needs no setting, never starts a stream, and costs nothing while nobody is subscribed: no snapshot is built and no event is prepared until the first subscriber connects.

Subscribing

curl -N http://127.0.0.1:6878/events
curl -N 'http://127.0.0.1:6878/events?streams=ace:0123456789abcdef0123456789abcdef01234567'

streams names up to 8 streams whose detail you want, as comma-separated <network>:<id> pairs. The id takes the same forms as the playback URL (a bare content id, cid:, ih: or key:). Duplicates count once.

Response When
200 text/event-stream Subscribed.
400 with {"error": {"code": "invalid_stream"}} An entry isn't <network>:<id>, a cid:, ih: or key: id is malformed, or an id is longer than 8,192 bytes (enough for the turl- id of a long transport URL). Other ids (a bare id on ace, any id on another network) aren't checked: a wrong one is accepted and its stream message shows status: null.
400 with {"error": {"code": "too_many_streams"}} More than 8 streams.
503 with {"error": {"code": "capacity"}} and Retry-After: 5 32 feed connections are already open.
503 with {"error": {"code": "shutting_down"}} The engine is stopping.

Like every route, /events sits behind the allowed host names check. It's read-only, so no cross-site check applies.

Message format

Every message has an event: line naming its type, a data: line with a JSON object, an id: line and a retry: line:

id: 42
event: stream_started
data: {"network":"ace","id":"cid:0123456789abcdef0123456789abcdef01234567"}
retry: 3000

  • Ids come from one engine-wide counter. They always increase within one connection, but one subscriber does not see every number. There is no replay: a client that reconnects (with or without Last-Event-ID) starts again from a fresh hello and snapshot.
  • Retry. Every message carries retry: 3000, so browsers wait 3 seconds before reconnecting.
  • Heartbeat. After 15 seconds without any message the engine sends a : keep-alive comment. With snapshots every second it rarely needs to.
  • Slow clients. Each subscriber has a queue of 64 messages. A burst larger than that (for example many peer events in one second) reaches a client that keeps reading: the engine waits for room. The engine never writes a message to a client more than 3 seconds after publishing it: when the next message it would write is older than that, the client gets event: lagged (data {"reason": "slow_consumer"}) instead, and the response ends. A client that frees no room in its queue for 3 seconds gets the same lagged message after the messages already queued (those are still checked for age as they are written). Either way the engine stops sending to it, so a stalled client never holds engine memory beyond that queue. Reconnect to continue. Until the client closes the connection it still counts towards the limit of 32. The age is measured when the engine writes the message to the connection: bytes waiting in the network between the engine and the client are not counted.
  • When the engine shuts down, every feed ends at once, even with messages still queued.

Messages

hello

Sent first, once:

{"interval_ms": 1000, "heartbeat_ms": 15000, "max_streams": 8,
 "streams": [{"network": "ace", "id": "cid:0123456789abcdef0123456789abcdef01234567"}]}

streams echoes the streams you named, with ids normalized as the routes spell them.

snapshot

Sent right after hello, then once per second:

{"engine": {"active_sessions": 1, "viewers": 2, "occupied_sessions": 1, "max_sessions": null,
            "peers": 6, "download_bps": 2450000, "upload_bps": 800000},
 "streams": [{"network": "ace", "id": "cid:0123456789abcdef0123456789abcdef01234567",
              "clients": 2,
              "client_list": [{"address": "192.168.1.20", "since": 1763100000, "output": "ts"},
                              {"address": "192.168.1.30", "since": 1763100042, "output": "cast"}],
              "metadata": {"title": "My Channel", "bitrate": 2450000, "categories": ["other"]},
              "phase": "playing", "stalled": false, "idle_ms": 40, "peers": 6,
              "download_bps": 2450000, "upload_bps": 800000, "outputs": ["ts", "cast"]}]}

engine has the session fields of GET /engine (max_sessions is null when unlimited) plus totals over all streams. Each streams entry is a GET /streams entry plus phase, stalled, idle_ms, peers, download_bps, upload_bps and outputs, with the meanings they have on the status route. Rates are bits per second.

stream

Sent right after the first snapshot, then once per second, for each stream you named:

{"network": "ace", "id": "cid:0123456789abcdef0123456789abcdef01234567",
 "status": {"phase": "playing", "peers": 6, "download_bps": 2450000, "...": "..."},
 "peers": [{"address": "192.0.2.9:8621", "direction": "out", "source": "pex", "...": "..."}]}

status is exactly the body of GET /streams/<network>/<id>/status, or null where that route answers 404. peers is the peers list of GET /streams/<network>/<id>/peers, empty while the stream isn't running. In private peer mode every address is null.

Stream events

Sent to every subscriber, whichever streams it named. All carry network and id.

Event Extra fields When
stream_started none A stream's session started (a player, POST, cast, support source or the CLI started it).
stream_stopped reason: stopped, idle, source_ended or failed; error: {"code", "message"} when failed, else null The session was removed. The reasons match the status route's end record.
stream_phase phase, previous The stream's phase changed, for example connecting to buffering to playing.
stream_stalled idle_ms A playing stream sent no media for 10 seconds (stalled became true).
stream_recovered none Media flows again after a stall (the stream is playing again; a stalled stream that ends gets only stream_phase).
upstream_reconnect count (new reconnects), total The stream rebuilt its upstream connections (the recovery.upstream_reconnects counter rose).
{"network": "ace", "id": "cid:0123456789abcdef0123456789abcdef01234567",
 "reason": "idle", "error": null}

A source that reaches its end and a removed session are two events. When the source ends, the feed sends stream_phase with phase: ended within about a second while the session remains. stream_stopped (with reason: source_ended) follows only when the session is removed, which can be much later while a viewer or a support source still holds it. Watch for stream_phase to detect the end of a source without waiting for the removal.

Peer events

Sent only to subscribers that named the stream.

Event Extra fields
peer_joined peer: one row of the /peers route
peer_dropped address: the peer's address, null in private peer mode
peers_changed joined, dropped: how many peers joined and dropped

When more than 16 peers join or drop on one stream within one second, the feed sends a single peers_changed summary instead of one event per peer. The next stream message carries the full peer list.

{"network": "ace", "id": "cid:0123456789abcdef0123456789abcdef01234567",
 "address": "192.0.2.9:8621"}

Timing and limits

stream_started and stream_stopped are sent the moment the session starts or ends. The other events are found by comparing each one-second snapshot with the previous one, so they arrive within about a second, and a change that is undone within one second (a peer that connects and drops right away) isn't reported. Nothing is compared before the first subscriber connects. Your first snapshot is your starting point: a stream or peer that is already there shows up in it, not as an event, and every change after it is reported. A stream that stops and starts again within one second starts over too: stream_stopped and stream_started announce it, and the new session's phase and peers are a new starting point, compared with nothing from the old one. When a stream starts or stops while a snapshot is being built, that one-second tick has no snapshot (its stream list would contradict the stream_started or stream_stopped just sent); the next tick has one.

Limit Value
Snapshot interval 1 second
Heartbeat 15 seconds of silence
Open feed connections 32 (a dropped subscriber counts until it closes)
Streams per subscriber 8
Length of one stream id 8,192 bytes
Queued messages per subscriber 64
Age of a message when written, or wait for a full queue, before lagged 3 seconds
Peer events per stream per second 16, then one peers_changed

These are fixed; there is no setting for them.

The feed shows viewer and peer addresses to anyone who can reach the API, like /streams and /peers do. Keep OUTPACE_BIND on a trusted interface (the default is loopback), as Deployment recommends.

Example: reading the feed in a browser

const feed = new EventSource("/events?streams=ace:0123456789abcdef0123456789abcdef01234567");
feed.addEventListener("snapshot", (e) => render(JSON.parse(e.data)));
feed.addEventListener("stream_stopped", (e) => log(JSON.parse(e.data)));
// After `lagged` the engine ends the response and EventSource reconnects by itself after the
// `retry` delay, starting again from a fresh `hello` and `snapshot`.
feed.addEventListener("lagged", () => console.warn("event feed fell behind; reconnecting"));

Clone this wiki locally