Skip to content

Commit e40007b

Browse files
Add agents to room api and add Agent class
1 parent 7d445a8 commit e40007b

24 files changed

+773
-143
lines changed

compile_proto.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ git submodule sync --recursive >>/dev/null
88
git submodule update --recursive --remote --init >>/dev/null
99
printf "DONE\n\n"
1010

11-
server_file="./protos/fishjam/server_notifications.proto"
12-
printf "Compiling: file $server_file\n"
13-
protoc -I . --python_betterproto_out=./fishjam/events/_protos $server_file
11+
FILES=("protos/fishjam/agent_notifications.proto" "protos/fishjam/server_notifications.proto")
12+
13+
printf "Compiling file: %s\n" "${FILES[@]}"
14+
protoc -I protos --python_betterproto_out="./fishjam/events/_protos" "${FILES[@]}"
1415
printf "\tDONE\n"

fishjam/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
.. include:: ../README.md
2+
.. include:: ../README.md
33
"""
44

55
# pylint: disable=locally-disabled, no-name-in-module, import-error
@@ -10,7 +10,7 @@
1010
# pylint: disable=locally-disabled, no-name-in-module, import-error
1111

1212
# Exceptions and Server Messages
13-
from fishjam import errors, events, peer, room
13+
from fishjam import agent, errors, events, peer, room
1414

1515
# API
1616
from fishjam._webhook_notifier import receive_binary
@@ -35,6 +35,7 @@
3535
"errors",
3636
"room",
3737
"peer",
38+
"agent",
3839
]
3940

4041
__docformat__ = "restructuredtext"

fishjam/_openapi_client/models/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,20 @@
77
from .peer import Peer
88
from .peer_details_response import PeerDetailsResponse
99
from .peer_details_response_data import PeerDetailsResponseData
10+
from .peer_options_agent import PeerOptionsAgent
1011
from .peer_options_web_rtc import PeerOptionsWebRTC
1112
from .peer_options_web_rtc_metadata import PeerOptionsWebRTCMetadata
13+
from .peer_options_web_rtc_subscribe import PeerOptionsWebRTCSubscribe
14+
from .peer_options_web_rtc_subscribe_audio_format import (
15+
PeerOptionsWebRTCSubscribeAudioFormat,
16+
)
17+
from .peer_options_web_rtc_subscribe_audio_sample_rate import (
18+
PeerOptionsWebRTCSubscribeAudioSampleRate,
19+
)
1220
from .peer_refresh_token_response import PeerRefreshTokenResponse
1321
from .peer_refresh_token_response_data import PeerRefreshTokenResponseData
1422
from .peer_status import PeerStatus
23+
from .peer_type import PeerType
1524
from .room import Room
1625
from .room_config import RoomConfig
1726
from .room_config_room_type import RoomConfigRoomType
@@ -33,11 +42,16 @@
3342
"Peer",
3443
"PeerDetailsResponse",
3544
"PeerDetailsResponseData",
45+
"PeerOptionsAgent",
3646
"PeerOptionsWebRTC",
3747
"PeerOptionsWebRTCMetadata",
48+
"PeerOptionsWebRTCSubscribe",
49+
"PeerOptionsWebRTCSubscribeAudioFormat",
50+
"PeerOptionsWebRTCSubscribeAudioSampleRate",
3851
"PeerRefreshTokenResponse",
3952
"PeerRefreshTokenResponseData",
4053
"PeerStatus",
54+
"PeerType",
4155
"Room",
4256
"RoomConfig",
4357
"RoomConfigRoomType",

fishjam/_openapi_client/models/add_peer_json_body.py

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1-
from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar
1+
from typing import (
2+
TYPE_CHECKING,
3+
Any,
4+
Dict,
5+
List,
6+
Type,
7+
TypeVar,
8+
Union,
9+
)
210

311
from attrs import define as _attrs_define
412
from attrs import field as _attrs_field
513

14+
from ..models.peer_type import PeerType
15+
616
if TYPE_CHECKING:
17+
from ..models.peer_options_agent import PeerOptionsAgent
718
from ..models.peer_options_web_rtc import PeerOptionsWebRTC
819

920

@@ -14,18 +25,26 @@
1425
class AddPeerJsonBody:
1526
""" """
1627

17-
options: "PeerOptionsWebRTC"
18-
"""Options specific to the WebRTC peer"""
19-
type: str
28+
options: Union["PeerOptionsAgent", "PeerOptionsWebRTC"]
29+
"""Peer-specific options"""
30+
type: PeerType
2031
"""Peer type"""
2132
additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict)
2233
"""@private"""
2334

2435
def to_dict(self) -> Dict[str, Any]:
2536
"""@private"""
26-
options = self.options.to_dict()
37+
from ..models.peer_options_web_rtc import PeerOptionsWebRTC
38+
39+
options: Dict[str, Any]
40+
41+
if isinstance(self.options, PeerOptionsWebRTC):
42+
options = self.options.to_dict()
43+
44+
else:
45+
options = self.options.to_dict()
2746

28-
type = self.type
47+
type = self.type.value
2948

3049
field_dict: Dict[str, Any] = {}
3150
field_dict.update(self.additional_properties)
@@ -41,12 +60,33 @@ def to_dict(self) -> Dict[str, Any]:
4160
@classmethod
4261
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
4362
"""@private"""
63+
from ..models.peer_options_agent import PeerOptionsAgent
4464
from ..models.peer_options_web_rtc import PeerOptionsWebRTC
4565

4666
d = src_dict.copy()
47-
options = PeerOptionsWebRTC.from_dict(d.pop("options"))
4867

49-
type = d.pop("type")
68+
def _parse_options(
69+
data: object,
70+
) -> Union["PeerOptionsAgent", "PeerOptionsWebRTC"]:
71+
try:
72+
if not isinstance(data, dict):
73+
raise TypeError()
74+
componentsschemas_peer_options_type_0 = PeerOptionsWebRTC.from_dict(
75+
data
76+
)
77+
78+
return componentsschemas_peer_options_type_0
79+
except: # noqa: E722
80+
pass
81+
if not isinstance(data, dict):
82+
raise TypeError()
83+
componentsschemas_peer_options_type_1 = PeerOptionsAgent.from_dict(data)
84+
85+
return componentsschemas_peer_options_type_1
86+
87+
options = _parse_options(d.pop("options"))
88+
89+
type = PeerType(d.pop("type"))
5090

5191
add_peer_json_body = cls(
5292
options=options,

fishjam/_openapi_client/models/peer.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from attrs import field as _attrs_field
55

66
from ..models.peer_status import PeerStatus
7+
from ..models.peer_type import PeerType
78

89
if TYPE_CHECKING:
910
from ..models.track import Track
@@ -24,7 +25,7 @@ class Peer:
2425
"""Informs about the peer status"""
2526
tracks: List["Track"]
2627
"""List of all peer's tracks"""
27-
type: str
28+
type: PeerType
2829
"""Peer type"""
2930
additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict)
3031
"""@private"""
@@ -41,7 +42,7 @@ def to_dict(self) -> Dict[str, Any]:
4142

