whitphx HF Staff commited on
Commit
fe70231
·
1 Parent(s): ce3aaa3

Cache Twilio credentials

Browse files
Files changed (1) hide show
  1. main.py +11 -16
main.py CHANGED
@@ -5,6 +5,13 @@ import aiortc
5
  frontend_ice_type = st.selectbox("Frontend ICE type", ["Empty", "Google STUN", "Twilio STUN/TURN", "Twilio STUN/TURN and Google STUN", "HF TURN only", "HF TURN and Google STUN", "None configured"])
6
  backend_ice_type = st.selectbox("Backend ICE type", ["Empty", "Google STUN", "Twilio STUN/TURN", "Twilio STUN/TURN and Google STUN", "HF TURN only", "HF TURN and Google STUN", "None configured"])
7
 
 
 
 
 
 
 
 
8
  # google_stun_ice_servers = [{"urls": ["stun:stun.l.google.com:19302"]}]
9
  google_stun_ice_servers = [{"urls": "stun:stun.l.google.com:19302", "url": "stun:stun.l.google.com:19302"}]
10
 
@@ -18,17 +25,11 @@ elif frontend_ice_type == "Google STUN":
18
  }
19
  elif frontend_ice_type == "Twilio STUN/TURN":
20
  frontend_rtc_configuration = {
21
- "iceServers": get_twilio_ice_servers(
22
- twilio_sid=st.secrets["TWILIO_ACCOUNT_SID"],
23
- twilio_token=st.secrets["TWILIO_AUTH_TOKEN"],
24
- )
25
  }
26
  elif frontend_ice_type == "Twilio STUN/TURN and Google STUN":
27
  frontend_rtc_configuration = {
28
- "iceServers": google_stun_ice_servers + get_twilio_ice_servers(
29
- twilio_sid=st.secrets["TWILIO_ACCOUNT_SID"],
30
- twilio_token=st.secrets["TWILIO_AUTH_TOKEN"],
31
- )
32
  }
33
  elif frontend_ice_type == "HF TURN only":
34
  hf_ice_servers = get_hf_ice_servers(token=st.secrets["HF_TOKEN"])
@@ -54,17 +55,11 @@ elif backend_ice_type == "Google STUN":
54
  }
55
  elif backend_ice_type == "Twilio STUN/TURN":
56
  backend_rtc_configuration = {
57
- "iceServers": get_twilio_ice_servers(
58
- twilio_sid=st.secrets["TWILIO_ACCOUNT_SID"],
59
- twilio_token=st.secrets["TWILIO_AUTH_TOKEN"],
60
- )
61
  }
62
  elif backend_ice_type == "Twilio STUN/TURN and Google STUN":
63
  backend_rtc_configuration = {
64
- "iceServers": google_stun_ice_servers + get_twilio_ice_servers(
65
- twilio_sid=st.secrets["TWILIO_ACCOUNT_SID"],
66
- twilio_token=st.secrets["TWILIO_AUTH_TOKEN"],
67
- ) + google_stun_ice_servers
68
  }
69
  elif backend_ice_type == "HF TURN only":
70
  hf_ice_servers = get_hf_ice_servers(token=st.secrets["HF_TOKEN"])
 
5
  frontend_ice_type = st.selectbox("Frontend ICE type", ["Empty", "Google STUN", "Twilio STUN/TURN", "Twilio STUN/TURN and Google STUN", "HF TURN only", "HF TURN and Google STUN", "None configured"])
6
  backend_ice_type = st.selectbox("Backend ICE type", ["Empty", "Google STUN", "Twilio STUN/TURN", "Twilio STUN/TURN and Google STUN", "HF TURN only", "HF TURN and Google STUN", "None configured"])
7
 
8
+ @st.cache_data
9
+ def cached_get_twilio_ice_servers():
10
+ return get_twilio_ice_servers(
11
+ twilio_sid=st.secrets["TWILIO_ACCOUNT_SID"],
12
+ twilio_token=st.secrets["TWILIO_AUTH_TOKEN"],
13
+ )
14
+
15
  # google_stun_ice_servers = [{"urls": ["stun:stun.l.google.com:19302"]}]
16
  google_stun_ice_servers = [{"urls": "stun:stun.l.google.com:19302", "url": "stun:stun.l.google.com:19302"}]
17
 
 
25
  }
26
  elif frontend_ice_type == "Twilio STUN/TURN":
27
  frontend_rtc_configuration = {
28
+ "iceServers": cached_get_twilio_ice_servers()
 
 
 
29
  }
30
  elif frontend_ice_type == "Twilio STUN/TURN and Google STUN":
31
  frontend_rtc_configuration = {
32
+ "iceServers": google_stun_ice_servers + cached_get_twilio_ice_servers()
 
 
 
33
  }
34
  elif frontend_ice_type == "HF TURN only":
35
  hf_ice_servers = get_hf_ice_servers(token=st.secrets["HF_TOKEN"])
 
55
  }
56
  elif backend_ice_type == "Twilio STUN/TURN":
57
  backend_rtc_configuration = {
58
+ "iceServers": cached_get_twilio_ice_servers()
 
 
 
59
  }
60
  elif backend_ice_type == "Twilio STUN/TURN and Google STUN":
61
  backend_rtc_configuration = {
62
+ "iceServers": google_stun_ice_servers + cached_get_twilio_ice_servers() + google_stun_ice_servers
 
 
 
63
  }
64
  elif backend_ice_type == "HF TURN only":
65
  hf_ice_servers = get_hf_ice_servers(token=st.secrets["HF_TOKEN"])