-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
217 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from typing import Optional | ||
from pydantic import BaseModel, Field | ||
|
||
|
||
class SipAuth(BaseModel): | ||
""" | ||
Model representing the authentication details for the SIP INVITE request | ||
for HTTP digest authentication, if it is required by your SIP platform. | ||
Attributes: | ||
username (str): The username for HTTP digest authentication. | ||
password (str): The password for HTTP digest authentication. | ||
""" | ||
|
||
username: str | ||
password: str | ||
|
||
|
||
class SipOptions(BaseModel): | ||
""" | ||
Model representing the SIP options for the call. | ||
Attributes: | ||
uri (str): The SIP URI to be used as the destination of the SIP call. | ||
from_ (Optional[str]): The number or string sent to the final SIP number | ||
as the caller. It must be a string in the form of `from@example.com`, where | ||
`from` can be a string or a number. | ||
headers (Optional[dict]): Custom headers to be added to the SIP INVITE request. | ||
auth (Optional[SipAuth]): Authentication details for the SIP INVITE request. | ||
secure (Optional[bool]): Indicates whether the media must be transmitted encrypted. | ||
Default is false. | ||
video (Optional[bool]): Indicates whether the SIP call will include video. | ||
Default is false. | ||
observe_force_mute (Optional[bool]): Indicates whether the SIP endpoint observes | ||
force mute moderation. | ||
""" | ||
|
||
uri: str | ||
from_: Optional[str] = Field(None, serialization_alias='from') | ||
headers: Optional[dict] = None | ||
auth: Optional[SipAuth] = None | ||
secure: Optional[bool] = None | ||
video: Optional[bool] = None | ||
observe_force_mute: Optional[bool] = Field( | ||
None, serialization_alias='observeForceMute' | ||
) | ||
|
||
|
||
class InitiateSipRequest(BaseModel): | ||
""" | ||
Model representing the SIP options for joining a Vonage Video session. | ||
Attributes: | ||
session_id (str): The Vonage Video session ID for the SIP call to join. | ||
token (str): The Vonage Video token to be used for the participant being called. | ||
sip (Sip): The SIP options for the call. | ||
""" | ||
|
||
session_id: str = Field(..., serialization_alias='sessionId') | ||
token: str | ||
sip: SipOptions | ||
|
||
|
||
class SipCall(BaseModel): | ||
""" | ||
Model representing the details of a SIP call. | ||
Attributes: | ||
id (str): A unique ID for the SIP call. | ||
connection_id (str): The Vonage Video connection ID for the SIP call's connection | ||
in the Vonage Video session. | ||
stream_id (str): The Vonage Video stream ID for the SIP call's stream in the | ||
Vonage Video session. | ||
""" | ||
|
||
id: str | ||
connection_id: str = Field(..., serialization_alias='connectionId') | ||
stream_id: str = Field(..., serialization_alias='streamId') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
from os.path import abspath | ||
|
||
import responses | ||
from vonage_http_client import HttpClient | ||
|
||
from vonage_video.models.sip import SipAuth, SipOptions, InitiateSipRequest | ||
from vonage_video.models.token import TokenOptions | ||
from vonage_video.video import Video | ||
|
||
from testutils import build_response, get_mock_jwt_auth | ||
|
||
path = abspath(__file__) | ||
|
||
|
||
video = Video(HttpClient(get_mock_jwt_auth())) | ||
|
||
|
||
def test_sip_params_model(): | ||
sip_request_params = InitiateSipRequest( | ||
session_id='test_session_id', | ||
token='test_token', | ||
sip=SipOptions( | ||
uri='sip:user@sip.partner.com;transport=tls', | ||
from_='example@example.com', | ||
headers={'header_key': 'header_value'}, | ||
auth=SipAuth(username='username', password='password'), | ||
secure=True, | ||
video=True, | ||
observe_force_mute=True, | ||
), | ||
) | ||
|
||
assert sip_request_params.model_dump(by_alias=True) == { | ||
'sessionId': 'test_session_id', | ||
'token': 'test_token', | ||
'sip': { | ||
'uri': 'sip:user@sip.partner.com;transport=tls', | ||
'from': 'example@example.com', | ||
'headers': {'header_key': 'header_value'}, | ||
'auth': {'username': 'username', 'password': 'password'}, | ||
'secure': True, | ||
'video': True, | ||
'observeForceMute': True, | ||
}, | ||
} | ||
|
||
|
||
@responses.activate | ||
def test_initiate_sip_call(): | ||
build_response( | ||
path, | ||
'POST', | ||
'https://video.api.vonage.com/v2/project/test_application_id/dial', | ||
'sip.json', | ||
200, | ||
) | ||
|
||
sip_request_params = InitiateSipRequest( | ||
session_id='test_session_id', | ||
token='test_token', | ||
sip=SipOptions( | ||
uri='sip:user@sip.partner.com;transport=tls', | ||
from_='example@example.com', | ||
headers={'header_key': 'header_value'}, | ||
auth=SipAuth(username='username', password='password'), | ||
secure=True, | ||
video=True, | ||
observe_force_mute=True, | ||
), | ||
) | ||
|
||
sip_call = video.initiate_sip_call(sip_request_params) | ||
|
||
assert sip_call.id == '' | ||
assert sip_call.connection_id == '' | ||
assert sip_call.stream_id == '' |