Skip to content

Commit

Permalink
[RTC-433] Add hls subscription and custom room id (#23)
Browse files Browse the repository at this point in the history
* Hls subscription

* Custom Room ID

* Fix typing

* Test for duplicated room
  • Loading branch information
roznawsk authored Dec 22, 2023
1 parent f2f6e28 commit 25d3d16
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 268 deletions.
4 changes: 2 additions & 2 deletions compile_proto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ git submodule update --recursive --remote --init >> /dev/null
printf "DONE\n\n"

server_file="./protos/jellyfish/server_notifications.proto"
printf "Compiling: file $server_file"
printf "Compiling: file $server_file\n"
protoc -I . --python_betterproto_out=./jellyfish/events/_protos $server_file
printf "\tDONE\n"

peer_file="./protos/jellyfish/peer_notifications.proto"
printf "Compiling: file $peer_file"
printf "Compiling: file $peer_file\n"
protoc -I . --python_betterproto_out=./tests/support/protos $peer_file
printf "\tDONE\n"
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def sync_detailed(
client: Union[AuthenticatedClient, Client],
json_body: SubscriptionConfig,
) -> Response[Union[Any, Error]]:
"""Subscribe hls component for tracks
"""Subscribe the HLS component to the tracks of peers or components
Args:
room_id (str):
Expand Down Expand Up @@ -95,7 +95,7 @@ def sync(
client: Union[AuthenticatedClient, Client],
json_body: SubscriptionConfig,
) -> Optional[Union[Any, Error]]:
"""Subscribe hls component for tracks
"""Subscribe the HLS component to the tracks of peers or components
Args:
room_id (str):
Expand All @@ -122,7 +122,7 @@ async def asyncio_detailed(
client: Union[AuthenticatedClient, Client],
json_body: SubscriptionConfig,
) -> Response[Union[Any, Error]]:
"""Subscribe hls component for tracks
"""Subscribe the HLS component to the tracks of peers or components
Args:
room_id (str):
Expand Down Expand Up @@ -152,7 +152,7 @@ async def asyncio(
client: Union[AuthenticatedClient, Client],
json_body: SubscriptionConfig,
) -> Optional[Union[Any, Error]]:
"""Subscribe hls component for tracks
"""Subscribe the HLS component to the tracks of peers or components
Args:
room_id (str):
Expand Down
8 changes: 8 additions & 0 deletions jellyfish/_openapi_client/models/room_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class RoomConfig:

max_peers: Union[Unset, None, int] = UNSET
"""Maximum amount of peers allowed into the room"""
room_id: Union[Unset, None, str] = UNSET
"""Custom id used for identifying room within Jellyfish. Must be unique across all rooms. If not provided, random UUID is generated."""
video_codec: Union[Unset, None, RoomConfigVideoCodec] = UNSET
"""Enforces video codec for each peer in the room"""
webhook_url: Union[Unset, None, str] = UNSET
Expand All @@ -25,6 +27,7 @@ class RoomConfig:
def to_dict(self) -> Dict[str, Any]:
"""@private"""
max_peers = self.max_peers
room_id = self.room_id
video_codec: Union[Unset, None, str] = UNSET
if not isinstance(self.video_codec, Unset):
video_codec = self.video_codec.value if self.video_codec else None
Expand All @@ -36,6 +39,8 @@ def to_dict(self) -> Dict[str, Any]:
field_dict.update({})
if max_peers is not UNSET:
field_dict["maxPeers"] = max_peers
if room_id is not UNSET:
field_dict["roomId"] = room_id
if video_codec is not UNSET:
field_dict["videoCodec"] = video_codec
if webhook_url is not UNSET:
Expand All @@ -49,6 +54,8 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
d = src_dict.copy()
max_peers = d.pop("maxPeers", UNSET)

room_id = d.pop("roomId", UNSET)

_video_codec = d.pop("videoCodec", UNSET)
video_codec: Union[Unset, None, RoomConfigVideoCodec]
if _video_codec is None:
Expand All @@ -62,6 +69,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:

room_config = cls(
max_peers=max_peers,
room_id=room_id,
video_codec=video_codec,
webhook_url=webhook_url,
)
Expand Down
18 changes: 9 additions & 9 deletions jellyfish/_openapi_client/models/subscription_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,33 @@
class SubscriptionConfig:
"""Subscription config"""

tracks: Union[Unset, List[str]] = UNSET
"""List of tracks that hls endpoint will subscribe for"""
origins: Union[Unset, List[str]] = UNSET
"""List of peers and components ids whose tracks the HLS endpoint will subscribe to"""
additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict)
"""@private"""

