Skip to content

Commit

Permalink
RTC-377 Add SIP Component (#30)
Browse files Browse the repository at this point in the history
* Add tests for SIP Component

* Fix lint issues

* Update openapi client

* Fix lint and format issues

* Add missing envs in docker-compose
  • Loading branch information
Rados13 authored Feb 20, 2024
1 parent b11b1fd commit 9ef121b
Show file tree
Hide file tree
Showing 24 changed files with 1,117 additions and 31 deletions.
2 changes: 2 additions & 0 deletions docker-compose-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ services:
JF_SERVER_API_TOKEN: "development"
JF_PORT: 5002
JF_SECRET_KEY_BASE: "super-secret-key"
JF_SIP_USED: "true"
JF_SIP_IP: "127.0.0.1"
ports:
- "5002:5002"
- "49999:49999"
Expand Down
11 changes: 11 additions & 0 deletions jellyfish/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,22 @@
ComponentOptionsHLS,
ComponentOptionsHLSSubscribeMode,
ComponentOptionsRTSP,
ComponentOptionsSIP,
ComponentPropertiesFile,
ComponentPropertiesHLS,
ComponentPropertiesHLSSubscribeMode,
ComponentPropertiesRTSP,
ComponentPropertiesSIP,
ComponentPropertiesSIPSIPCredentials,
ComponentRTSP,
ComponentSIP,
Peer,
PeerOptionsWebRTC,
PeerStatus,
Room,
RoomConfig,
RoomConfigVideoCodec,
SIPCredentials,
)

# API
Expand All @@ -50,6 +55,11 @@
"ComponentOptionsHLSSubscribeMode",
"ComponentPropertiesHLS",
"ComponentPropertiesHLSSubscribeMode",
"ComponentSIP",
"ComponentOptionsSIP",
"ComponentPropertiesSIP",
"ComponentPropertiesSIPSIPCredentials",
"ComponentFile",
"ComponentRTSP",
"ComponentOptionsRTSP",
"ComponentPropertiesRTSP",
Expand All @@ -58,5 +68,6 @@
"ComponentPropertiesFile",
"events",
"errors",
"SIPCredentials",
]
__docformat__ = "restructuredtext"
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from ... import errors
from ...client import AuthenticatedClient, Client
from ...models.error import Error
from ...models.healthcheck_response import HealthcheckResponse
from ...types import Response

Expand All @@ -18,15 +19,15 @@ def _get_kwargs() -> Dict[str, Any]:

def _parse_response(
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
) -> Optional[HealthcheckResponse]:
) -> Optional[Union[Error, HealthcheckResponse]]:
if response.status_code == HTTPStatus.OK:
response_200 = HealthcheckResponse.from_dict(response.json())

return response_200
if response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR:
response_500 = HealthcheckResponse.from_dict(response.json())
if response.status_code == HTTPStatus.UNAUTHORIZED:
response_401 = Error.from_dict(response.json())

