-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy path__init__.py
More file actions
91 lines (78 loc) · 2.77 KB
/
__init__.py
File metadata and controls
91 lines (78 loc) · 2.77 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
import logging
from typing import Optional
from getstream.video.async_call import Call
from getstream.video.rtc.location_discovery import (
HTTPHintLocationDiscovery,
HEADER_CLOUDFRONT_POP,
FALLBACK_LOCATION_NAME,
STREAM_PROD_URL,
)
from getstream.video.rtc.models import (
JoinCallRequest,
JoinCallResponse,
ServerCredentials,
Credentials,
)
from getstream.video.rtc.connection_utils import join_call_coordinator_request
from getstream.video.rtc.connection_manager import ConnectionManager
from getstream.video.rtc.audio_track import AudioStreamTrack
from getstream.video.rtc.track_util import PcmData, Resampler, AudioFormat
logger = logging.getLogger(__name__)
try:
import aiortc
except ImportError:
# before throwing, suggest the user to install the `webrtc` optional dependency
raise ImportError(
"The `webrtc` optional dependency is required to use the `getstream.video.rtc` module. "
"Please install it using the following command: `pip install getstream[webrtc]`"
)
logger.debug(f"loaded aiortc {aiortc.__version__} correctly")
async def discover_location():
"""
Discover the closest location based on CloudFront pop headers.
Returns:
str: The 3-character location code (e.g. "IAD")
"""
logger.info("Discovering location")
discovery = HTTPHintLocationDiscovery(logger=logger)
# Even though discover is synchronous, we keep this function async for future compatibility
return discovery.discover()
async def join(
call: Call, user_id: Optional[str] = None, create=True, fast_join=False, **kwargs
) -> ConnectionManager:
"""
Join a call. This method will:
- discover the best location
- join the call (or create it if needed)
- setup the peer connection
- connect to the SFU
Args:
call: The call to join
user_id: The user id to join with
create: Whether to create the call if it doesn't exist
fast_join: Whether to use fast join (default: False)
**kwargs: Additional arguments to pass to the join call request
Returns:
A ConnectionManager object that can be used as a context manager
"""
# Return ConnectionManager instance that handles everything internally
# when used as an async context manager and async iterator
return ConnectionManager(call=call, user_id=user_id, create=create, fast_join=fast_join, **kwargs)
__all__ = [
"HTTPHintLocationDiscovery",
"HEADER_CLOUDFRONT_POP",
"FALLBACK_LOCATION_NAME",
"STREAM_PROD_URL",
"join",
"ConnectionManager",
"JoinCallRequest",
"JoinCallResponse",
"ServerCredentials",
"Credentials",
"join_call_coordinator_request",
"discover_location",
"PcmData",
"Resampler",
"AudioFormat",
"AudioStreamTrack",
]