streamlit-webrtc 0.56.0__py3-none-any.whl → 0.60.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -103,6 +103,12 @@ except ImportError:
103
103
  # streamlit < 1.27.0
104
104
  from streamlit import experimental_rerun as rerun # type: ignore
105
105
 
106
+ try:
107
+ from streamlit import cache_data # type: ignore
108
+ except ImportError:
109
+ # streamlit < 1.18.0
110
+ from streamlit import experimental_memo as cache_data # type: ignore
111
+
106
112
 
107
113
  __all__ = [
108
114
  "VER_GTE_1_12_0",
@@ -114,4 +120,5 @@ __all__ = [
114
120
  "SessionInfo",
115
121
  "get_script_run_ctx",
116
122
  "rerun",
123
+ "cache_data",
117
124
  ]
@@ -30,11 +30,16 @@ import urllib.error
30
30
  import urllib.request
31
31
  from typing import List, Optional
32
32
 
33
+ from ._compat import cache_data
33
34
  from .config import RTCIceServer
34
35
 
35
36
  LOGGER = logging.getLogger(__name__)
36
37
 
37
38
 
39
+ HF_ICE_SERVER_TTL = 3600 # 1 hour. Not sure if this is the best value.
40
+
41
+
42
+ @cache_data(ttl=HF_ICE_SERVER_TTL)
38
43
  def get_hf_ice_servers(token: Optional[str] = None) -> List[RTCIceServer]:
39
44
  if token is None:
40
45
  token = os.getenv("HF_TOKEN")
@@ -61,6 +66,10 @@ def get_hf_ice_servers(token: Optional[str] = None) -> List[RTCIceServer]:
61
66
  raise ValueError("Failed to get credentials from HF turn server")
62
67
 
63
68
 
69
+ TWILIO_CRED_TTL = 3600 # 1 hour. Twilio's default is 1 day. Shorter TTL should be ok for this library's use case.
70
+
71
+
72
+ @cache_data(ttl=TWILIO_CRED_TTL)
64
73
  def get_twilio_ice_servers(
65
74
  twilio_sid: Optional[str] = None, twilio_token: Optional[str] = None
66
75
  ) -> List[RTCIceServer]:
@@ -78,7 +87,7 @@ def get_twilio_ice_servers(
78
87
 
79
88
  client = Client(twilio_sid, twilio_token)
80
89
 
81
- token = client.tokens.create()
90
+ token = client.tokens.create(ttl=TWILIO_CRED_TTL)
82
91
 
83
92
  return token.ice_servers
84
93