opencv-gui / utils /turn.py
samuellimabraz's picture
Add ICE server retrieval functionality for WebRTC
c5a4e4e unverified
raw
history blame
582 Bytes
import os, logging
from twilio.rest import Client
import streamlit as st
logger = logging.getLogger(__name__)
@st.cache_data
def get_ice_servers():
try:
sid = os.environ["TWILIO_ACCOUNT_SID"]
token = os.environ["TWILIO_AUTH_TOKEN"]
except KeyError:
logger.warning("Twilio credentials not set; falling back to public STUN only.")
return [{"urls": ["stun:stun.l.google.com:19302"]}]
client = Client(sid, token)
# This will return both STUN and TURN servers from Twilio
token = client.tokens.create()
return token.ice_servers