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
2 changes: 2 additions & 0 deletions src/content/docs/realtime/realtimekit/audio-calls.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ products:
RealtimeKit supports voice calls, allowing you to build audio-only experiences such as audio rooms, support lines, or community hangouts.
In these meetings, participants use their microphones and hear others, but cannot use their camera. Voice meetings reduce bandwidth requirements and focus on audio communication.

To let someone join a live meeting from a phone number, [set up SIP dial-in](/realtime/realtimekit/sip-dial-in/).

## How Audio Calls Work

A participant’s meeting experience is determined by the **Preset** applied to that participant.
Expand Down
96 changes: 96 additions & 0 deletions src/content/docs/realtime/realtimekit/sip-dial-in.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
title: Add phone dial-in to a meeting
description: Let callers join a live RealtimeKit meeting by phone. Enable SIP, connect a voice provider, and test audio with another participant.
pcx_content_type: how-to
sidebar:
label: SIP dial-in
order: 8
products:
- realtime
---

import { APIRequest, Steps, TabItem, Tabs } from "~/components";

Use Session Initiation Protocol (SIP) dial-in to let someone join a live RealtimeKit meeting from an ordinary phone. A voice provider routes the phone number to the meeting's SIP address. RealtimeKit answers and adds the caller as an audio participant.

## Prerequisites

You need a [RealtimeKit app and API token](/realtime/realtimekit/quickstart/) with **Realtime** or **Realtime Admin** permission. Call the meeting API from your backend. Meeting responses can contain the SIP password, so keep them out of browser clients and logs.

## Enable dial-in

<Tabs>
<TabItem label="New meeting">

Set `enable_sip` when you create the meeting.

<APIRequest
method="POST"
path="/accounts/{account_id}/realtime/kit/{app_id}/meetings"
json={{ title: "Support room", enable_sip: true }}
roles={false}
/>

</TabItem>
<TabItem label="Existing meeting">

Update the meeting with `PATCH`. The meeting replacement operation (`PUT`) ignores `enable_sip`.

<APIRequest
method="PATCH"
path="/accounts/{account_id}/realtime/kit/{app_id}/meetings/{meeting_id}"
json={{ enable_sip: true }}
roles={false}
/>

</TabItem>
</Tabs>

## Connect your voice provider

Save the meeting ID. Use the `data.sip` fields from the response to configure your provider.

| Field | Provider setting |
| ---------- | ------------------- |
| `sip_uri` | SIP address to dial |
| `username` | SIP digest username |
| `password` | SIP digest password |

You can retrieve these credentials with an authenticated `GET` on the meeting. When dial-in is off, `data.sip` is `null`.

Route a voice-capable number to the SIP address and give callers that number. For a complete provider example, follow [Route a Twilio number to Cloudflare](/realtime/sfu/features/sip/twilio/).

:::note[Meeting access]
Phone callers join with the reserved `sip_preset` and skip the waiting room. If your meeting requires a PIN or caller screening, configure it at the provider before forwarding the call.
:::

## Test a call

<Steps>

1. Join the meeting from a browser or mobile client using the [RealtimeKit quickstart](/realtime/realtimekit/quickstart/). Turn on the microphone before dialing. The phone caller joins that [live session](/realtime/realtimekit/concepts/session-lifecycle/).
2. Call the provider's number from a phone. Look for a new audio participant in the meeting. Its display name comes from the user part of the SIP caller address, often a phone number. The fallback name is `Phone caller`.
3. Speak in each direction and confirm both participants hear each other. Hang up the phone and confirm the caller leaves. A moderator can also remove the caller or end the session.

</Steps>

## What participants can hear

Meeting participants hear the caller through an audio track. The caller hears up to 32 microphones that were unmuted when RealtimeKit answered. Screen-share audio is excluded.

The mix keeps the same microphones for the duration of the call. If someone joins or publishes a new microphone later, the phone caller can redial to hear them.

## Troubleshoot dial-in

| Symptom | What to do |
| ----------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| The provider receives SIP `480` | Have a participant join the meeting, then dial again. The phone caller cannot start a session. |
| The meeting hears the caller, but the phone is silent | Make sure a meeting participant has an active microphone, then redial. A call can connect with an empty audio mix. |
| The call ends after other people leave | RealtimeKit ends the call after about 60 seconds without another eligible participant. Other phone callers, recording or livestream participants, and people in the waiting room do not keep it open. |
| The provider repeatedly receives SIP `401` | Read the current meeting credentials and update the provider. Check that the number points to this meeting's full SIP URI. |

