From d1ab1d38b79e2e2409b4cf133b573a74144ad7a2 Mon Sep 17 00:00:00 2001 From: Filipi Fuchter Date: Tue, 29 Apr 2025 10:33:19 -0300 Subject: [PATCH] Fixing the examples to use the new IceServer structure. --- examples/foundational/run.py | 8 ++++++-- examples/p2p-webrtc/daily-interop-bridge/server.py | 8 ++++++-- examples/p2p-webrtc/video-transform/server/server.py | 8 ++++++-- examples/p2p-webrtc/voice-agent/server.py | 11 +++++++++-- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/examples/foundational/run.py b/examples/foundational/run.py index fc8b631b4..e7012c9e9 100644 --- a/examples/foundational/run.py +++ b/examples/foundational/run.py @@ -20,7 +20,7 @@ from fastapi.responses import RedirectResponse from loguru import logger from pipecat_ai_small_webrtc_prebuilt.frontend import SmallWebRTCPrebuiltUI -from pipecat.transports.network.webrtc_connection import SmallWebRTCConnection +from pipecat.transports.network.webrtc_connection import IceServer, SmallWebRTCConnection # Load environment variables load_dotenv(override=True) @@ -30,7 +30,11 @@ app = FastAPI() # Store connections by pc_id pcs_map: Dict[str, SmallWebRTCConnection] = {} -ice_servers = ["stun:stun.l.google.com:19302"] +ice_servers = [ + IceServer( + urls="stun:stun.l.google.com:19302", + ) +] # Mount the frontend at / app.mount("/client", SmallWebRTCPrebuiltUI) diff --git a/examples/p2p-webrtc/daily-interop-bridge/server.py b/examples/p2p-webrtc/daily-interop-bridge/server.py index d65bd3013..0025b3490 100644 --- a/examples/p2p-webrtc/daily-interop-bridge/server.py +++ b/examples/p2p-webrtc/daily-interop-bridge/server.py @@ -18,7 +18,7 @@ from fastapi.responses import RedirectResponse from loguru import logger from pipecat_ai_small_webrtc_prebuilt.frontend import SmallWebRTCPrebuiltUI -from pipecat.transports.network.webrtc_connection import SmallWebRTCConnection +from pipecat.transports.network.webrtc_connection import IceServer, SmallWebRTCConnection # Load environment variables load_dotenv(override=True) @@ -28,7 +28,11 @@ app = FastAPI() # Store connections by pc_id pcs_map: Dict[str, SmallWebRTCConnection] = {} -ice_servers = ["stun:stun.l.google.com:19302"] +ice_servers = [ + IceServer( + urls="stun:stun.l.google.com:19302", + ) +] # Mount the frontend at / app.mount("/prebuilt", SmallWebRTCPrebuiltUI) diff --git a/examples/p2p-webrtc/video-transform/server/server.py b/examples/p2p-webrtc/video-transform/server/server.py index d65bd3013..0025b3490 100644 --- a/examples/p2p-webrtc/video-transform/server/server.py +++ b/examples/p2p-webrtc/video-transform/server/server.py @@ -18,7 +18,7 @@ from fastapi.responses import RedirectResponse from loguru import logger from pipecat_ai_small_webrtc_prebuilt.frontend import SmallWebRTCPrebuiltUI -from pipecat.transports.network.webrtc_connection import SmallWebRTCConnection +from pipecat.transports.network.webrtc_connection import IceServer, SmallWebRTCConnection # Load environment variables load_dotenv(override=True) @@ -28,7 +28,11 @@ app = FastAPI() # Store connections by pc_id pcs_map: Dict[str, SmallWebRTCConnection] = {} -ice_servers = ["stun:stun.l.google.com:19302"] +ice_servers = [ + IceServer( + urls="stun:stun.l.google.com:19302", + ) +] # Mount the frontend at / app.mount("/prebuilt", SmallWebRTCPrebuiltUI) diff --git a/examples/p2p-webrtc/voice-agent/server.py b/examples/p2p-webrtc/voice-agent/server.py index 3706455a5..b2ee0b4cd 100644 --- a/examples/p2p-webrtc/voice-agent/server.py +++ b/examples/p2p-webrtc/voice-agent/server.py @@ -17,7 +17,7 @@ from fastapi import BackgroundTasks, FastAPI from fastapi.responses import FileResponse from loguru import logger -from pipecat.transports.network.webrtc_connection import SmallWebRTCConnection +from pipecat.transports.network.webrtc_connection import IceServer, SmallWebRTCConnection # Load environment variables load_dotenv(override=True) @@ -28,6 +28,13 @@ app = FastAPI() pcs_map: Dict[str, SmallWebRTCConnection] = {} +ice_servers = [ + IceServer( + urls="stun:stun.l.google.com:19302", + ) +] + + @app.post("/api/offer") async def offer(request: dict, background_tasks: BackgroundTasks): pc_id = request.get("pc_id") @@ -37,7 +44,7 @@ async def offer(request: dict, background_tasks: BackgroundTasks): logger.info(f"Reusing existing connection for pc_id: {pc_id}") await pipecat_connection.renegotiate(sdp=request["sdp"], type=request["type"]) else: - pipecat_connection = SmallWebRTCConnection() + pipecat_connection = SmallWebRTCConnection(ice_servers) await pipecat_connection.initialize(sdp=request["sdp"], type=request["type"]) @pipecat_connection.event_handler("closed")