return response_500
return response_401
if client.raise_on_unexpected_status:
raise errors.UnexpectedStatus(response.status_code, response.content)
else:
Expand All @@ -35,7 +36,7 @@ def _parse_response(

def _build_response(
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
) -> Response[HealthcheckResponse]:
) -> Response[Union[Error, HealthcheckResponse]]:
return Response(
status_code=HTTPStatus(response.status_code),
content=response.content,
Expand All @@ -47,15 +48,15 @@ def _build_response(
def sync_detailed(
*,
client: Union[AuthenticatedClient, Client],
) -> Response[HealthcheckResponse]:
) -> Response[Union[Error, HealthcheckResponse]]:
"""Describes the health of Jellyfish
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.
Returns:
Response[HealthcheckResponse]
Response[Union[Error, HealthcheckResponse]]
"""

kwargs = _get_kwargs()
Expand All @@ -70,15 +71,15 @@ def sync_detailed(
def sync(
*,
client: Union[AuthenticatedClient, Client],
) -> Optional[HealthcheckResponse]:
) -> Optional[Union[Error, HealthcheckResponse]]:
"""Describes the health of Jellyfish
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.
Returns:
HealthcheckResponse
Union[Error, HealthcheckResponse]
"""

return sync_detailed(
Expand All @@ -89,15 +90,15 @@ def sync(
async def asyncio_detailed(
*,
client: Union[AuthenticatedClient, Client],
) -> Response[HealthcheckResponse]:
) -> Response[Union[Error, HealthcheckResponse]]:
"""Describes the health of Jellyfish
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.
Returns:
Response[HealthcheckResponse]
Response[Union[Error, HealthcheckResponse]]
"""

kwargs = _get_kwargs()
Expand All @@ -110,15 +111,15 @@ async def asyncio_detailed(
async def asyncio(
*,
client: Union[AuthenticatedClient, Client],
) -> Optional[HealthcheckResponse]:
) -> Optional[Union[Error, HealthcheckResponse]]:
"""Describes the health of Jellyfish
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.
Returns:
HealthcheckResponse
Union[Error, HealthcheckResponse]
"""

return (
Expand Down
4 changes: 4 additions & 0 deletions jellyfish/_openapi_client/api/hls/subscribe_hls_to.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def _parse_response(
response_400 = Error.from_dict(response.json())

return response_400
if response.status_code == HTTPStatus.UNAUTHORIZED:
response_401 = Error.from_dict(response.json())

return response_401
if response.status_code == HTTPStatus.NOT_FOUND:
response_404 = Error.from_dict(response.json())

Expand Down
4 changes: 4 additions & 0 deletions jellyfish/_openapi_client/api/recording/delete_recording.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def _parse_response(
response_400 = Error.from_dict(response.json())

return response_400
if response.status_code == HTTPStatus.UNAUTHORIZED:
response_401 = Error.from_dict(response.json())

return response_401
if response.status_code == HTTPStatus.NOT_FOUND:
response_404 = Error.from_dict(response.json())

Expand Down
4 changes: 4 additions & 0 deletions jellyfish/_openapi_client/api/recording/get_recordings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def _parse_response(
response_200 = RecordingListResponse.from_dict(response.json())

return response_200
if response.status_code == HTTPStatus.UNAUTHORIZED:
response_401 = Error.from_dict(response.json())

return response_401
if response.status_code == HTTPStatus.NOT_FOUND:
response_404 = Error.from_dict(response.json())

Expand Down
Empty file.
193 changes: 193 additions & 0 deletions jellyfish/_openapi_client/api/sip/dial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
from http import HTTPStatus
from typing import Any, Dict, Optional, Union, cast

import httpx

from ... import errors
from ...client import AuthenticatedClient, Client
from ...models.dial_config import DialConfig
from ...models.error import Error
from ...types import Response


def _get_kwargs(
room_id: str,
component_id: str,
*,
json_body: DialConfig,
) -> Dict[str, Any]:
json_json_body = json_body.to_dict()

return {
"method": "post",
"url": "/sip/{room_id}/{component_id}/call".format(
room_id=room_id,
component_id=component_id,
),
"json": json_json_body,
}


def _parse_response(
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
) -> Optional[Union[Any, Error]]:
if response.status_code == HTTPStatus.CREATED:
response_201 = cast(Any, None)
return response_201
if response.status_code == HTTPStatus.BAD_REQUEST:
response_400 = Error.from_dict(response.json())

return response_400
if response.status_code == HTTPStatus.UNAUTHORIZED:
response_401 = Error.from_dict(response.json())

return response_401
if response.status_code == HTTPStatus.NOT_FOUND:
response_404 = Error.from_dict(response.json())

return response_404
if client.raise_on_unexpected_status:
raise errors.UnexpectedStatus(response.status_code, response.content)
else:
return None


def _build_response(
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
) -> Response[Union[Any, Error]]:
return Response(
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=_parse_response(client=client, response=response),
)


def sync_detailed(
room_id: str,
component_id: str,
*,
client: Union[AuthenticatedClient, Client],
json_body: DialConfig,
) -> Response[Union[Any, Error]]:
"""Make a call from the SIP component to the provided phone number
Args:
room_id (str):
component_id (str):
json_body (DialConfig): Dial config
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.
Returns:
Response[Union[Any, Error]]
"""

kwargs = _get_kwargs(
room_id=room_id,
component_id=component_id,
json_body=json_body,
)

response = client.get_httpx_client().request(
**kwargs,
)

return _build_response(client=client, response=response)


def sync(
room_id: str,
component_id: str,
*,
client: Union[AuthenticatedClient, Client],
json_body: DialConfig,
) -> Optional[Union[Any, Error]]:
"""Make a call from the SIP component to the provided phone number
Args:
room_id (str):
component_id (str):
json_body (DialConfig): Dial config
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.
Returns:
Union[Any, Error]
"""

return sync_detailed(
room_id=room_id,
component_id=component_id,
client=client,
json_body=json_body,
).parsed


async def asyncio_detailed(
room_id: str,
component_id: str,
*,
client: Union[AuthenticatedClient, Client],
json_body: DialConfig,
) -> Response[Union[Any, Error]]:
"""Make a call from the SIP component to the provided phone number
Args:
room_id (str):
component_id (str):
json_body (DialConfig): Dial config
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.
Returns:
Response[Union[Any, Error]]
"""

kwargs = _get_kwargs(
room_id=room_id,
component_id=component_id,
json_body=json_body,
)

response = await client.get_async_httpx_client().request(**kwargs)

return _build_response(client=client, response=response)


async def asyncio(
room_id: str,
component_id: str,
*,
client: Union[AuthenticatedClient, Client],
json_body: DialConfig,
) -> Optional[Union[Any, Error]]:
"""Make a call from the SIP component to the provided phone number
Args:
room_id (str):
component_id (str):
json_body (DialConfig): Dial config
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.
Returns:
Union[Any, Error]
"""

return (
await asyncio_detailed(
room_id=room_id,
component_id=component_id,
client=client,
json_body=json_body,
)
).parsed
Loading

0 comments on commit 9ef121b

Please sign in to comment.