Spaces:
Sleeping
Sleeping
fixed local + hosted STUN/TURN
Browse files- app.py +2 -1
- utils/turn.py +12 -4
app.py
CHANGED
@@ -134,11 +134,12 @@ def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
|
|
134 |
|
135 |
return av.VideoFrame.from_ndarray(image, format="bgr24")
|
136 |
|
|
|
137 |
|
138 |
webrtc_ctx = webrtc_streamer(
|
139 |
key="object-detection",
|
140 |
mode=WebRtcMode.SENDRECV,
|
141 |
-
rtc_configuration=
|
142 |
video_frame_callback=video_frame_callback,
|
143 |
media_stream_constraints={"video": True, "audio": False},
|
144 |
async_processing=True,
|
|
|
134 |
|
135 |
return av.VideoFrame.from_ndarray(image, format="bgr24")
|
136 |
|
137 |
+
ice_servers = get_ice_servers()
|
138 |
|
139 |
webrtc_ctx = webrtc_streamer(
|
140 |
key="object-detection",
|
141 |
mode=WebRtcMode.SENDRECV,
|
142 |
+
rtc_configuration=ice_servers,
|
143 |
video_frame_callback=video_frame_callback,
|
144 |
media_stream_constraints={"video": True, "audio": False},
|
145 |
async_processing=True,
|
utils/turn.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import logging
|
2 |
import os
|
3 |
|
4 |
import streamlit as st
|
@@ -16,6 +16,11 @@ def get_ice_servers():
|
|
16 |
See https://github.com/whitphx/streamlit-webrtc/issues/1213
|
17 |
"""
|
18 |
|
|
|
|
|
|
|
|
|
|
|
19 |
# Ref: https://www.twilio.com/docs/stun-turn/api
|
20 |
try:
|
21 |
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
|
@@ -24,7 +29,7 @@ def get_ice_servers():
|
|
24 |
logger.warning(
|
25 |
"Twilio credentials are not set. Fallback to a free STUN server from Google." # noqa: E501
|
26 |
)
|
27 |
-
return
|
28 |
|
29 |
client = Client(account_sid, auth_token)
|
30 |
|
@@ -34,6 +39,9 @@ def get_ice_servers():
|
|
34 |
st.warning(
|
35 |
f"Error occurred while accessing Twilio API. Fallback to a free STUN server from Google. ({e})" # noqa: E501
|
36 |
)
|
37 |
-
return
|
38 |
|
39 |
-
return
|
|
|
|
|
|
|
|
1 |
+
import logging
|
2 |
import os
|
3 |
|
4 |
import streamlit as st
|
|
|
16 |
See https://github.com/whitphx/streamlit-webrtc/issues/1213
|
17 |
"""
|
18 |
|
19 |
+
GOOGLE_RTC_CONFIGURATION = {
|
20 |
+
"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}],
|
21 |
+
"iceTransportPolicy": "all",
|
22 |
+
}
|
23 |
+
|
24 |
# Ref: https://www.twilio.com/docs/stun-turn/api
|
25 |
try:
|
26 |
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
|
|
|
29 |
logger.warning(
|
30 |
"Twilio credentials are not set. Fallback to a free STUN server from Google." # noqa: E501
|
31 |
)
|
32 |
+
return GOOGLE_RTC_CONFIGURATION
|
33 |
|
34 |
client = Client(account_sid, auth_token)
|
35 |
|
|
|
39 |
st.warning(
|
40 |
f"Error occurred while accessing Twilio API. Fallback to a free STUN server from Google. ({e})" # noqa: E501
|
41 |
)
|
42 |
+
return GOOGLE_RTC_CONFIGURATION
|
43 |
|
44 |
+
return {
|
45 |
+
"iceServers": token.ice_servers,
|
46 |
+
"iceTransportPolicy": "all",
|
47 |
+
}
|