def to_dict(self) -> Dict[str, Any]:
"""@private"""
tracks: Union[Unset, List[str]] = UNSET
if not isinstance(self.tracks, Unset):
tracks = self.tracks
origins: Union[Unset, List[str]] = UNSET
if not isinstance(self.origins, Unset):
origins = self.origins

field_dict: Dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update({})
if tracks is not UNSET:
field_dict["tracks"] = tracks
if origins is not UNSET:
field_dict["origins"] = origins

return field_dict

@classmethod
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
"""@private"""
d = src_dict.copy()
tracks = cast(List[str], d.pop("tracks", UNSET))
origins = cast(List[str], d.pop("origins", UNSET))

subscription_config = cls(
tracks=tracks,
origins=origins,
)

subscription_config.additional_properties = d
Expand Down
10 changes: 9 additions & 1 deletion jellyfish/_openapi_client/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
""" Contains some shared types for properties """
from http import HTTPStatus
from typing import BinaryIO, Generic, Literal, MutableMapping, Optional, Tuple, TypeVar
from typing import (
BinaryIO,
Generic,
Literal,
MutableMapping,
Optional,
Tuple,
TypeVar,
)

from attrs import define

Expand Down
26 changes: 19 additions & 7 deletions jellyfish/api/_room_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from typing import Literal, Union

from jellyfish._openapi_client.api.hls import subscribe_tracks as hls_subscribe_tracks
from jellyfish._openapi_client.api.hls import subscribe_hls_to as hls_subscribe_hls_to
from jellyfish._openapi_client.api.room import add_component as room_add_component
from jellyfish._openapi_client.api.room import add_peer as room_add_peer
from jellyfish._openapi_client.api.room import create_room as room_create_room
Expand Down Expand Up @@ -51,6 +51,7 @@ def __init__(

def create_room(
self,
room_id: str = None,
max_peers: int = None,
video_codec: Literal["h264", "vp8"] = None,
webhook_url: str = None,
Expand All @@ -72,7 +73,10 @@ def create_room(
video_codec = None

room_config = RoomConfig(
max_peers=max_peers, video_codec=video_codec, webhook_url=webhook_url
room_id=room_id,
max_peers=max_peers,
video_codec=video_codec,
webhook_url=webhook_url,
)

resp = self._request(room_create_room, json_body=room_config)
Expand Down Expand Up @@ -139,11 +143,19 @@ def delete_component(self, room_id: str, component_id: str) -> None:

return self._request(room_delete_component, id=component_id, room_id=room_id)

def hls_subscribe(self, room_id: str, tracks: list):
"""subscribes hls component for tracks"""

subscription_config = SubscriptionConfig(tracks=tracks)
def hls_subscribe(self, room_id: str, origins: [str]):
"""
In order to subscribe to HLS peers/components,
the HLS component should be initialized with the subscribe_mode set to manual.
This mode proves beneficial when you do not wish to record or stream
all the available streams within a room via HLS.
It allows for selective addition instead –
you can manually select specific streams.
For instance, you could opt to record only the stream of an event's host.
"""

return self._request(
hls_subscribe_tracks, room_id=room_id, json_body=subscription_config
hls_subscribe_hls_to,
room_id=room_id,
json_body=SubscriptionConfig(origins=origins),
)
2 changes: 0 additions & 2 deletions jellyfish/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ class HTTPError(Exception):
def from_response(response: Response):
"""@private"""
errors = response.parsed.errors
print("resp errors", errors)

if response.status_code == HTTPStatus.BAD_REQUEST:
return BadRequestError(errors)

Expand Down
Loading

0 comments on commit 25d3d16

Please sign in to comment.