whitphx HF Staff commited on
Commit
34947c3
·
1 Parent(s): fe9aac5

Add HF TURN server configs

Browse files
Files changed (1) hide show
  1. main.py +26 -3
main.py CHANGED
@@ -1,8 +1,8 @@
1
  import streamlit as st
2
- from streamlit_webrtc import webrtc_streamer, get_twilio_ice_servers, __version__ as st_webrtc_version
3
 
4
- frontend_ice_type = st.selectbox("Frontend ICE type", ["Empty", "Google STUN", "Twilio TURN"])
5
- backend_ice_type = st.selectbox("Backend ICE type", ["Empty", "Google STUN", "Twilio TURN"])
6
 
7
  if frontend_ice_type == "Empty":
8
  frontend_rtc_configuration = {
@@ -19,6 +19,17 @@ elif frontend_ice_type == "Twilio TURN":
19
  twilio_token=st.secrets["TWILIO_AUTH_TOKEN"],
20
  )
21
  }
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  if backend_ice_type == "Empty":
24
  backend_rtc_configuration = {
@@ -35,6 +46,18 @@ elif backend_ice_type == "Twilio TURN":
35
  twilio_token=st.secrets["TWILIO_AUTH_TOKEN"],
36
  )
37
  }
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
  st.write("Frontend ICE configuration:", frontend_rtc_configuration)
40
  st.write("Backend ICE configuration:", backend_rtc_configuration)
 
1
  import streamlit as st
2
+ from streamlit_webrtc import webrtc_streamer, get_hf_ice_servers, get_twilio_ice_servers, __version__ as st_webrtc_version
3
 
4
+ frontend_ice_type = st.selectbox("Frontend ICE type", ["Empty", "Google STUN", "Twilio TURN", "HF TURN only", "HF TURN and Google STUN"])
5
+ backend_ice_type = st.selectbox("Backend ICE type", ["Empty", "Google STUN", "Twilio TURN", "HF TURN only", "HF TURN and Google STUN"])
6
 
7
  if frontend_ice_type == "Empty":
8
  frontend_rtc_configuration = {
 
19
  twilio_token=st.secrets["TWILIO_AUTH_TOKEN"],
20
  )
21
  }
22
+ elif frontend_ice_type == "HF TURN only":
23
+ hf_ice_servers = get_hf_ice_servers(token=st.secrets["HF_TOKEN"])
24
+ frontend_rtc_configuration = {
25
+ "iceServers": hf_ice_servers
26
+ }
27
+ elif frontend_ice_type == "HF TURN and Google STUN":
28
+ hf_ice_servers = get_hf_ice_servers(token=st.secrets["HF_TOKEN"])
29
+ ice_servers = hf_ice_servers + [{"urls": ["stun:stun.l.google.com:19302"]}]
30
+ frontend_rtc_configuration = {
31
+ "iceServers": ice_servers
32
+ }
33
 
34
  if backend_ice_type == "Empty":
35
  backend_rtc_configuration = {
 
46
  twilio_token=st.secrets["TWILIO_AUTH_TOKEN"],
47
  )
48
  }
49
+ elif backend_ice_type == "HF TURN only":
50
+ hf_ice_servers = get_hf_ice_servers(token=st.secrets["HF_TOKEN"])
51
+ backend_rtc_configuration = {
52
+ "iceServers": hf_ice_servers
53
+ }
54
+ elif backend_ice_type == "HF TURN and Google STUN":
55
+ hf_ice_servers = get_hf_ice_servers(token=st.secrets["HF_TOKEN"])
56
+ ice_servers = hf_ice_servers + [{"urls": ["stun:stun.l.google.com:19302"]}]
57
+ backend_rtc_configuration = {
58
+ "iceServers": ice_servers
59
+ }
60
+
61
 
62
  st.write("Frontend ICE configuration:", frontend_rtc_configuration)
63
  st.write("Backend ICE configuration:", backend_rtc_configuration)