From d80d385b2f77e3a5cd21ca2f2fd193f4ccedc232 Mon Sep 17 00:00:00 2001 From: Filipi Fuchter Date: Tue, 29 Apr 2025 12:19:59 -0300 Subject: [PATCH] Adding a section explaining about ice servers. --- examples/p2p-webrtc/voice-agent/README.md | 40 ++++++++++++++++++++++ examples/p2p-webrtc/voice-agent/index.html | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/examples/p2p-webrtc/voice-agent/README.md b/examples/p2p-webrtc/voice-agent/README.md index 17bf165af..a4f6f0b2a 100644 --- a/examples/p2p-webrtc/voice-agent/README.md +++ b/examples/p2p-webrtc/voice-agent/README.md @@ -46,6 +46,46 @@ http://localhost:7860 --- +## WebRTC ICE Servers Configuration + +When implementing WebRTC in your project, **STUN** (Session Traversal Utilities for NAT) and **TURN** (Traversal Using Relays around NAT) +servers are usually needed in cases where users are behind routers or firewalls. + +In local networks (e.g., testing within the same home or office network), you usually don’t need to configure STUN or TURN servers. +In such cases, WebRTC can often directly establish peer-to-peer connections without needing to traverse NAT or firewalls. + +### What are STUN and TURN Servers? + +- **STUN Server**: Helps clients discover their public IP address and port when they're behind a NAT (Network Address Translation) device (like a router). +This allows WebRTC to attempt direct peer-to-peer communication by providing the public-facing IP and port. + +- **TURN Server**: Used as a fallback when direct peer-to-peer communication isn't possible due to strict NATs or firewalls blocking connections. +The TURN server relays media traffic between peers. + +### Why are ICE Servers Important? + +**ICE (Interactive Connectivity Establishment)** is a framework used by WebRTC to handle network traversal and NAT issues. +The `iceServers` configuration provides a list of **STUN** and **TURN** servers that WebRTC uses to find the best way to connect two peers. + +### Example Configuration for ICE Servers + +Here’s how you can configure a basic `iceServers` object in WebRTC for testing purposes, using Google's public STUN server: + +```javascript +const config = { + iceServers: [ + { + urls: ["stun:stun.l.google.com:19302"], // Google's public STUN server + } + ], +}; +``` + +> For testing purposes, you can either use public **STUN** servers (like Google's) or set up your own **TURN** server. +If you're running your own TURN server, make sure to include your server URL, username, and credential in the configuration. + +--- + ### 💡 Notes - Ensure all dependencies are installed before running the server. - Check the `.env` file for missing configurations. diff --git a/examples/p2p-webrtc/voice-agent/index.html b/examples/p2p-webrtc/voice-agent/index.html index a6def2b30..f39be3c28 100644 --- a/examples/p2p-webrtc/voice-agent/index.html +++ b/examples/p2p-webrtc/voice-agent/index.html @@ -55,7 +55,7 @@ const createSmallWebRTCConnection = async (audioTrack) => { const config = { - iceServers: [{ urls: ["stun:stun.l.google.com:19302"] }], + iceServers: [], }; const pc = new RTCPeerConnection(config) addPeerConnectionEventListeners(pc)