Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
284 changes: 202 additions & 82 deletions public/realtime/static/realtime-api-2024-05-21.yaml

Large diffs are not rendered by default.

56 changes: 29 additions & 27 deletions src/content/docs/realtime/sfu/api/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ The [quickstart](/realtime/sfu/get-started/) shows this setup with a Worker back

The paths in this table are relative to the base URL:

| Operation | Method and path |
| ------------------------------ | ------------------------------------------------------ |
| Create a session | `POST /apps/{appId}/sessions/new` |
| Publish or subscribe to tracks | `POST /apps/{appId}/sessions/{sessionId}/tracks/new` |
| Update tracks | `PUT /apps/{appId}/sessions/{sessionId}/tracks/update` |
| Submit a renegotiation answer | `PUT /apps/{appId}/sessions/{sessionId}/renegotiate` |
| Close tracks | `PUT /apps/{appId}/sessions/{sessionId}/tracks/close` |
| Read session information | `GET /apps/{appId}/sessions/{sessionId}` |
| Operation | Method and path |
| --------------------------------------- | ------------------------------------------------------ |
| Create a session | `POST /apps/{appId}/sessions/new` |
| Publish or subscribe to tracks | `POST /apps/{appId}/sessions/{sessionId}/tracks/new` |
| Update tracks | `PUT /apps/{appId}/sessions/{sessionId}/tracks/update` |
| Submit a renegotiation answer | `PUT /apps/{appId}/sessions/{sessionId}/renegotiate` |
| Close tracks | `PUT /apps/{appId}/sessions/{sessionId}/tracks/close` |
| Inspect a connected session’s resources | `GET /apps/{appId}/sessions/{sessionId}` |

Refer to [sessions and tracks](/realtime/sfu/concepts/sessions-tracks/) for publication and identifier ownership.

Expand All @@ -49,27 +49,29 @@ The optional `correlationId` query parameter on `sessions/new` is a diagnostic l

### Inspect a session

