streamlit-webrtc 0.52.0__py3-none-any.whl → 0.53.1__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.
@@ -1,3 +1,4 @@
1
+ import copy
1
2
  import json
2
3
  import logging
3
4
  import os
@@ -17,7 +18,7 @@ from typing import (
17
18
 
18
19
  import streamlit as st
19
20
  import streamlit.components.v1 as components
20
- from aiortc import RTCConfiguration
21
+ from aiortc import RTCConfiguration as AiortcRTCConfiguration
21
22
  from aiortc.mediastreams import MediaStreamTrack
22
23
 
23
24
  from streamlit_webrtc.models import (
@@ -36,6 +37,7 @@ from .config import (
36
37
  DEFAULT_VIDEO_HTML_ATTRS,
37
38
  AudioHTMLAttributes,
38
39
  MediaStreamConstraints,
40
+ RTCConfiguration,
39
41
  Translations,
40
42
  VideoHTMLAttributes,
41
43
  compile_ice_servers,
@@ -90,6 +92,7 @@ class WebRtcStreamerContext(Generic[VideoProcessorT, AudioProcessorT]):
90
92
  _worker_ref: "Optional[weakref.ReferenceType[WebRtcWorker[VideoProcessorT, AudioProcessorT]]]" # noqa
91
93
 
92
94
  _component_value_snapshot: Union[ComponentValueSnapshot, None]
95
+ _frontend_rtc_configuration: Optional[Union[Dict[str, Any], RTCConfiguration]]
93
96
 
94
97
  def __init__(
95
98
  self,
@@ -99,6 +102,7 @@ class WebRtcStreamerContext(Generic[VideoProcessorT, AudioProcessorT]):
99
102
  self._set_worker(worker)
100
103
  self._set_state(state)
101
104
  self._component_value_snapshot = None
105
+ self._frontend_rtc_configuration = None
102
106
 
103
107
  def _set_worker(
104
108
  self, worker: Optional[WebRtcWorker[VideoProcessorT, AudioProcessorT]]
@@ -215,7 +219,10 @@ def compile_state(component_value) -> WebRtcStreamerState:
215
219
  def webrtc_streamer(
216
220
  key: str,
217
221
  mode: WebRtcMode = WebRtcMode.SENDRECV,
218
- rtc_configuration: Optional[Union[Dict[str, Any], RTCConfiguration]] = None,
222
+ server_rtc_configuration: Optional[Union[Dict[str, Any], RTCConfiguration]] = None,
223
+ frontend_rtc_configuration: Optional[
224
+ Union[Dict[str, Any], RTCConfiguration]
225
+ ] = None,
219
226
  media_stream_constraints: Optional[Union[Dict, MediaStreamConstraints]] = None,
220
227
  desired_playing_state: Optional[bool] = None,
221
228
  player_factory: Optional[MediaPlayerFactory] = None,
@@ -243,6 +250,7 @@ def webrtc_streamer(
243
250
  # Deprecated. Just for backward compatibility
244
251
  video_transformer_factory: None = None,
245
252
  async_transform: Optional[bool] = None,
253
+ rtc_configuration: Optional[Union[Dict[str, Any], RTCConfiguration]] = None,
246
254
  ) -> WebRtcStreamerContext:
247
255
  # XXX: We wanted something like `WebRtcStreamerContext[None, None]`
248
256
  # as the return value, but could not find a good solution
@@ -255,7 +263,10 @@ def webrtc_streamer(
255
263
  def webrtc_streamer(
256
264
  key: str,
257
265
  mode: WebRtcMode = WebRtcMode.SENDRECV,
258
- rtc_configuration: Optional[Union[Dict[str, Any], RTCConfiguration]] = None,
266
+ server_rtc_configuration: Optional[Union[Dict[str, Any], RTCConfiguration]] = None,
267
+ frontend_rtc_configuration: Optional[
268
+ Union[Dict[str, Any], RTCConfiguration]
269
+ ] = None,
259
270
  media_stream_constraints: Optional[Union[Dict, MediaStreamConstraints]] = None,
260
271
  desired_playing_state: Optional[bool] = None,
261
272
  player_factory: Optional[MediaPlayerFactory] = None,
@@ -283,6 +294,7 @@ def webrtc_streamer(
283
294
  # Deprecated. Just for backward compatibility
284
295
  video_transformer_factory: None = None,
285
296
  async_transform: Optional[bool] = None,
297
+ rtc_configuration: Optional[Union[Dict[str, Any], RTCConfiguration]] = None,
286
298
  ) -> WebRtcStreamerContext[VideoProcessorT, Any]:
287
299
  pass
288
300
 
@@ -291,7 +303,10 @@ def webrtc_streamer(
291
303
  def webrtc_streamer(
292
304
  key: str,
293
305
  mode: WebRtcMode = WebRtcMode.SENDRECV,
294
- rtc_configuration: Optional[Union[Dict[str, Any], RTCConfiguration]] = None,
306
+ server_rtc_configuration: Optional[Union[Dict[str, Any], RTCConfiguration]] = None,
307
+ frontend_rtc_configuration: Optional[
308
+ Union[Dict[str, Any], RTCConfiguration]
309
+ ] = None,
295
310
  media_stream_constraints: Optional[Union[Dict, MediaStreamConstraints]] = None,
296
311
  desired_playing_state: Optional[bool] = None,
297
312
  player_factory: Optional[MediaPlayerFactory] = None,
@@ -319,6 +334,7 @@ def webrtc_streamer(
319
334
  # Deprecated. Just for backward compatibility
320
335
  video_transformer_factory: None = None,
321
336
  async_transform: Optional[bool] = None,
337
+ rtc_configuration: Optional[Union[Dict[str, Any], RTCConfiguration]] = None,
322
338
  ) -> WebRtcStreamerContext[Any, AudioProcessorT]:
323
339
  pass
324
340
 
@@ -327,7 +343,10 @@ def webrtc_streamer(
327
343
  def webrtc_streamer(
328
344
  key: str,
329
345
  mode: WebRtcMode = WebRtcMode.SENDRECV,
330
- rtc_configuration: Optional[Union[Dict[str, Any], RTCConfiguration]] = None,
346
+ server_rtc_configuration: Optional[Union[Dict[str, Any], RTCConfiguration]] = None,
347
+ frontend_rtc_configuration: Optional[
348
+ Union[Dict[str, Any], RTCConfiguration]
349
+ ] = None,
331
350
  media_stream_constraints: Optional[Union[Dict, MediaStreamConstraints]] = None,
332
351
  desired_playing_state: Optional[bool] = None,
333
352
  player_factory: Optional[MediaPlayerFactory] = None,
@@ -355,6 +374,7 @@ def webrtc_streamer(
355
374
  # Deprecated. Just for backward compatibility
356
375
  video_transformer_factory: None = None,
357
376
  async_transform: Optional[bool] = None,
377
+ rtc_configuration: Optional[Union[Dict[str, Any], RTCConfiguration]] = None,
358
378
  ) -> WebRtcStreamerContext[VideoProcessorT, AudioProcessorT]:
359
379
  pass
360
380
 
@@ -362,7 +382,10 @@ def webrtc_streamer(
362
382
  def webrtc_streamer(
363
383
  key: str,
364
384
  mode: WebRtcMode = WebRtcMode.SENDRECV,
365
- rtc_configuration: Optional[Union[Dict[str, Any], RTCConfiguration]] = None,
385
+ server_rtc_configuration: Optional[Union[Dict[str, Any], RTCConfiguration]] = None,
386
+ frontend_rtc_configuration: Optional[
387
+ Union[Dict[str, Any], RTCConfiguration]
388
+ ] = None,
366
389
  media_stream_constraints: Optional[Union[Dict, MediaStreamConstraints]] = None,
367
390
  desired_playing_state: Optional[bool] = None,
368
391
  player_factory: Optional[MediaPlayerFactory] = None,
@@ -390,13 +413,14 @@ def webrtc_streamer(
390
413
  # Deprecated. Just for backward compatibility
391
414
  video_transformer_factory=None,
392
415
  async_transform: Optional[bool] = None,
416
+ rtc_configuration: Optional[Union[Dict[str, Any], RTCConfiguration]] = None,
393
417
  ) -> WebRtcStreamerContext[VideoProcessorT, AudioProcessorT]:
394
418
  # Backward compatibility
395
419
  if video_transformer_factory is not None:
396
420
  warnings.warn(
397
421
  "The argument video_transformer_factory is deprecated. "
398
422
  "Use video_processor_factory instead.\n"
399
- "See https://github.com/whitphx/streamlit-webrtc#for-users-since-versions-020", # noqa: E501
423
+ "See https://github.com/whitphx/streamlit-webrtc#for-users-since-versions-020",
400
424
  DeprecationWarning,
401
425
  stacklevel=2,
402
426
  )
@@ -405,11 +429,19 @@ def webrtc_streamer(
405
429
  warnings.warn(
406
430
  "The argument async_transform is deprecated. "
407
431
  "Use async_processing instead.\n"
408
- "See https://github.com/whitphx/streamlit-webrtc#for-users-since-versions-020", # noqa: E501
432
+ "See https://github.com/whitphx/streamlit-webrtc#for-users-since-versions-020",
409
433
  DeprecationWarning,
410
434
  stacklevel=2,
411
435
  )
412
436
  async_processing = async_transform
437
+ if rtc_configuration is not None:
438
+ warnings.warn(
439
+ "The argument rtc_configuration is deprecated. "
440
+ "Use frontend_rtc_configuration and server_rtc_configuration instead.\n",
441
+ DeprecationWarning,
442
+ stacklevel=2,
443
+ )
444
+ frontend_rtc_configuration = rtc_configuration
413
445
 
414
446
  if media_stream_constraints is None:
415
447
  media_stream_constraints = DEFAULT_MEDIA_STREAM_CONSTRAINTS
@@ -437,6 +469,18 @@ def webrtc_streamer(
437
469
  )
438
470
  st.session_state[key] = context
439
471
 
472
+ if context._frontend_rtc_configuration is None:
473
+ context._frontend_rtc_configuration = copy.deepcopy(frontend_rtc_configuration)
474
+ if context._frontend_rtc_configuration is None:
475
+ context._frontend_rtc_configuration = {}
476
+ if context._frontend_rtc_configuration.get("iceServers") is None:
477
+ LOGGER.info(
478
+ "No iceServers found in the rtc_configuration for the frontend. Set the default value to use Google STUN server."
479
+ )
480
+ context._frontend_rtc_configuration["iceServers"] = [
481
+ {"urls": "stun:stun.l.google.com:19302"}
482
+ ]
483
+
440
484
  webrtc_worker = context._get_worker()
441
485
 
442
486
  sdp_answer_json = None
@@ -473,6 +517,7 @@ def webrtc_streamer(
473
517
  key=frontend_key,
474
518
  sdp_answer_json=sdp_answer_json,
475
519
  mode=mode.name,
520
+ rtc_configuration=context._frontend_rtc_configuration,
476
521
  media_stream_constraints=media_stream_constraints,
477
522
  video_html_attrs=video_html_attrs,
478
523
  audio_html_attrs=audio_html_attrs,
@@ -554,9 +599,9 @@ def webrtc_streamer(
554
599
  )
555
600
 
556
601
  aiortc_rtc_configuration = (
557
- compile_rtc_configuration(rtc_configuration)
558
- if rtc_configuration and isinstance(rtc_configuration, dict)
559
- else RTCConfiguration()
602
+ compile_rtc_configuration(server_rtc_configuration)
603
+ if server_rtc_configuration and isinstance(server_rtc_configuration, dict)
604
+ else AiortcRTCConfiguration()
560
605
  )
561
606
 
562
607
  if aiortc_rtc_configuration.iceServers is None: