whitphx HF Staff commited on
Commit
1c95726
·
1 Parent(s): 6ee63a9

Update turn.py

Browse files
Files changed (1) hide show
  1. sample_utils/turn.py +9 -2
sample_utils/turn.py CHANGED
@@ -3,11 +3,12 @@ import os
3
 
4
  import streamlit as st
5
  from twilio.rest import Client
 
6
 
7
  logger = logging.getLogger(__name__)
8
 
9
 
10
- @st.cache_data
11
  def get_ice_servers():
12
  """Use Twilio's TURN server because Streamlit Community Cloud has changed
13
  its infrastructure and WebRTC connection cannot be established without TURN server now. # noqa: E501
@@ -28,6 +29,12 @@ def get_ice_servers():
28
 
29
  client = Client(account_sid, auth_token)
30
 
31
- token = client.tokens.create()
 
 
 
 
 
 
32
 
33
  return token.ice_servers
 
3
 
4
  import streamlit as st
5
  from twilio.rest import Client
6
+ from twilio.base.exceptions import TwilioRestException
7
 
8
  logger = logging.getLogger(__name__)
9
 
10
 
11
+ @st.cache_data # type: ignore
12
  def get_ice_servers():
13
  """Use Twilio's TURN server because Streamlit Community Cloud has changed
14
  its infrastructure and WebRTC connection cannot be established without TURN server now. # noqa: E501
 
29
 
30
  client = Client(account_sid, auth_token)
31
 
32
+ try:
33
+ token = client.tokens.create()
34
+ except TwilioRestException as e:
35
+ logger.warning(
36
+ f"Error occurred while accessing Twilio API. Fallback to a free STUN server from Google. ({e})" # noqa: E501
37
+ )
38
+ return [{"urls": ["stun:stun.l.google.com:19302"]}]
39
 
40
  return token.ice_servers