Skip to content

Commit 9ef121b

Browse files
authored
RTC-377 Add SIP Component (#30)
* Add tests for SIP Component * Fix lint issues * Update openapi client * Fix lint and format issues * Add missing envs in docker-compose
1 parent b11b1fd commit 9ef121b

24 files changed

+1117
-31
lines changed

docker-compose-test.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ services:
2121
JF_SERVER_API_TOKEN: "development"
2222
JF_PORT: 5002
2323
JF_SECRET_KEY_BASE: "super-secret-key"
24+
JF_SIP_USED: "true"
25+
JF_SIP_IP: "127.0.0.1"
2426
ports:
2527
- "5002:5002"
2628
- "49999:49999"

jellyfish/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,22 @@
1515
ComponentOptionsHLS,
1616
ComponentOptionsHLSSubscribeMode,
1717
ComponentOptionsRTSP,
18+
ComponentOptionsSIP,
1819
ComponentPropertiesFile,
1920
ComponentPropertiesHLS,
2021
ComponentPropertiesHLSSubscribeMode,
2122
ComponentPropertiesRTSP,
23+
ComponentPropertiesSIP,
24+
ComponentPropertiesSIPSIPCredentials,
2225
ComponentRTSP,
26+
ComponentSIP,
2327
Peer,
2428
PeerOptionsWebRTC,
2529
PeerStatus,
2630
Room,
2731
RoomConfig,
2832
RoomConfigVideoCodec,
33+
SIPCredentials,
2934
)
3035

3136
# API
@@ -50,6 +55,11 @@
5055
"ComponentOptionsHLSSubscribeMode",
5156
"ComponentPropertiesHLS",
5257
"ComponentPropertiesHLSSubscribeMode",
58+
"ComponentSIP",
59+
"ComponentOptionsSIP",
60+
"ComponentPropertiesSIP",
61+
"ComponentPropertiesSIPSIPCredentials",
62+
"ComponentFile",
5363
"ComponentRTSP",
5464
"ComponentOptionsRTSP",
5565
"ComponentPropertiesRTSP",
@@ -58,5 +68,6 @@
5868
"ComponentPropertiesFile",
5969
"events",
6070
"errors",
71+
"SIPCredentials",
6172
]
6273
__docformat__ = "restructuredtext"
File renamed without changes.

jellyfish/_openapi_client/api/default/healthcheck.py renamed to jellyfish/_openapi_client/api/health/healthcheck.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from ... import errors
77
from ...client import AuthenticatedClient, Client
8+
from ...models.error import Error
89
from ...models.healthcheck_response import HealthcheckResponse
910
from ...types import Response
1011

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

1920
def _parse_response(
2021
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
21-
) -> Optional[HealthcheckResponse]:
22+
) -> Optional[Union[Error, HealthcheckResponse]]:
2223
if response.status_code == HTTPStatus.OK:
2324
response_200 = HealthcheckResponse.from_dict(response.json())
2425

2526
return response_200
26-
if response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR:
27-
response_500 = HealthcheckResponse.from_dict(response.json())
27+
if response.status_code == HTTPStatus.UNAUTHORIZED:
28+
response_401 = Error.from_dict(response.json())
2829