## Turn off dial-in

Send `{"enable_sip":false}` with `PATCH` to the same meeting URL. This removes its dial-in configuration. To disconnect a caller already in the meeting, remove that participant. Enabling dial-in again creates a new SIP address and credentials. Update your provider before sharing the number again.

For an application that makes its own accept decisions or changes the audio mix during a call, use [Realtime SFU SIP dial-in](/realtime/sfu/features/sip/).
40 changes: 22 additions & 18 deletions src/content/docs/realtime/sfu/api/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ https://rtc.live.cloudflare.com/v1

Send `Authorization: Bearer <APP_SECRET>` and `Content-Type: application/json`. Keep the App Secret on trusted backend infrastructure. Endpoint authentication and resource authorization belong to your application.

[Download the full OpenAPI schema](/realtime/static/realtime-api-2024-05-21.yaml) for request and response fields.
[Download the session, track, and adapter OpenAPI schema](/realtime/static/realtime-api-2024-05-21.yaml) for request and response fields.

To implement a connection, follow the [browser and backend recipes](/realtime/sfu/get-started/connection-patterns/) for publication, reception, messages, or media with controls. Use this reference to look up operations and fields.

Expand Down Expand Up @@ -53,23 +53,23 @@ Call `GET /apps/{appId}/sessions/{sessionId}` to inspect the session's media tra

