setayesh / turn.py
digitalai's picture
Create turn.py
f4ee378
raw
history blame contribute delete
676 Bytes
import logging
import os
import streamlit as st
from twilio.rest import Client
logger = logging.getLogger(__name__)
@st.cache_data # type: ignore
def get_ice_servers():
# Ref: https://www.twilio.com/docs/stun-turn/api
try:
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
except KeyError:
logger.warning(
"Twilio credentials are not set. Fallback to a free STUN server from Google." # noqa: E501
)
return [{"urls": ["stun:stun.l.google.com:19302"]}]
client = Client(account_sid, auth_token)
token = client.tokens.create()
return token.ice_servers