Skip to content

Commit

Permalink
RTC-510 Update subscribe method in room_api (#34)
Browse files Browse the repository at this point in the history
* Update subscribe method in room_api

* Update jellyfish/api/_room_api.py

Co-authored-by: Karol Konkol <56369082+Karolk99@users.noreply.github.com>

* Update client

* Update example

---------

Co-authored-by: Karol Konkol <56369082+Karolk99@users.noreply.github.com>
  • Loading branch information
Rados13 and Karolk99 authored Apr 10, 2024
1 parent 98df769 commit 1169e90
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 30 deletions.
4 changes: 2 additions & 2 deletions examples/mini_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async def test_notifier():
room_api = RoomApi(server_address=address)

# Add HLS component with manual subscribe mode
_hls_component = room_api.add_component(
hls_component = room_api.add_component(
room.id,
ComponentOptionsHLS(subscribe_mode=ComponentOptionsHLSSubscribeMode.MANUAL),
)
Expand All @@ -70,7 +70,7 @@ async def test_notifier():
file_component = room_api.add_component(room.id, ComponentOptionsFile("video.h264"))

# Subscribe on specific component
room_api.hls_subscribe(room.id, [file_component.id])
room_api.subscribe(room.id, hls_component.id, [file_component.id])

try:
await notifier_task
Expand Down
4 changes: 4 additions & 0 deletions jellyfish/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
ComponentOptionsHLS,
ComponentOptionsHLSSubscribeMode,
ComponentOptionsRecording,
ComponentOptionsRecordingSubscribeMode,
ComponentOptionsRTSP,
ComponentOptionsSIP,
ComponentPropertiesFile,
ComponentPropertiesHLS,
ComponentPropertiesHLSSubscribeMode,
ComponentPropertiesRecording,
ComponentPropertiesRecordingSubscribeMode,
ComponentPropertiesRTSP,
ComponentPropertiesSIP,
ComponentPropertiesSIPSIPCredentials,
Expand Down Expand Up @@ -75,7 +77,9 @@
"SIPCredentials",
"ComponentRecording",
"ComponentOptionsRecording",
"ComponentOptionsRecordingSubscribeMode",
"ComponentPropertiesRecording",
"ComponentPropertiesRecordingSubscribeMode",
"S3Credentials",
]
__docformat__ = "restructuredtext"
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@

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

return {
"method": "post",
"url": "/hls/{room_id}/subscribe".format(
"url": "/room/{room_id}/component/{component_id}/subscribe".format(
room_id=room_id,
component_id=component_id,
),
"json": json_json_body,
}
Expand Down Expand Up @@ -63,14 +65,16 @@ def _build_response(

def sync_detailed(
room_id: str,
component_id: str,
*,
client: AuthenticatedClient,
json_body: SubscriptionConfig,
) -> Response[Union[Any, Error]]:
"""Subscribe the HLS component to the tracks of peers or components
"""Subscribe component to the tracks of peers or components
Args:
room_id (str):
component_id (str):
json_body (SubscriptionConfig): Subscription config
Raises:
Expand All @@ -83,6 +87,7 @@ def sync_detailed(

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

Expand All @@ -95,14 +100,16 @@ def sync_detailed(

def sync(
room_id: str,
component_id: str,
*,
client: AuthenticatedClient,
json_body: SubscriptionConfig,
) -> Optional[Union[Any, Error]]:
"""Subscribe the HLS component to the tracks of peers or components
"""Subscribe component to the tracks of peers or components
Args:
room_id (str):
component_id (str):
json_body (SubscriptionConfig): Subscription config
Raises:
Expand All @@ -115,21 +122,24 @@ def sync(

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: AuthenticatedClient,
json_body: SubscriptionConfig,
) -> Response[Union[Any, Error]]:
"""Subscribe the HLS component to the tracks of peers or components
"""Subscribe component to the tracks of peers or components
Args:
room_id (str):
component_id (str):
json_body (SubscriptionConfig): Subscription config
Raises:
Expand All @@ -142,6 +152,7 @@ async def asyncio_detailed(

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

Expand All @@ -152,14 +163,16 @@ async def asyncio_detailed(

async def asyncio(
room_id: str,
component_id: str,
*,
client: AuthenticatedClient,
json_body: SubscriptionConfig,
) -> Optional[Union[Any, Error]]:
"""Subscribe the HLS component to the tracks of peers or components
"""Subscribe component to the tracks of peers or components
Args:
room_id (str):
component_id (str):
json_body (SubscriptionConfig): Subscription config
Raises:
Expand All @@ -173,6 +186,7 @@ async def asyncio(
return (
await asyncio_detailed(
room_id=room_id,
component_id=component_id,
client=client,
json_body=json_body,
)
Expand Down
8 changes: 8 additions & 0 deletions jellyfish/_openapi_client/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@
from .component_options_hls import ComponentOptionsHLS
from .component_options_hls_subscribe_mode import ComponentOptionsHLSSubscribeMode
from .component_options_recording import ComponentOptionsRecording
from .component_options_recording_subscribe_mode import (
ComponentOptionsRecordingSubscribeMode,
)
from .component_options_rtsp import ComponentOptionsRTSP
from .component_options_sip import ComponentOptionsSIP
from .component_options_sipsip_credentials import ComponentOptionsSIPSIPCredentials
from .component_properties_file import ComponentPropertiesFile
from .component_properties_hls import ComponentPropertiesHLS
from .component_properties_hls_subscribe_mode import ComponentPropertiesHLSSubscribeMode
from .component_properties_recording import ComponentPropertiesRecording
from .component_properties_recording_subscribe_mode import (
ComponentPropertiesRecordingSubscribeMode,
)
from .component_properties_rtsp import ComponentPropertiesRTSP
from .component_properties_sip import ComponentPropertiesSIP
from .component_properties_sipsip_credentials import (
Expand Down Expand Up @@ -59,13 +65,15 @@
"ComponentOptionsHLS",
"ComponentOptionsHLSSubscribeMode",
"ComponentOptionsRecording",
"ComponentOptionsRecordingSubscribeMode",
"ComponentOptionsRTSP",
"ComponentOptionsSIP",
"ComponentOptionsSIPSIPCredentials",
"ComponentPropertiesFile",
"ComponentPropertiesHLS",
"ComponentPropertiesHLSSubscribeMode",
"ComponentPropertiesRecording",
"ComponentPropertiesRecordingSubscribeMode",
"ComponentPropertiesRTSP",
"ComponentPropertiesSIP",
"ComponentPropertiesSIPSIPCredentials",
Expand Down
22 changes: 21 additions & 1 deletion jellyfish/_openapi_client/models/component_options_recording.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from attrs import define as _attrs_define
from attrs import field as _attrs_field

from ..models.component_options_recording_subscribe_mode import (
ComponentOptionsRecordingSubscribeMode,
)
from ..types import UNSET, Unset

if TYPE_CHECKING:
Expand All @@ -18,8 +21,12 @@ class ComponentOptionsRecording:

credentials: Union[Unset, None, "S3Credentials"] = UNSET
"""An AWS S3 credential that will be used to send HLS stream. The stream will only be uploaded if credentials are provided"""
path_prefix: Union[Unset, str] = ""
path_prefix: Union[Unset, None, str] = UNSET
"""Path prefix under which all recording are stored"""
subscribe_mode: Union[
Unset, ComponentOptionsRecordingSubscribeMode
] = ComponentOptionsRecordingSubscribeMode.AUTO
"""Whether the Recording component should subscribe to tracks automatically or manually."""
additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict)
"""@private"""

Expand All @@ -30,6 +37,9 @@ def to_dict(self) -> Dict[str, Any]:
credentials = self.credentials.to_dict() if self.credentials else None

path_prefix = self.path_prefix
subscribe_mode: Union[Unset, str] = UNSET
if not isinstance(self.subscribe_mode, Unset):
subscribe_mode = self.subscribe_mode.value

field_dict: Dict[str, Any] = {}
field_dict.update(self.additional_properties)
Expand All @@ -38,6 +48,8 @@ def to_dict(self) -> Dict[str, Any]:
field_dict["credentials"] = credentials
if path_prefix is not UNSET:
field_dict["pathPrefix"] = path_prefix
if subscribe_mode is not UNSET:
field_dict["subscribeMode"] = subscribe_mode

return field_dict

Expand All @@ -58,9 +70,17 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:

path_prefix = d.pop("pathPrefix", UNSET)

_subscribe_mode = d.pop("subscribeMode", UNSET)
subscribe_mode: Union[Unset, ComponentOptionsRecordingSubscribeMode]
if isinstance(_subscribe_mode, Unset):
subscribe_mode = UNSET
else:
subscribe_mode = ComponentOptionsRecordingSubscribeMode(_subscribe_mode)

component_options_recording = cls(
credentials=credentials,
path_prefix=path_prefix,
subscribe_mode=subscribe_mode,
)

component_options_recording.additional_properties = d
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from enum import Enum


class ComponentOptionsRecordingSubscribeMode(str, Enum):
"""Whether the Recording component should subscribe to tracks automatically or manually."""

AUTO = "auto"
MANUAL = "manual"

def __str__(self) -> str:
return str(self.value)
18 changes: 12 additions & 6 deletions jellyfish/_openapi_client/models/component_properties_recording.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,31 @@
from attrs import define as _attrs_define
from attrs import field as _attrs_field

from ..models.component_properties_recording_subscribe_mode import (
ComponentPropertiesRecordingSubscribeMode,
)

T = TypeVar("T", bound="ComponentPropertiesRecording")


@_attrs_define
class ComponentPropertiesRecording:
"""Properties specific to the Recording component"""

path_prefix: str
"""Path prefix under which all recording are stored"""
subscribe_mode: ComponentPropertiesRecordingSubscribeMode
"""Whether the Recording component should subscribe to tracks automatically or manually"""
additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict)
"""@private"""

def to_dict(self) -> Dict[str, Any]:
"""@private"""
path_prefix = self.path_prefix
subscribe_mode = self.subscribe_mode.value

field_dict: Dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update(
{
"pathPrefix": path_prefix,
"subscribeMode": subscribe_mode,
}
)

Expand All @@ -33,10 +37,12 @@ def to_dict(self) -> Dict[str, Any]:
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
"""@private"""
d = src_dict.copy()
path_prefix = d.pop("pathPrefix")
subscribe_mode = ComponentPropertiesRecordingSubscribeMode(
d.pop("subscribeMode")
)

component_properties_recording = cls(
path_prefix=path_prefix,
subscribe_mode=subscribe_mode,
)

component_properties_recording.additional_properties = d
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from enum import Enum


class ComponentPropertiesRecordingSubscribeMode(str, Enum):
"""Whether the Recording component should subscribe to tracks automatically or manually"""

AUTO = "auto"
MANUAL = "manual"

def __str__(self) -> str:
return str(self.value)
14 changes: 14 additions & 0 deletions jellyfish/_openapi_client/models/health_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,36 @@ class HealthReport:

distribution: "HealthReportDistribution"
"""Informs about the status of Jellyfish distribution"""
git_commit: str
"""Commit hash of the build"""
status: HealthReportStatus
"""Informs about the status of Jellyfish or a specific service"""
uptime: int
"""Uptime of Jellyfish (in seconds)"""
version: str
"""Version of Jellyfish"""
additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict)
"""@private"""

def to_dict(self) -> Dict[str, Any]:
"""@private"""
distribution = self.distribution.to_dict()

git_commit = self.git_commit
status = self.status.value

uptime = self.uptime
version = self.version

field_dict: Dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update(
{
"distribution": distribution,
"gitCommit": git_commit,
"status": status,
"uptime": uptime,
"version": version,
}
)

Expand All @@ -53,14 +61,20 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
d = src_dict.copy()
distribution = HealthReportDistribution.from_dict(d.pop("distribution"))

git_commit = d.pop("gitCommit")

status = HealthReportStatus(d.pop("status"))

uptime = d.pop("uptime")

version = d.pop("version")

health_report = cls(
distribution=distribution,
git_commit=git_commit,
status=status,
uptime=uptime,
version=version,
)

health_report.additional_properties = d
Expand Down
Loading

0 comments on commit 1169e90

Please sign in to comment.