```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 Down Expand Up @@ -109,6 +109,10 @@ Create adapters to ingest external audio or stream existing audio/video publicat

The [WebSocket adapter reference](/realtime/sfu/features/media-transport-adapters/websocket-adapter/) covers formats, request limits, partial success, reconnect, and close behavior.

## SIP operations

Use the [SIP API reference](/realtime/sfu/features/sip/api/) to configure dial-in addresses, accept or reject incoming calls, change the audio a caller hears, and end calls. For a first call, follow [Receive SIP calls](/realtime/sfu/features/sip/).

## Batch resource operations

Track and DataChannel create, update, and close operations accept multiple entries in their `tracks` or `dataChannels` array. For example, publish camera and microphone tracks together, or request several publications in one receiving-session call. Each batch targets the session in the request URL.
Expand Down
4 changes: 2 additions & 2 deletions src/content/docs/realtime/sfu/features/index.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Features
description: Add application messages, video quality selection, and WebSocket media integration to your Realtime SFU application.
description: Add application messages, video quality selection, SIP dial-in, and WebSocket media integration to your Realtime SFU application.
pcx_content_type: navigation
sidebar:
order: 3
Expand All @@ -10,6 +10,6 @@ products:

import { DirectoryListing } from "~/components";

Use DataChannels for application messages, simulcast for multiple video qualities, and media adapters to connect external services.
Use DataChannels for application messages, simulcast for multiple video qualities, and media adapters to connect external services. Use [SIP dial-in](/realtime/sfu/features/sip/) to connect phone callers to your app.

<DirectoryListing />
92 changes: 92 additions & 0 deletions src/content/docs/realtime/sfu/features/sip/api.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
---
title: SIP API reference
description: Look up Realtime SFU SIP configuration and call operations, credential rotation, audio mix limits, and retry behavior.
pcx_content_type: reference
sidebar:
label: SIP API
order: 3
products:
- realtime
---

Use the SIP API from your backend to manage dial-in addresses and incoming calls. All paths on this page are relative to the app's SIP base URL.

```txt
https://rtc.live.cloudflare.com/v1/apps/{appId}/sip
```

Authenticate with `Authorization: Bearer <APP_SECRET>`. For requests with a JSON body, send `Content-Type: application/json`. To set up your first call, follow [Receive SIP calls](/realtime/sfu/features/sip/).

## Manage a dial-in address

Each configuration has its own SIP URI, digest credentials, and HTTPS webhook. The default limit is 10 configurations per app, including disabled ones.

| Method and path | Request and result |
| ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `POST /configs` | Send `name` and `webhook: {url, signingSecret}`. The optional `enabled` defaults to `false`. Save the returned `id`, `version`, `sipUri`, `username`, and one-time `password`. |
| `GET /configs` | Returns `configs`, `configCount`, and `maxConfigsPerApp`. Pass `nextCursor` as `cursor` for the next page. The default page size is 50. Use `limit` to request up to 100. |
| `GET /configs/{id}` | Read the current version, address, username, and webhook metadata. Reads omit the password and signing key. |
| `PATCH /configs/{id}` | Change `name`, `enabled`, or `webhook`. To change the webhook, supply both its HTTPS URL and signing key. |
| `POST /configs/{id}/rotate-credentials` | Issue a new password. The URI and username stay the same. Save the password from this response. |
| `DELETE /configs/{id}/previous-credentials` | Revoke the previous password immediately during a rotation grace period. |
| `DELETE /configs/{id}` | Remove the configuration and free its quota slot. |

For updates, send the quoted configuration version in `If-Match`, for example `If-Match: "1"`. If creation times out, list configurations before trying again. If the configuration exists and you lost the password, rotate it.

If a request returns `403`, check that the app has SIP access. For `429` with `sip_config_limit_exceeded`, delete an unused configuration to free a slot.

### Rotate credentials

By default, rotation invalidates the old password immediately. To give your provider time to switch passwords, set `previousSecretTtlSeconds` when you rotate. For example, `{"previousSecretTtlSeconds":3600}` keeps the previous password valid for one hour. The maximum is seven days. Rotating again replaces the previous password.

### Disable a dial-in address

Disabling or deleting a configuration stops new calls. Existing calls can finish and still send events to their original webhook. To disconnect a caller, use the [terminate operation](#control-a-call).

### Route calls within one configuration

Append an optional destination to the returned address, for example `;destination=support`. Keep the generated username intact. Use one to 256 ASCII letters, digits, or characters from `._~-`. Cloudflare includes the value in the webhook and call state. Check it against the destinations your app serves before selecting a room or audio track.

## Control a call

Use the Cloudflare `callId` from the [signed webhook](/realtime/sfu/features/sip/webhooks/) for every call operation. Your provider's SIP Call-ID and Twilio's Call SID identify different resources.

| Method and path | When to use it |
| -------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| `GET /calls/{callId}` | Read `status`, `sipFrom`, `sipTo`, and any `callsIngress` track. An ended call includes its termination details. |
| `POST /calls/{callId}/accept` | Answer a pending call. Send `{}` for silence or provide `initialMixConfig.inputs`. The response gives you the caller's SFU track. |
| `POST /calls/{callId}/reject` | Decline a pending call, for example with `{"statusCode":486,"reason":"Busy Here"}`. The SIP status code must be an integer from 400 to 699. |
| `POST /calls/{callId}/mix` | Replace the complete set of tracks a connected caller hears. |
| `POST /calls/{callId}/terminate` | Hang up an accepted or connected call, for example with `{"reason":"agent_hangup"}`. Repeating this on an ended call returns its final state. |

Reject and terminate reasons must be nonempty, single-line strings of up to 256 UTF-8 bytes.

### Call states and timeouts

| `status` | Meaning for your app |
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `SIP_CALL_STATUS_PENDING` | The phone is ringing. Send a decision within the default 30-second window. A caller can cancel first. |
| `SIP_CALL_STATUS_ACCEPTED` | Cloudflare has recorded your decision and is setting up the audio. |
| `SIP_CALL_STATUS_CONNECTED` | Cloudflare has answered. The provider has up to 32 seconds to acknowledge the SIP answer. A missing acknowledgment can still end the call with `ack_timeout`. |
| `SIP_CALL_STATUS_TERMINATED` | Stop ringing and release resources. Check `terminatedReason` for details such as `caller_bye` or `pending_timeout`. |

If an accept, reject, or terminate request times out or returns HTTP `503`, read the call state before retrying the same decision. A competing decision or a caller who has already hung up can produce HTTP `409`.

## Change what the caller hears

Use the session ID and track name of each publisher in the same SFU app. Include up to 32 distinct tracks. Each must be a single audio track with no variants, encoded as Opus, PCMA, or PCMU. Exclude the caller's own `callsIngress` track. An empty list sends silence to the caller while the caller's microphone remains available to subscribers.

For a connected call, send the **entire** new list, including tracks you want to keep. For example, to switch the caller to the second agent's microphone, send the following body to `POST /calls/{callId}/mix`.

```json
{
"requestId": "transfer-to-agent-2",
"mixConfig": {
"inputs": [{ "sessionId": "agent-2-session", "trackName": "microphone" }]
}
}
```

Make one update at a time per call. Choose a new `requestId` for each change. After a timeout or HTTP `503`, retry with the same ID and input set. Reusing the ID with different inputs returns `400`. Retrying an update that a newer one has replaced returns `409`.

The call state includes `desiredMixConfig` and `desiredMixRevision` as soon as Cloudflare records the request. A successful `POST /mix` confirms that Cloudflare applied that revision. To verify audible media, check that each selected publisher is still sending audio.
Loading