Call `GET /apps/{appId}/sessions/{sessionId}` to inspect the session's media tracks and DataChannels. The response identifies media by `mid` and channels by their allocated `id`. For a remote resource, `sessionId` identifies its publisher:
While your endpoint is connected to the SFU, use `GET /apps/{appId}/sessions/{sessionId}` to inspect its current tracks and DataChannels. After the PeerConnection closes, [discard the session ID](/realtime/sfu/concepts/sessions-tracks/#resource-lifetime). There is no final session snapshot to poll for.

The response identifies media by `mid` and channels by their allocated `id`. A remote resource’s `sessionId` identifies its publisher.

```json
{
"tracks": [
{
"location": "local",
"mid": "0",
"trackName": "camera",
"status": "inactive"
}
],
"dataChannels": [
{
"location": "remote",
"sessionId": "<PUBLISHER_SESSION_ID>",
"dataChannelName": "controls",
"id": 2,
"status": "active"
}
]
"tracks": [
{
"location": "local",
"mid": "0",
"trackName": "camera",
"status": "inactive"
}
],
"dataChannels": [
{
"location": "remote",
"sessionId": "<PUBLISHER_SESSION_ID>",
"dataChannelName": "controls",
"id": 2,
"status": "active"
}
]
}
```

Expand All @@ -81,7 +83,7 @@ Interpret the resource's `status` as follows:
| `inactive` | Closed or unavailable. | No longer connecting or open. |
| `initializing` | Not applicable. | Still connecting. |

A media track marked `active` does not prove that packets are arriving or playing. Use [endpoint statistics](/realtime/sfu/observability/#inspect-browser-media-statistics) to check delivery. Forced closure can leave a track listed as `inactive`.
A media track marked `active` does not prove that packets are arriving or playing. Use [endpoint statistics](/realtime/sfu/observability/#inspect-browser-media-statistics) to check delivery. A track can remain listed as `inactive` while the session is connected.

The response contains resource state, not SDP or request history. Pending requests can still change it, even when the resource lists are empty. Follow [retry and reconnect guidance](/realtime/sfu/concepts/negotiation/#retry-and-reconnect) before resuming mutations.

Expand Down
22 changes: 11 additions & 11 deletions src/content/docs/realtime/sfu/concepts/negotiation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ A lost response leaves the request's outcome unknown. Pause later mutations on t

Use the interrupted operation to choose the next step:

| Interrupted operation | Next step |
| ------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `sessions/new` | Create a replacement session. |
| `tracks/new` | Inspect allocations before creating more tracks. Repeated subscriptions can allocate duplicates. If the SDP response is lost, replace the connection. |
| `datachannels/new` | Recover visible allocations through session inspection. An empty snapshot cannot resolve an uncertain request. Retain successful allocations from partial responses. |
| `datachannels/establish` | Complete the transport's SDP exchange. If its response is lost, replace the connection. Repeating establish is not a state check. |
| `/renegotiate` | A repeated answer can fail after the first succeeds. If acceptance remains unknown, replace the connection. A retry error cannot resolve that uncertainty. |
| Forced media close or `datachannels/close` | While the session is live, retry unresolved IDs in order. Process each result. |
| Negotiated media close | Apply the original answer if available. Otherwise, close the PeerConnection and discard the session. |

[Session inspection](/realtime/sfu/api/#inspect-a-session) can recover resource identifiers, but not lost SDP or request history. [`correlationId`](/realtime/sfu/api/#correlate-session-creation) labels diagnostics. It does not recover or deduplicate a session.
| Interrupted operation | Next step |
| ------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `sessions/new` | If you did not receive or save the session ID, create a replacement only if you still need a connection. |
| `tracks/new` | If the PeerConnection is still connected, inspect its allocations before creating more tracks. Repeated subscriptions can allocate duplicates. If the SDP response is lost, replace the connection. |
| `datachannels/new` | If the PeerConnection is still connected, inspect its channel allocations. Retain successful items. If you cannot recover the IDs needed to continue, replace the connection. |
| `datachannels/establish` | Complete the transport's SDP exchange. If its response is lost, replace the connection. Repeating establish is not a state check. |
| `/renegotiate` | A repeated answer can fail after the first succeeds. If acceptance remains unknown, replace the connection. A retry error cannot resolve that uncertainty. |
| Forced media close or `datachannels/close` | While the session is live, retry unresolved IDs in order. Process each result. |
| Negotiated media close | Apply the original answer if available. Otherwise, close the PeerConnection and discard the session. |

[Session inspection](/realtime/sfu/api/#inspect-a-session) can recover resource identifiers on a connected session. An empty snapshot cannot resolve an earlier request, and inspection cannot recover lost SDP. [`correlationId`](/realtime/sfu/api/#correlate-session-creation) labels diagnostics. It does not recover or deduplicate a session.

Give a replacement connection a new application attempt ID. Ignore old responses when updating it. Republish and rebuild subscriptions using the new session identifiers.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ A participant does not have to correspond to exactly one session. The [video-roo

### Session setup

Calling `POST /sessions/new` with no request body returns a `sessionId`, but does not establish the WebRTC connection. Follow a [connection recipe](/realtime/sfu/get-started/connection-patterns/) to complete the offer/answer exchange, then wait for the endpoint's connection state to become `connected`.
Send `POST /sessions/new` with no request body. Omit the JSON payload entirely. The response supplies a `sessionId` for connection setup. Follow a [connection recipe](/realtime/sfu/get-started/connection-patterns/) to complete the offer/answer exchange, then wait for the endpoint's connection state to become `connected`.

Create each session when the endpoint is ready to negotiate. If setup fails or the PeerConnection closes, create a new session and repeat connection setup.

Expand Down
2 changes: 1 addition & 1 deletion src/content/docs/realtime/sfu/examples/video-room.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The components have these responsibilities:
| Durable Object | Own room membership, track discovery, room permissions, reconnect state, and cleanup |
| Realtime SFU | Receive published audio/video and forward the tracks requested by each receiving session |

A hibernating WebSocket notifies browsers that a room revision changed. Browsers fetch the authoritative snapshot over HTTP. A periodic safety poll also checks for changes. Closing the notification socket does not by itself remove a participant.
A hibernating WebSocket notifies browsers that a room revision changed. Browsers fetch the room Worker’s membership and publication snapshot over HTTP. They also poll the room Worker periodically for missed changes. Closing the notification socket does not by itself remove a participant.

## Publication and discovery

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Only `payload` is used for ingest. Send small, frequent audio chunks within the

### Media egress packets (stream mode)

Audio messages contain PCM frames with timestamps and sequence numbers. Video messages contain JPEG frames with timestamps; a video sequence number may be unset. Each frame is a separate WebSocket message.
Audio messages contain PCM frames with sequence numbers. When a PCM frame carries the source Opus RTP timestamp, read it in 48,000 ticks per second. JPEG frame timestamps use 90,000 presentation-clock ticks per second. A video sequence number may be unset. Each frame is a separate WebSocket message.

The JPEG path supports H.264, H.265, VP8, and VP9 WebRTC input. Refer to [supported SFU codecs](/realtime/sfu/platform/limits/#supported-codecs) for the broader media-track codec list.

Expand Down
10 changes: 9 additions & 1 deletion src/content/docs/realtime/sfu/features/simulcast.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,15 @@ Start with an existing publication that advertises simulcast encodings. Obtain i

To change an existing subscription, update `preferredRid` through `PUT /apps/{appId}/sessions/{sessionId}/tracks/update` on your backend. The URL identifies the receiving session. Use that subscription's receiving `mid` in the request and select a RID advertised by the publisher.

Check the track result before advancing application state. Refer to the [OpenAPI schema](/realtime/static/realtime-api-2024-05-21.yaml) for the complete update body.
This request selects encoding `h` for the receiving transceiver with `mid` `7`.

```json
{
"tracks": [{ "mid": "7", "simulcast": { "preferredRid": "h" } }]
}
```

Check the result for that `mid` before advancing application state. To receive a different publication, [subscribe to it](/realtime/sfu/get-started/connection-patterns/#receive-a-published-track) with `tracks/new`.

## Quality control

Expand Down
4 changes: 2 additions & 2 deletions src/content/docs/realtime/sfu/get-started/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ The backend coordinates the room and checks permissions. Media travels directly

## Clean up

Select **Leave** to remove one participant. The room creator can select **Terminate room** to end the room for everyone. Wait for confirmation; a failed cleanup remains available to retry.
Select **Leave** to remove one participant. The room creator can select **Terminate room** to end the room for everyone. Wait for the room application to confirm the action. If the room reports a cleanup failure, retry it there.

Stop the local development process when finished. Delete `.dev.vars` when you no longer need the local credentials. Delete a dedicated SFU app only after all applications using it have stopped.

Expand All @@ -89,7 +89,7 @@ To adapt this application, follow [the video-room architecture](/realtime/sfu/ex
To share a deployed room, follow the video-room guide's [deployment instructions](/realtime/sfu/examples/video-room/#deploy-the-room).

<LinkButton href="/realtime/sfu/examples/">
Explore more applications
Explore more applications
</LinkButton>

If media does not appear, start with [troubleshooting](/realtime/sfu/observability/).
Loading