whitphx HF staff commited on
Commit
421a2dd
1 Parent(s): 47644bc

Use Open Relay

Browse files
Files changed (2) hide show
  1. app.py +6 -1
  2. turn.py +26 -0
app.py CHANGED
@@ -1,3 +1,8 @@
1
  from streamlit_webrtc import webrtc_streamer
2
 
3
- webrtc_streamer(key="sample")
 
 
 
 
 
1
  from streamlit_webrtc import webrtc_streamer
2
 
3
+ from turn import get_ice_servers
4
+
5
+ webrtc_streamer(
6
+ key="sample",
7
+ rtc_configuration={"iceServers": get_ice_servers()},
8
+ )
turn.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import logging
2
+ import os
3
+
4
+ import requests
5
+ import streamlit as st
6
+
7
+ logger = logging.getLogger(__name__)
8
+
9
+
10
+ OPEN_RELAY_API_HOST = os.environ.get("OPEN_RELAY_API_HOST")
11
+ OPEN_RELAY_API_KEY = os.environ.get("OPEN_RELAY_API_KEY")
12
+
13
+
14
+ @st.cache_data
15
+ def get_ice_servers():
16
+ if not OPEN_RELAY_API_HOST or not OPEN_RELAY_API_KEY:
17
+ logger.warning(
18
+ "Open Relay API host or key is not set. Fallback to a free STUN server from Google." # noqa: E501
19
+ )
20
+ return [{"urls": ["stun:stun.l.google.com:19302"]}]
21
+
22
+ # Get response from Open Relay API
23
+ response = requests.get(
24
+ f"https://{OPEN_RELAY_API_HOST}/api/v1/turn/credentials?apiKey={OPEN_RELAY_API_KEY}" # noqa: E501
25
+ )
26
+ return response.json()