You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/calls/datachannels.mdx
+24-2Lines changed: 24 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,10 +3,32 @@ pcx_content_type: get-started
3
3
title: DataChannels
4
4
sidebar:
5
5
order: 8
6
-
7
6
---
8
7
9
-
Since Cloudflare Calls is basically a pub/sub server for WebRTC that can scale up to many subscribers per publisher, it's fit for arbitrary data besides media too.
8
+
DataChannels are a way to send arbitrary data, not just audio or video data, between client in low latency. DataChannels are useful for scenarios like chat, game state, or any other data that doesn't need to be encoded as audio or video but still needs to be sent between clients in real time.
9
+
10
+
While it is possible to send audio and video over DataChannels, it's not optimal because audio and video transfer includes media specific optimizations that DataChannels do not have, such as simulcast, forward error correction, better caching across the Cloudflare network for retransmissions.
B -->|Arbitrary data| C@{ shape: procs, label: "Subscribers"}
16
+
```
17
+
18
+
DataChannels on Cloudflare Calls can scale up to many subscribers per publisher, there is no limit to the number of subscribers per publisher.
19
+
20
+
### How to use DataChannels
21
+
22
+
1. Create a two Calls sessions, one for the publisher and one for the subscribers.
23
+
2. Create a DataChannel by calling /datachannels/new with the location set to "local" and the dataChannelName set to the name of the DataChannel.
24
+
3. Create a DataChannel by calling /datachannels/new with the location set to "remote" and the sessionId set to the sessionId of the publisher.
25
+
4. Use the DataChannel to send data from the publisher to the subscribers.
26
+
27
+
### Unidirectional DataChannels
28
+
29
+
Cloudflare Calls SFU DataChannels are one way only. This means that you can only send data from the publisher to the subscribers. Subscribers cannot send data back to the publisher. While regular MediaStream WebRTC DataChannels are bidirectional, this introduces a problem for Cloudflare Calls because the SFU does not know which session to send the data back to. This is especially problematic for scenarios where you have multiple subscribers and you want to send data from the publisher to all subscribers at scale, such as distributing game score updates to all players in a multiplayer game.
30
+
31
+
To send data in a bidirectional way, you can use two DataChannels, one for sending data from the publisher to the subscribers and one for sending data the opposite direction.
Copy file name to clipboardExpand all lines: src/content/docs/calls/https-api.mdx
+56-19Lines changed: 56 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,23 +3,22 @@ pcx_content_type: get-started
3
3
title: Connection API
4
4
sidebar:
5
5
order: 5
6
-
7
6
---
8
7
9
8
Cloudflare Calls simplifies the management of peer connections and media tracks through HTTPS API endpoints. These endpoints allow developers to efficiently manage sessions, add or remove tracks, and gather session information.
10
9
11
10
## API Endpoints
12
11
13
-
***Create a New Session**: Initiates a new session on Cloudflare Calls, which can be modified with other endpoints below.
14
-
*`POST /apps/{appId}/sessions/new`
15
-
***Add a New Track**: Adds a media track (audio or video) to an existing session.
-**Retrieve Session Information**: Fetches detailed information about a specific session.
21
+
-`GET /apps/{appId}/sessions/{sessionId}`
23
22
24
23
[View full API and schema (OpenAPI format)](/calls/static/calls-api-2024-05-21.yaml)
25
24
@@ -31,24 +30,62 @@ It is vital to manage App ID and its secret securely. While track and session ID
31
30
32
31
Cloudflare Calls is designed to operate efficiently without the need for TURN servers in most scenarios, as Cloudflare exposes a publicly routable IP address for Calls. However, integrating a STUN server can be necessary for facilitating peer discovery and connectivity.
Utilizing Cloudflare's STUN server can help the connection process for Calls applications.
37
36
38
37
## Lifecycle of a Simple Session
39
38
40
39
This section provides an overview of the typical lifecycle of a simple session, focusing on audio-only applications. It illustrates how clients are notified by the backend server as new remote clients join or leave, incorporating video would introduce additional tracks and considerations into the session.
41
40
42
-
<divclass="full-img">
41
+
```mermaid
42
+
sequenceDiagram
43
+
participant WA as WebRTC Agent
44
+
participant BS as Backend Server
45
+
participant CA as Calls API
46
+
47
+
Note over BS: Client Joins
48
+
49
+
WA->>BS: Request
50
+
BS->>CA: POST /sessions/new
51
+
CA->>BS: newSessionResponse
52
+
BS->>WA: Response
53
+
54
+
WA->>BS: Request
55
+
BS->>CA: POST /sessions/<ID>/tracks/new (Offer)
56
+
CA->>BS: newTracksResponse (Answer)
57
+
BS->>WA: Response
58
+
59
+
WA-->>CA: ICE Connectivity Check
60
+
Note over WA: iceconnectionstatechange (connected)
There is also a previously used, but now deprecated way to use the API illustrated below. If you are using this style please consider upgrading to the newer version illustrated above.
0 commit comments