Spaces:
Running
Running
Add ICE server retrieval functionality for WebRTC
Browse files- Introduced a new utility module to fetch ICE servers from Twilio, enhancing connectivity options.
- Updated the WebRTC configuration in app.py to utilize the new get_ice_servers function for improved server management.
- app.py +2 -1
- utils/turn.py +19 -0
app.py
CHANGED
@@ -4,6 +4,7 @@ import numpy as np
|
|
4 |
import streamlit as st
|
5 |
from streamlit_webrtc import webrtc_streamer, WebRtcMode
|
6 |
from src.opencv_utils import OpenCVUtils
|
|
|
7 |
|
8 |
st.set_page_config(page_title="OpenCV Explorer", page_icon="🎨", layout="wide")
|
9 |
|
@@ -122,7 +123,7 @@ def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
|
|
122 |
webrtc_streamer(
|
123 |
key="opencv-explorer",
|
124 |
mode=WebRtcMode.SENDRECV,
|
125 |
-
|
126 |
video_frame_callback=video_frame_callback,
|
127 |
media_stream_constraints={"video": True, "audio": False},
|
128 |
async_processing=True,
|
|
|
4 |
import streamlit as st
|
5 |
from streamlit_webrtc import webrtc_streamer, WebRtcMode
|
6 |
from src.opencv_utils import OpenCVUtils
|
7 |
+
from utils.turn import get_ice_servers
|
8 |
|
9 |
st.set_page_config(page_title="OpenCV Explorer", page_icon="🎨", layout="wide")
|
10 |
|
|
|
123 |
webrtc_streamer(
|
124 |
key="opencv-explorer",
|
125 |
mode=WebRtcMode.SENDRECV,
|
126 |
+
rrtc_configuration={"iceServers": get_ice_servers()},
|
127 |
video_frame_callback=video_frame_callback,
|
128 |
media_stream_constraints={"video": True, "audio": False},
|
129 |
async_processing=True,
|
utils/turn.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os, logging
|
2 |
+
from twilio.rest import Client
|
3 |
+
import streamlit as st
|
4 |
+
|
5 |
+
logger = logging.getLogger(__name__)
|
6 |
+
|
7 |
+
|
8 |
+
@st.cache_data
|
9 |
+
def get_ice_servers():
|
10 |
+
try:
|
11 |
+
sid = os.environ["TWILIO_ACCOUNT_SID"]
|
12 |
+
token = os.environ["TWILIO_AUTH_TOKEN"]
|
13 |
+
except KeyError:
|
14 |
+
logger.warning("Twilio credentials not set; falling back to public STUN only.")
|
15 |
+
return [{"urls": ["stun:stun.l.google.com:19302"]}]
|
16 |
+
client = Client(sid, token)
|
17 |
+
# This will return both STUN and TURN servers from Twilio
|
18 |
+
token = client.tokens.create()
|
19 |
+
return token.ice_servers
|