Skip to content

Commit 25d3d16

Browse files
authored
[RTC-433] Add hls subscription and custom room id (#23)
* Hls subscription * Custom Room ID * Fix typing * Test for duplicated room
1 parent f2f6e28 commit 25d3d16

9 files changed

Lines changed: 130 additions & 268 deletions

File tree

compile_proto.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ git submodule update --recursive --remote --init >> /dev/null
1010
printf "DONE\n\n"
1111

1212
server_file="./protos/jellyfish/server_notifications.proto"
13-
printf "Compiling: file $server_file"
13+
printf "Compiling: file $server_file\n"
1414
protoc -I . --python_betterproto_out=./jellyfish/events/_protos $server_file
1515
printf "\tDONE\n"
1616

1717
peer_file="./protos/jellyfish/peer_notifications.proto"
18-
printf "Compiling: file $peer_file"
18+
printf "Compiling: file $peer_file\n"
1919
protoc -I . --python_betterproto_out=./tests/support/protos $peer_file
2020
printf "\tDONE\n"

jellyfish/_openapi_client/api/hls/subscribe_tracks.py renamed to jellyfish/_openapi_client/api/hls/subscribe_hls_to.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def sync_detailed(
6363
client: Union[AuthenticatedClient, Client],
6464
json_body: SubscriptionConfig,
6565
) -> Response[Union[Any, Error]]:
66-
"""Subscribe hls component for tracks
66+
"""Subscribe the HLS component to the tracks of peers or components
6767
6868
Args:
6969
room_id (str):
@@ -95,7 +95,7 @@ def sync(
9595
client: Union[AuthenticatedClient, Client],
9696
json_body: SubscriptionConfig,
9797
) -> Optional[Union[Any, Error]]:
98-
"""Subscribe hls component for tracks
98+
"""Subscribe the HLS component to the tracks of peers or components
9999
100100
Args:
101101
room_id (str):
@@ -122,7 +122,7 @@ async def asyncio_detailed(
122122
client: Union[AuthenticatedClient, Client],
123123
json_body: SubscriptionConfig,
124124
) -> Response[Union[Any, Error]]:
125-
"""Subscribe hls component for tracks
125+
"""Subscribe the HLS component to the tracks of peers or components
126126
127127
Args:
128128
room_id (str):
@@ -152,7 +152,7 @@ async def asyncio(
152152
client: Union[AuthenticatedClient, Client],
153153
json_body: SubscriptionConfig,
154154
) -> Optional[Union[Any, Error]]:
155-
"""Subscribe hls component for tracks
155+
"""Subscribe the HLS component to the tracks of peers or components
156156
157157
Args:
158158
room_id (str):

jellyfish/_openapi_client/models/room_config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class RoomConfig:
1515

1616
max_peers: Union[Unset, None, int] = UNSET
1717
"""Maximum amount of peers allowed into the room"""
18+
room_id: Union[Unset, None, str] = UNSET
19+
"""Custom id used for identifying room within Jellyfish. Must be unique across all rooms. If not provided, random UUID is generated."""
1820
video_codec: Union[Unset, None, RoomConfigVideoCodec] = UNSET
1921
"""Enforces video codec for each peer in the room"""
2022
webhook_url: Union[Unset, None, str] = UNSET
@@ -25,6 +27,7 @@ class RoomConfig:
2527
def to_dict(self) -> Dict[str, Any]:
2628
"""@private"""
2729
max_peers = self.max_peers
30+
room_id = self.room_id
2831
video_codec: Union[Unset, None, str] = UNSET
2932
if not isinstance(self.video_codec, Unset):
3033
video_codec = self.video_codec.value if self.video_codec else None
@@ -36,6 +39,8 @@ def to_dict(self) -> Dict[str, Any]:
3639
field_dict.update({})
3740
if max_peers is not UNSET:
3841
field_dict["maxPeers"] = max_peers
42+
if room_id is not UNSET:
43+
field_dict["roomId"] = room_id
3944
if video_codec is not UNSET:
4045
field_dict["videoCodec"] = video_codec
4146
if webhook_url is not UNSET:
@@ -49,6 +54,8 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
4954
d = src_dict.copy()
5055
max_peers = d.pop("maxPeers", UNSET)
5156

57+
room_id = d.pop("roomId", UNSET)
58+
5259
_video_codec = d.pop("videoCodec", UNSET)
5360
video_codec: Union[Unset, None, RoomConfigVideoCodec]
5461
if _video_codec is None:
@@ -62,6 +69,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
6269

6370
room_config = cls(
6471
max_peers=max_peers,
72+
room_id=room_id,
6573
video_codec=video_codec,
6674
webhook_url=webhook_url,
6775
)

jellyfish/_openapi_client/models/subscription_config.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,33 @@
1212
class SubscriptionConfig:
1313
"""Subscription config"""
1414

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

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

2626
field_dict: Dict[str, Any] = {}
2727
field_dict.update(self.additional_properties)
2828
field_dict.update({})
29-
if tracks is not UNSET:
30-
field_dict["tracks"] = tracks
29+
if origins is not UNSET:
30+
field_dict["origins"] = origins
3131

3232
return field_dict
3333

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

4040
subscription_config = cls(
41-
tracks=tracks,
41+
origins=origins,
4242
)
4343

4444
subscription_config.additional_properties = d

jellyfish/_openapi_client/types.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
""" Contains some shared types for properties """
22
from http import HTTPStatus
3-
from typing import BinaryIO, Generic, Literal, MutableMapping, Optional, Tuple, TypeVar
3+
from typing import (
4+
BinaryIO,
5+
Generic,
6+
Literal,
7+
MutableMapping,
8+
Optional,
9+
Tuple,
10+
TypeVar,
11+
)
412

513
from attrs import define
614

jellyfish/api/_room_api.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from typing import Literal, Union
66

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

5252
def create_room(
5353
self,
54+
room_id: str = None,
5455
max_peers: int = None,
5556
video_codec: Literal["h264", "vp8"] = None,
5657
webhook_url: str = None,
@@ -72,7 +73,10 @@ def create_room(
7273
video_codec = None
7374

7475
room_config = RoomConfig(
75-
max_peers=max_peers, video_codec=video_codec, webhook_url=webhook_url
76+
room_id=room_id,
77+
max_peers=max_peers,
78+
video_codec=video_codec,
79+
webhook_url=webhook_url,
7680
)
7781

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

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

142-
def hls_subscribe(self, room_id: str, tracks: list):
143-
"""subscribes hls component for tracks"""
144-
145-
subscription_config = SubscriptionConfig(tracks=tracks)
146+
def hls_subscribe(self, room_id: str, origins: [str]):
147+
"""
148+
In order to subscribe to HLS peers/components,
149+
the HLS component should be initialized with the subscribe_mode set to manual.
150+
This mode proves beneficial when you do not wish to record or stream
151+
all the available streams within a room via HLS.
152+
It allows for selective addition instead –
153+
you can manually select specific streams.
154+
For instance, you could opt to record only the stream of an event's host.
155+
"""
146156

147157
return self._request(
148-
hls_subscribe_tracks, room_id=room_id, json_body=subscription_config
158+
hls_subscribe_hls_to,
159+
room_id=room_id,
160+
json_body=SubscriptionConfig(origins=origins),
149161
)

jellyfish/errors.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ class HTTPError(Exception):
1010
def from_response(response: Response):
1111
"""@private"""
1212
errors = response.parsed.errors
13-
print("resp errors", errors)
14-
1513
if response.status_code == HTTPStatus.BAD_REQUEST:
1614
return BadRequestError(errors)
1715

0 commit comments

Comments
 (0)