Set ice candidates server (#285)

* Add code

* Add code

* Code
This commit is contained in:
Freddy Boulton
2025-04-17 10:20:53 -04:00
committed by GitHub
parent 72fdc74e82
commit c9bca428af
7 changed files with 59 additions and 21 deletions

View File

@@ -13,7 +13,7 @@ Cloudflare also offers a managed TURN server with [Cloudflare Calls](https://www
Cloudflare and Hugging Face have partnered to allow you to stream 10gb of WebRTC traffic per month for free with a Hugging Face account!
```python
from fastrtc import Stream, get_cloudflare_turn_credentials_async
from fastrtc import Stream, get_cloudflare_turn_credentials_async, get_cloudflare_turn_credentials
# Make sure the HF_TOKEN environment variable is set
# Or pass in a callable with all arguments set
@@ -26,11 +26,14 @@ async def get_credentials():
stream = Stream(
handler=...,
rtc_configuration=get_credentials,
server_rtc_configuration=get_cloudflare_turn_credentials(ttl=360_000)
modality="audio",
mode="send-receive",
)
```
!!! tip
Setting an rtc configuration in the server is recommended but not required. It's a good practice to set short lived credentials in the client (default `ttl` value of 10 minutes when calling `get_cloudflare_turn_credentials*`) but you can share the same credentials between server and client.
### With a Cloudflare API Token

View File

@@ -39,7 +39,8 @@ This class encapsulates the logic for handling real-time communication (WebRTC)
| `additional_outputs_handler` | `Callable \| None` | Handler for additional outputs. |
| `track_constraints` | `dict[str, Any] \| None` | Constraints for media tracks (e.g., resolution). |
| `webrtc_component` | `WebRTC` | The underlying Gradio WebRTC component instance. |
| `rtc_configuration` | `dict[str, Any] \| None` | Configuration for the RTCPeerConnection (e.g., ICE servers). |
| `rtc_configuration` | `dict[str, Any] \| None \| Callable` | Configuration for the RTCPeerConnection (e.g., ICE servers). |
| `server_rtc_configuration` | `dict[str, Any] \| None` | Configuration for the RTCPeerConnection (e.g., ICE servers) to be used in the server |
| `_ui` | `Blocks` | The Gradio Blocks UI instance. |
## Methods