Cache HF TURN server and add an invalid TURN server option for experiment
Browse files
main.py
CHANGED
@@ -12,6 +12,10 @@ def cached_get_twilio_ice_servers():
|
|
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 |
|
@@ -32,15 +36,12 @@ elif frontend_ice_type == "Twilio STUN/TURN and Google STUN":
|
|
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"])
|
36 |
frontend_rtc_configuration = {
|
37 |
-
"iceServers":
|
38 |
}
|
39 |
elif frontend_ice_type == "HF TURN and Google STUN":
|
40 |
-
hf_ice_servers = get_hf_ice_servers(token=st.secrets["HF_TOKEN"])
|
41 |
-
ice_servers = hf_ice_servers + google_stun_ice_servers
|
42 |
frontend_rtc_configuration = {
|
43 |
-
"iceServers":
|
44 |
}
|
45 |
elif frontend_ice_type == "None configured":
|
46 |
frontend_rtc_configuration = None
|
@@ -62,20 +63,25 @@ elif backend_ice_type == "Twilio STUN/TURN and Google STUN":
|
|
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"])
|
66 |
backend_rtc_configuration = {
|
67 |
-
"iceServers":
|
68 |
}
|
69 |
elif backend_ice_type == "HF TURN and Google STUN":
|
70 |
-
hf_ice_servers = get_hf_ice_servers(token=st.secrets["HF_TOKEN"])
|
71 |
-
ice_servers = hf_ice_servers + google_stun_ice_servers
|
72 |
backend_rtc_configuration = {
|
73 |
-
"iceServers":
|
74 |
}
|
75 |
elif backend_ice_type == "None configured":
|
76 |
backend_rtc_configuration = None
|
77 |
|
78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
st.write("Frontend ICE configuration:", frontend_rtc_configuration)
|
80 |
st.write("Backend ICE configuration:", backend_rtc_configuration)
|
81 |
|
|
|
12 |
twilio_token=st.secrets["TWILIO_AUTH_TOKEN"],
|
13 |
)
|
14 |
|
15 |
+
@st.cache_data
|
16 |
+
def cached_get_hf_ice_servers():
|
17 |
+
return get_hf_ice_servers(token=st.secrets["HF_TOKEN"])
|
18 |
+
|
19 |
# google_stun_ice_servers = [{"urls": ["stun:stun.l.google.com:19302"]}]
|
20 |
google_stun_ice_servers = [{"urls": "stun:stun.l.google.com:19302", "url": "stun:stun.l.google.com:19302"}]
|
21 |
|
|
|
36 |
"iceServers": google_stun_ice_servers + cached_get_twilio_ice_servers()
|
37 |
}
|
38 |
elif frontend_ice_type == "HF TURN only":
|
|
|
39 |
frontend_rtc_configuration = {
|
40 |
+
"iceServers": cached_get_hf_ice_servers()
|
41 |
}
|
42 |
elif frontend_ice_type == "HF TURN and Google STUN":
|
|
|
|
|
43 |
frontend_rtc_configuration = {
|
44 |
+
"iceServers": cached_get_hf_ice_servers() + google_stun_ice_servers
|
45 |
}
|
46 |
elif frontend_ice_type == "None configured":
|
47 |
frontend_rtc_configuration = None
|
|
|
63 |
"iceServers": google_stun_ice_servers + cached_get_twilio_ice_servers() + google_stun_ice_servers
|
64 |
}
|
65 |
elif backend_ice_type == "HF TURN only":
|
|
|
66 |
backend_rtc_configuration = {
|
67 |
+
"iceServers": cached_get_hf_ice_servers()
|
68 |
}
|
69 |
elif backend_ice_type == "HF TURN and Google STUN":
|
|
|
|
|
70 |
backend_rtc_configuration = {
|
71 |
+
"iceServers": cached_get_hf_ice_servers() + google_stun_ice_servers
|
72 |
}
|
73 |
elif backend_ice_type == "None configured":
|
74 |
backend_rtc_configuration = None
|
75 |
|
76 |
|
77 |
+
if st.checkbox("Add invalid TURN server"):
|
78 |
+
backend_rtc_configuration["iceServers"].append({
|
79 |
+
"urls":"turn:gradio-turn.com:80",
|
80 |
+
"username":"non-existing-username",
|
81 |
+
"credential":"non-existing-credential"
|
82 |
+
})
|
83 |
+
|
84 |
+
|
85 |
st.write("Frontend ICE configuration:", frontend_rtc_configuration)
|
86 |
st.write("Backend ICE configuration:", backend_rtc_configuration)
|
87 |
|