4243
tracks.append(tracks_item)
4344

44-
type = self.type
45+
type = self.type.value
4546

4647
field_dict: Dict[str, Any] = {}
4748
field_dict.update(self.additional_properties)
@@ -76,7 +77,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
7677

7778
tracks.append(tracks_item)
7879

79-
type = d.pop("type")
80+
type = PeerType(d.pop("type"))
8081

8182
peer = cls(
8283
id=id,
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from typing import Any, Dict, List, Type, TypeVar
2+
3+
from attrs import define as _attrs_define
4+
from attrs import field as _attrs_field
5+
6+
T = TypeVar("T", bound="PeerOptionsAgent")
7+
8+
9+
@_attrs_define
10+
class PeerOptionsAgent:
11+
"""Options specific to the Agent peer"""
12+
13+
additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict)
14+
"""@private"""
15+
16+
def to_dict(self) -> Dict[str, Any]:
17+
"""@private"""
18+
19+
field_dict: Dict[str, Any] = {}
20+
field_dict.update(self.additional_properties)
21+
field_dict.update({})
22+
23+
return field_dict
24+
25+
@classmethod
26+
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
27+
"""@private"""
28+
d = src_dict.copy()
29+
peer_options_agent = cls()
30+
31+
peer_options_agent.additional_properties = d
32+
return peer_options_agent
33+
34+
@property
35+
def additional_keys(self) -> List[str]:
36+
"""@private"""
37+
return list(self.additional_properties.keys())
38+
39+
def __getitem__(self, key: str) -> Any:
40+
return self.additional_properties[key]
41+
42+
def __setitem__(self, key: str, value: Any) -> None:
43+
self.additional_properties[key] = value
44+
45+
def __delitem__(self, key: str) -> None:
46+
del self.additional_properties[key]
47+
48+
def __contains__(self, key: str) -> bool:
49+
return key in self.additional_properties

fishjam/_openapi_client/models/peer_options_web_rtc.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
if TYPE_CHECKING:
99
from ..models.peer_options_web_rtc_metadata import PeerOptionsWebRTCMetadata
10+
from ..models.peer_options_web_rtc_subscribe import PeerOptionsWebRTCSubscribe
1011

1112

1213
T = TypeVar("T", bound="PeerOptionsWebRTC")
@@ -20,6 +21,8 @@ class PeerOptionsWebRTC:
2021
"""Enables the peer to use simulcast"""
2122
metadata: Union[Unset, "PeerOptionsWebRTCMetadata"] = UNSET
2223
"""Custom peer metadata"""
24+
subscribe: Union[Unset, None, "PeerOptionsWebRTCSubscribe"] = UNSET
25+
"""Configure server-side subscriptions to the peer's tracks"""
2326
additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict)
2427
"""@private"""
2528

@@ -30,20 +33,27 @@ def to_dict(self) -> Dict[str, Any]:
3033
if not isinstance(self.metadata, Unset):
3134
metadata = self.metadata.to_dict()
3235

