diff --git a/sample_utils/turn.py b/sample_utils/turn.py index 47712be0..1b0a0bd4 100644 --- a/sample_utils/turn.py +++ b/sample_utils/turn.py @@ -2,6 +2,7 @@ import os import streamlit as st +from twilio.base.exceptions import TwilioRestException from twilio.rest import Client logger = logging.getLogger(__name__) @@ -28,6 +29,12 @@ def get_ice_servers(): client = Client(account_sid, auth_token) - token = client.tokens.create() + try: + token = client.tokens.create() + except TwilioRestException as e: + st.warning( + f"Error occurred while accessing Twilio API. Fallback to a free STUN server from Google. ({e})" # noqa: E501 + ) + return [{"urls": ["stun:stun.l.google.com:19302"]}] return token.ice_servers