29-
return response_500
30+
return response_401
3031
if client.raise_on_unexpected_status:
3132
raise errors.UnexpectedStatus(response.status_code, response.content)
3233
else:
@@ -35,7 +36,7 @@ def _parse_response(
3536

3637
def _build_response(
3738
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
38-
) -> Response[HealthcheckResponse]:
39+
) -> Response[Union[Error, HealthcheckResponse]]:
3940
return Response(
4041
status_code=HTTPStatus(response.status_code),
4142
content=response.content,
@@ -47,15 +48,15 @@ def _build_response(
4748
def sync_detailed(
4849
*,
4950
client: Union[AuthenticatedClient, Client],
50-
) -> Response[HealthcheckResponse]:
51+
) -> Response[Union[Error, HealthcheckResponse]]:
5152
"""Describes the health of Jellyfish
5253
5354
Raises:
5455
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
5556
httpx.TimeoutException: If the request takes longer than Client.timeout.
5657
5758
Returns:
58-
Response[HealthcheckResponse]
59+
Response[Union[Error, HealthcheckResponse]]
5960
"""
6061

6162
kwargs = _get_kwargs()
@@ -70,15 +71,15 @@ def sync_detailed(
7071
def sync(
7172
*,
7273
client: Union[AuthenticatedClient, Client],
73-
) -> Optional[HealthcheckResponse]:
74+
) -> Optional[Union[Error, HealthcheckResponse]]:
7475
"""Describes the health of Jellyfish
7576
7677
Raises:
7778
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
7879
httpx.TimeoutException: If the request takes longer than Client.timeout.
7980
8081
Returns:
81-
HealthcheckResponse
82+
Union[Error, HealthcheckResponse]
8283
"""
8384

8485
return sync_detailed(
@@ -89,15 +90,15 @@ def sync(
8990
async def asyncio_detailed(
9091
*,
9192
client: Union[AuthenticatedClient, Client],
92-
) -> Response[HealthcheckResponse]:
93+
) -> Response[Union[Error, HealthcheckResponse]]:
9394
"""Describes the health of Jellyfish
9495
9596
Raises:
9697
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
9798
httpx.TimeoutException: If the request takes longer than Client.timeout.
9899
99100
Returns:
100-
Response[HealthcheckResponse]
101+
Response[Union[Error, HealthcheckResponse]]
101102
"""
102103

103104
kwargs = _get_kwargs()
@@ -110,15 +111,15 @@ async def asyncio_detailed(
110111
async def asyncio(
111112
*,
112113
client: Union[AuthenticatedClient, Client],
113-
) -> Optional[HealthcheckResponse]:
114+
) -> Optional[Union[Error, HealthcheckResponse]]:
114115
"""Describes the health of Jellyfish
115116
116117
Raises:
117118
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
118119
httpx.TimeoutException: If the request takes longer than Client.timeout.
119120
120121
Returns:
121-
HealthcheckResponse
122+
Union[Error, HealthcheckResponse]
122123
"""
123124

124125
return (

jellyfish/_openapi_client/api/hls/subscribe_hls_to.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ def _parse_response(
3636
response_400 = Error.from_dict(response.json())
3737

3838
return response_400
39+
if response.status_code == HTTPStatus.UNAUTHORIZED:
40+
response_401 = Error.from_dict(response.json())
41+
42+
return response_401
3943
if response.status_code == HTTPStatus.NOT_FOUND:
4044
response_404 = Error.from_dict(response.json())
4145

jellyfish/_openapi_client/api/recording/delete_recording.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ def _parse_response(
3030
response_400 = Error.from_dict(response.json())
3131

3232
return response_400
33+
if response.status_code == HTTPStatus.UNAUTHORIZED:
34+
response_401 = Error.from_dict(response.json())
35+
36+
return response_401
3337
if response.status_code == HTTPStatus.NOT_FOUND:
3438
response_404 = Error.from_dict(response.json())
3539

jellyfish/_openapi_client/api/recording/get_recordings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ def _parse_response(
2424
response_200 = RecordingListResponse.from_dict(response.json())
2525

2626
return response_200
27+
if response.status_code == HTTPStatus.UNAUTHORIZED:
28+
response_401 = Error.from_dict(response.json())
29+
30+
return response_401
2731
if response.status_code == HTTPStatus.NOT_FOUND:
2832
response_404 = Error.from_dict(response.json())
2933

jellyfish/_openapi_client/api/sip/__init__.py

Whitespace-only changes.
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
from http import HTTPStatus
2+
from typing import Any, Dict, Optional, Union, cast
3+
4+
import httpx
5+
6+
from ... import errors
7+
from ...client import AuthenticatedClient, Client
8+
from ...models.dial_config import DialConfig
9+
from ...models.error import Error
10+
from ...types import Response
11+
12+
13+
def _get_kwargs(
14+
room_id: str,
15+
component_id: str,
16+
*,
17+
json_body: DialConfig,
18+
) -> Dict[str, Any]:
19+
json_json_body = json_body.to_dict()
20+
21+
return {
22+
"method": "post",
23+
"url": "/sip/{room_id}/{component_id}/call".format(
24+
room_id=room_id,
25+
component_id=component_id,
26+
),
27+
"json": json_json_body,
28+
}
29+
30+
31+
def _parse_response(
32+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
33+
) -> Optional[Union[Any, Error]]:
34+
if response.status_code == HTTPStatus.CREATED:
35+
response_201 = cast(Any, None)
36+
return response_201
37+
if response.status_code == HTTPStatus.BAD_REQUEST:
38+
response_400 = Error.from_dict(response.json())
39+
40+
return response_400
41+
if response.status_code == HTTPStatus.UNAUTHORIZED:
42+
response_401 = Error.from_dict(response.json())
43+
44+
return response_401
45+
if response.status_code == HTTPStatus.NOT_FOUND:
46+
response_404 = Error.from_dict(response.json())
47+
48+
return response_404
49+
if client.raise_on_unexpected_status:
50+
raise errors.UnexpectedStatus(response.status_code, response.content)
51+
else:
52+
return None
53+
54+
55+
def _build_response(
56+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
57+
) -> Response[Union[Any, Error]]:
58+
return Response(
59+
status_code=HTTPStatus(response.status_code),
60+
content=response.content,
61+
headers=response.headers,
62+
parsed=_parse_response(client=client, response=response),
63+
)
64+
65+
66+
def sync_detailed(
67+
room_id: str,
68+
component_id: str,
69+
*,
70+
client: Union[AuthenticatedClient, Client],
71+
json_body: DialConfig,
72+
) -> Response[Union[Any, Error]]:
73+
"""Make a call from the SIP component to the provided phone number
74+
75+
Args:
76+
room_id (str):
77+
component_id (str):
78+
json_body (DialConfig): Dial config
79+
80+
Raises:
81+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
82+
httpx.TimeoutException: If the request takes longer than Client.timeout.
83+
84+
Returns:
85+
Response[Union[Any, Error]]
86+
"""
87+
88+
kwargs = _get_kwargs(
89+
room_id=room_id,
90+
component_id=component_id,
91+
json_body=json_body,
92+
)
93+
94+
response = client.get_httpx_client().request(
95+
**kwargs,
96+
)
97+
98+
return _build_response(client=client, response=response)
99+
100+
101+
def sync(
102+
room_id: str,
103+
component_id: str,
104+
*,
105+
client: Union[AuthenticatedClient, Client],
106+
json_body: DialConfig,
107+
) -> Optional[Union[Any, Error]]:
108+
"""Make a call from the SIP component to the provided phone number
109+
110+
Args:
111+
room_id (str):
112+
component_id (str):
113+
json_body (DialConfig): Dial config
114+
115+
Raises:
116+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
117+
httpx.TimeoutException: If the request takes longer than Client.timeout.
118+
119+
Returns:
120+
Union[Any, Error]
121+
"""
122+
123+
return sync_detailed(
124+
room_id=room_id,
125+
component_id=component_id,
126+
client=client,
127+
json_body=json_body,
128+
).parsed
129+
130+
131+
async def asyncio_detailed(
132+
room_id: str,
133+
component_id: str,
134+
*,
135+
client: Union[AuthenticatedClient, Client],
136+
json_body: DialConfig,
137+
) -> Response[Union[Any, Error]]:
138+
"""Make a call from the SIP component to the provided phone number
139+
140+
Args:
141+
room_id (str):
142+
component_id (str):
143+
json_body (DialConfig): Dial config
144+
145+
Raises:
146+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
147+
httpx.TimeoutException: If the request takes longer than Client.timeout.
148+
149+
Returns:
150+
Response[Union[Any, Error]]
151+
"""
152+
153+
kwargs = _get_kwargs(
154+
room_id=room_id,
155+
component_id=component_id,
156+
json_body=json_body,
157+
)
158+
159+
response = await client.get_async_httpx_client().request(**kwargs)
160+
161+
return _build_response(client=client, response=response)
162+
163+
164+
async def asyncio(
165+
room_id: str,
166+
component_id: str,
167+
*,
168+
client: Union[AuthenticatedClient, Client],
169+
json_body: DialConfig,
170+
) -> Optional[Union[Any, Error]]:
171+
"""Make a call from the SIP component to the provided phone number
172+
173+
Args:
174+
room_id (str):
175+
component_id (str):
176+
json_body (DialConfig): Dial config
177+
178+
Raises:
179+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
180+
httpx.TimeoutException: If the request takes longer than Client.timeout.
181+
182+
Returns:
183+
Union[Any, Error]
184+
"""
185+
186+
return (
187+
await asyncio_detailed(
188+
room_id=room_id,
189+
component_id=component_id,
190+
client=client,
191+
json_body=json_body,
192+
)
193+
).parsed

0 commit comments

Comments
 (0)