36+
subscribe: Union[Unset, None, Dict[str, Any]] = UNSET
37+
if not isinstance(self.subscribe, Unset):
38+
subscribe = self.subscribe.to_dict() if self.subscribe else None
39+
3340
field_dict: Dict[str, Any] = {}
3441
field_dict.update(self.additional_properties)
3542
field_dict.update({})
3643
if enable_simulcast is not UNSET:
3744
field_dict["enableSimulcast"] = enable_simulcast
3845
if metadata is not UNSET:
3946
field_dict["metadata"] = metadata
47+
if subscribe is not UNSET:
48+
field_dict["subscribe"] = subscribe
4049

4150
return field_dict
4251

4352
@classmethod
4453
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
4554
"""@private"""
4655
from ..models.peer_options_web_rtc_metadata import PeerOptionsWebRTCMetadata
56+
from ..models.peer_options_web_rtc_subscribe import PeerOptionsWebRTCSubscribe
4757

4858
d = src_dict.copy()
4959
enable_simulcast = d.pop("enableSimulcast", UNSET)
@@ -55,9 +65,19 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
5565
else:
5666
metadata = PeerOptionsWebRTCMetadata.from_dict(_metadata)
5767

68+
_subscribe = d.pop("subscribe", UNSET)
69+
subscribe: Union[Unset, None, PeerOptionsWebRTCSubscribe]
70+
if _subscribe is None:
71+
subscribe = None
72+
elif isinstance(_subscribe, Unset):
73+
subscribe = UNSET
74+
else:
75+
subscribe = PeerOptionsWebRTCSubscribe.from_dict(_subscribe)
76+
5877
peer_options_web_rtc = cls(
5978
enable_simulcast=enable_simulcast,
6079
metadata=metadata,
80+
subscribe=subscribe,
6181
)
6282

6383
peer_options_web_rtc.additional_properties = d
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
from typing import Any, Dict, Type, TypeVar, Union
2+
3+
from attrs import define as _attrs_define
4+
5+
from ..models.peer_options_web_rtc_subscribe_audio_format import (
6+
PeerOptionsWebRTCSubscribeAudioFormat,
7+
)
8+
from ..models.peer_options_web_rtc_subscribe_audio_sample_rate import (
9+
PeerOptionsWebRTCSubscribeAudioSampleRate,
10+
)
11+
from ..types import UNSET, Unset
12+
13+
T = TypeVar("T", bound="PeerOptionsWebRTCSubscribe")
14+
15+
16+
@_attrs_define
17+
class PeerOptionsWebRTCSubscribe:
18+
"""Configure server-side subscriptions to the peer's tracks
19+
20+
Example:
21+
{'audioFormat': 'pcm16'}
22+
23+
"""
24+
25+
audio_format: Union[
26+
Unset, PeerOptionsWebRTCSubscribeAudioFormat
27+
] = PeerOptionsWebRTCSubscribeAudioFormat.PCM16
28+
"""The format to use for the output audio"""
29+
audio_sample_rate: Union[
30+
Unset, PeerOptionsWebRTCSubscribeAudioSampleRate
31+
] = PeerOptionsWebRTCSubscribeAudioSampleRate.VALUE_16000
32+
"""The sample rate to use for the output audio"""
33+
34+
def to_dict(self) -> Dict[str, Any]:
35+
"""@private"""
36+
audio_format: Union[Unset, str] = UNSET
37+
if not isinstance(self.audio_format, Unset):
38+
audio_format = self.audio_format.value
39+
40+
audio_sample_rate: Union[Unset, int] = UNSET
41+
if not isinstance(self.audio_sample_rate, Unset):
42+
audio_sample_rate = self.audio_sample_rate.value
43+
44+
field_dict: Dict[str, Any] = {}
45+
field_dict.update({})
46+
if audio_format is not UNSET:
47+
field_dict["audioFormat"] = audio_format
48+
if audio_sample_rate is not UNSET:
49+
field_dict["audioSampleRate"] = audio_sample_rate
50+
51+
return field_dict
52+
53+
@classmethod
54+
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
55+
"""@private"""
56+
d = src_dict.copy()
57+
_audio_format = d.pop("audioFormat", UNSET)
58+
audio_format: Union[Unset, PeerOptionsWebRTCSubscribeAudioFormat]
59+
if isinstance(_audio_format, Unset):
60+
audio_format = UNSET
61+
else:
62+
audio_format = PeerOptionsWebRTCSubscribeAudioFormat(_audio_format)
63+
64+
_audio_sample_rate = d.pop("audioSampleRate", UNSET)
65+
audio_sample_rate: Union[Unset, PeerOptionsWebRTCSubscribeAudioSampleRate]
66+
if isinstance(_audio_sample_rate, Unset):
67+
audio_sample_rate = UNSET
68+
else:
69+
audio_sample_rate = PeerOptionsWebRTCSubscribeAudioSampleRate(
70+
_audio_sample_rate
71+
)
72+
73+
peer_options_web_rtc_subscribe = cls(
74+
audio_format=audio_format,
75+
audio_sample_rate=audio_sample_rate,
76+
)
77+
78+
return peer_options_web_rtc_subscribe

0 commit comments

Comments
 (0)