File size: 3,014 Bytes
0d338e8
34947c3
d79183c
af3ede9
 
d79183c
0d338e8
4196959
 
 
0d338e8
 
 
 
 
 
 
 
 
 
 
34947c3
 
 
 
 
 
 
 
 
 
 
af3ede9
 
0d338e8
 
4196959
 
 
0d338e8
 
 
 
 
 
 
 
 
 
 
34947c3
 
 
 
 
 
 
 
 
 
 
af3ede9
 
34947c3
0d338e8
 
 
 
 
 
 
 
 
 
69afee6
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import streamlit as st
from streamlit_webrtc import webrtc_streamer, get_hf_ice_servers, get_twilio_ice_servers, __version__ as st_webrtc_version

frontend_ice_type = st.selectbox("Frontend ICE type", ["Empty", "Google STUN", "Twilio TURN", "HF TURN only", "HF TURN and Google STUN", "None configured"])
backend_ice_type = st.selectbox("Backend ICE type", ["Empty", "Google STUN", "Twilio TURN", "HF TURN only", "HF TURN and Google STUN", "None configured"])

if frontend_ice_type == "Empty":
    frontend_rtc_configuration = {
        "iceServers": []
    }
elif frontend_ice_type == "Google STUN":
    frontend_rtc_configuration = {
        "iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]
    }
elif frontend_ice_type == "Twilio TURN":
    frontend_rtc_configuration = {
        "iceServers": get_twilio_ice_servers(
            twilio_sid=st.secrets["TWILIO_ACCOUNT_SID"],
            twilio_token=st.secrets["TWILIO_AUTH_TOKEN"],
        )
    }
elif frontend_ice_type == "HF TURN only":
    hf_ice_servers = get_hf_ice_servers(token=st.secrets["HF_TOKEN"])
    frontend_rtc_configuration = {
        "iceServers": hf_ice_servers
    }
elif frontend_ice_type == "HF TURN and Google STUN":
    hf_ice_servers = get_hf_ice_servers(token=st.secrets["HF_TOKEN"])
    ice_servers = hf_ice_servers + [{"urls": ["stun:stun.l.google.com:19302"]}]
    frontend_rtc_configuration = {
        "iceServers": ice_servers
    }
elif frontend_ice_type == "None configured":
    frontend_rtc_configuration = None

if backend_ice_type == "Empty":
    backend_rtc_configuration = {
        "iceServers": []
    }
elif backend_ice_type == "Google STUN":
    backend_rtc_configuration = {
        "iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]
    }
elif backend_ice_type == "Twilio TURN":
    backend_rtc_configuration = {
        "iceServers": get_twilio_ice_servers(
            twilio_sid=st.secrets["TWILIO_ACCOUNT_SID"],
            twilio_token=st.secrets["TWILIO_AUTH_TOKEN"],
        )
    }
elif backend_ice_type == "HF TURN only":
    hf_ice_servers = get_hf_ice_servers(token=st.secrets["HF_TOKEN"])
    backend_rtc_configuration = {
        "iceServers": hf_ice_servers
    }
elif backend_ice_type == "HF TURN and Google STUN":
    hf_ice_servers = get_hf_ice_servers(token=st.secrets["HF_TOKEN"])
    ice_servers = hf_ice_servers + [{"urls": ["stun:stun.l.google.com:19302"]}]
    backend_rtc_configuration = {
        "iceServers": ice_servers
    }
elif backend_ice_type == "None configured":
    backend_rtc_configuration = None


st.write("Frontend ICE configuration:", frontend_rtc_configuration)
st.write("Backend ICE configuration:", backend_rtc_configuration)

webrtc_streamer(
    key="example",
    media_stream_constraints={"video": True, "audio": False},
    frontend_rtc_configuration=frontend_rtc_configuration,
    server_rtc_configuration=backend_rtc_configuration,
)

st.write(f"Streamlit version: {st.__version__}")
st.write(f"Streamlit-Webrtc version: {st_webrtc_version}")