Skip to content

Commit c5a93da

Browse files
committedSep 23, 2024
start adding video api
1 parent 8b3bb19 commit c5a93da

File tree

15 files changed

+714
-652
lines changed

15 files changed

+714
-652
lines changed
 

‎http_client/src/vonage_http_client/auth.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def __init__(
4545

4646
self._api_key = api_key
4747
self._api_secret = api_secret
48+
self._application_id = application_id
4849

4950
if application_id is not None and private_key is not None:
5051
self._jwt_client = JwtClient(application_id, private_key)
@@ -60,10 +61,14 @@ def api_key(self):
6061
def api_secret(self):
6162
return self._api_secret
6263

64+
@property
65+
def application_id(self):
66+
return self._application_id
67+
6368
def create_jwt_auth_string(self):
6469
return b'Bearer ' + self.generate_application_jwt()
6570

66-
def generate_application_jwt(self, claims: dict = None):
71+
def generate_application_jwt(self, claims: dict = {}) -> bytes:
6772
try:
6873
return self._jwt_client.generate_application_jwt(claims)
6974
except AttributeError as err:

‎http_client/src/vonage_http_client/http_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class HttpClient:
4343
The http_client_options dict can have any of the following fields:
4444
api_host (str, optional): The API host to use for HTTP requests. Defaults to 'api.nexmo.com'.
4545
rest_host (str, optional): The REST host to use for HTTP requests. Defaults to 'rest.nexmo.com'.
46+
video_host (str, optional): The Video host to use for HTTP requests. Defaults to 'video.api.vonage.com'.
4647
timeout (int, optional): The timeout for HTTP requests in seconds. Defaults to None.
4748
pool_connections (int, optional): The number of pool connections. Must be > 0. Default is 10.
4849
pool_maxsize (int, optional): The maximum size of the connection pool. Must be > 0. Default is 10.
@@ -70,6 +71,7 @@ def __init__(
7071

7172
self._api_host = self._http_client_options.api_host
7273
self._rest_host = self._http_client_options.rest_host
74+
self._video_host = self._http_client_options.video_host
7375

7476
self._timeout = self._http_client_options.timeout
7577
self._session = Session()
@@ -102,6 +104,10 @@ def api_host(self):
102104
def rest_host(self):
103105
return self._rest_host
104106

107+
@property
108+
def video_host(self):
109+
return self._video_host
110+
105111
@property
106112
def user_agent(self):
107113
return self._user_agent

‎jwt/src/vonage_jwt/jwt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __init__(self, application_id: str, private_key: str):
2424
'Both of "application_id" and "private_key" are required.'
2525
)
2626

27-
def generate_application_jwt(self, jwt_options: dict = {}):
27+
def generate_application_jwt(self, jwt_options: dict = {}) -> bytes:
2828
"""Generates a JWT for the specified Vonage application.
2929
3030
You can override values for application_id and private_key on the JWTClient object by
@@ -44,7 +44,7 @@ def generate_application_jwt(self, jwt_options: dict = {}):
4444
token = encode(payload, self._private_key, algorithm='RS256', headers=headers)
4545
return bytes(token, 'utf-8')
4646

47-
def _set_private_key(self, key: Union[str, bytes]):
47+
def _set_private_key(self, key: Union[str, bytes]) -> None:
4848
if isinstance(key, (str, bytes)) and re.search("[.][a-zA-Z0-9_]+$", key):
4949
with open(key, "rb") as key_file:
5050
self._private_key = key_file.read()
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
from .enums import ArchiveMode, MediaMode, TokenRole
2+
from .session import SessionOptions, VideoSession
23
from .token import TokenOptions
34

4-
__all__ = ['MediaMode', 'ArchiveMode', 'TokenRole', 'TokenOptions']
5+
__all__ = [
6+
'MediaMode',
7+
'ArchiveMode',
8+
'TokenRole',
9+
'TokenOptions',
10+
'SessionOptions',
11+
'VideoSession',
12+
]

‎video/src/vonage_video/models/enums.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@ class ArchiveMode(str, Enum):
1616
class MediaMode(str, Enum):
1717
ROUTED = 'routed'
1818
RELAYED = 'relayed'
19+
20+
21+
class P2pPreference(str, Enum):
22+
DISABLED = 'disabled'
23+
ALWAYS = 'always'

‎video/src/vonage_video/models/requests.py

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from typing import Optional
2+
3+
from pydantic import BaseModel, Field, model_validator
4+
5+
from .enums import ArchiveMode, MediaMode, P2pPreference
6+
7+
8+
class SessionOptions(BaseModel):
9+
"""Options for creating a new session.
10+
11+
Args:
12+
media_mode (MediaMode): The media mode for the session.
13+
archive_mode (ArchiveMode): The archive mode for the session.
14+
location (str): The location of the session.
15+
e2ee (bool): Whether end-to-end encryption is enabled.
16+
p2p_preference (str): The preference for peer-to-peer connections.
17+
This is set automatically by selecting the `media_mode`.
18+
"""
19+
20+
archive_mode: Optional[ArchiveMode] = Field(None, serialization_alias='archiveMode')
21+
location: Optional[str] = None
22+
media_mode: Optional[MediaMode] = None
23+
e2ee: Optional[bool] = None
24+
p2p_preference: Optional[str] = Field(
25+
P2pPreference.DISABLED, serialization_alias='p2p.preference'
26+
)
27+
28+
@model_validator(mode='after')
29+
def set_p2p_preference(self):
30+
if self.media_mode == MediaMode.ROUTED:
31+
self.p2p_preference = P2pPreference.DISABLED
32+
if self.media_mode == MediaMode.RELAYED:
33+
self.p2p_preference = P2pPreference.ALWAYS
34+
return self
35+
36+
@model_validator(mode='after')
37+
def set_p2p_preference_if_archive_mode_set(self):
38+
if self.archive_mode == ArchiveMode.ALWAYS:
39+
self.p2p_preference = P2pPreference.DISABLED
40+
return self
41+
42+
43+
class VideoSession(BaseModel):
44+
session_id: str
45+
archive_mode: Optional[ArchiveMode] = None
46+
media_mode: Optional[MediaMode] = None
47+
location: Optional[str] = None
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from typing import List, Optional
2+
3+
from pydantic import BaseModel, Field
4+
5+
6+
class StreamInfo(BaseModel):
7+
id: Optional[str] = Field(None, validation_alias='id')
8+
video_type: Optional[str] = Field(None, validation_alias='videoType')
9+
name: Optional[str] = Field(None, validation_alias='name')
10+
layout_class_list: Optional[List[str]] = Field(
11+
None, validation_alias='layoutClassList'
12+
)
13+
14+
15+
class StreamLayout(BaseModel):
16+
id: str
17+
layout_class_list: List[str] = Field(..., validation_alias='layoutClassList')
18+
19+
20+
class StreamLayoutOptions(BaseModel):
21+
items: List[StreamLayout]

‎video/src/vonage_video/models/token.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from time import time
2-
from typing import List, Literal, Optional, Union
3-
from uuid import UUID, uuid4
2+
from typing import List, Literal, Optional
3+
from uuid import uuid4
44

55
from pydantic import BaseModel, field_validator, model_validator
66

@@ -29,7 +29,7 @@ class TokenOptions(BaseModel):
2929
connection_data: Optional[str] = None
3030
initial_layout_class_list: Optional[List[str]] = None
3131
exp: Optional[int] = None
32-
jti: Union[UUID, str] = uuid4()
32+
jti: str = str(uuid4())
3333
iat: int = int(time())
3434
subject: Literal['video'] = 'video'
3535
scope: Literal['session.connect'] = 'session.connect'

0 commit comments

Comments
 (0)
Failed to load comments.