Skip to content

Commit 8da05f9

Browse files
committed
update _fishjam_client docstrings
1 parent 461b8ea commit 8da05f9

1 file changed

Lines changed: 128 additions & 25 deletions

File tree

fishjam/api/_fishjam_client.py

Lines changed: 128 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@
5151

5252
@dataclass
5353
class Room:
54-
"""Description of the room state"""
54+
"""Description of the room state.
55+
56+
Attributes:
57+
config: Room configuration.
58+
id: Room ID.
59+
peers: List of all peers.
60+
"""
5561

5662
config: RoomConfig
5763
"""Room configuration"""
@@ -63,7 +69,15 @@ class Room:
6369

6470
@dataclass
6571
class RoomOptions:
66-
"""Description of a room options"""
72+
"""Description of a room options.
73+
74+
Attributes:
75+
max_peers: Maximum amount of peers allowed into the room.
76+
video_codec: Enforces video codec for each peer in the room.
77+
webhook_url: URL where Fishjam notifications will be sent.
78+
room_type: The use-case of the room. If not provided, this defaults to conference.
79+
public: True if livestream viewers can omit specifying a token.
80+
"""
6781

6882
max_peers: int | None = None
6983
"""Maximum amount of peers allowed into the room"""
@@ -86,7 +100,13 @@ class RoomOptions:
86100

87101
@dataclass
88102
class PeerOptions:
89-
"""Options specific to a WebRTC Peer"""
103+
"""Options specific to a WebRTC Peer.
104+
105+
Attributes:
106+
enable_simulcast: Enables the peer to use simulcast.
107+
metadata: Peer metadata.
108+
subscribe_mode: Configuration of peer's subscribing policy.
109+
"""
90110

91111
enable_simulcast: bool = True
92112
"""Enables the peer to use simulcast"""
@@ -98,31 +118,44 @@ class PeerOptions:
98118

99119
@dataclass
100120
class AgentOutputOptions:
101-
"""Options of the desired format of audio tracks going from Fishjam to the agent."""
121+
"""Options of the desired format of audio tracks going from Fishjam to the agent.
122+
123+
Attributes:
124+
audio_format: The format of the audio stream (e.g., 'pcm16').
125+
audio_sample_rate: The sample rate of the audio stream.
126+
"""
102127

103128
audio_format: Literal["pcm16"] = "pcm16"
104129
audio_sample_rate: Literal[16000, 24000] = 16000
105130

106131

107132
@dataclass
108133
class AgentOptions:
109-
"""Options specific to a WebRTC Peer"""
134+
"""Options specific to a WebRTC Peer.
135+
136+
Attributes:
137+
output: Configuration for the agent's output options.
138+
subscribe_mode: Configuration of peer's subscribing policy.
139+
"""
110140

111141
output: AgentOutputOptions = field(default_factory=AgentOutputOptions)
112142

113143
subscribe_mode: Literal["auto", "manual"] = "auto"
114144

115145

116146
class FishjamClient(Client):
117-
"""Allows for managing rooms"""
147+
"""Allows for managing rooms."""
118148

119149
def __init__(
120150
self,
121151
fishjam_id: str,
122152
management_token: str,
123153
):
124-
"""
125-
Create a FishjamClient instance, providing the fishjam id and management token.
154+
"""Create a FishjamClient instance.
155+
156+
Args:
157+
fishjam_id: The unique identifier for the Fishjam instance.
158+
management_token: The token used for authenticating management operations.
126159
"""
127160
super().__init__(fishjam_id=fishjam_id, management_token=management_token)
128161

@@ -131,13 +164,16 @@ def create_peer(
131164
room_id: str,
132165
options: PeerOptions | None = None,
133166
) -> tuple[Peer, str]:
134-
"""
135-
Creates peer in the room
167+
"""Creates a peer in the room.
136168
137-
Returns a tuple (`Peer`, `PeerToken`) - the token is needed by Peer
138-
to authenticate to Fishjam.
169+
Args:
170+
room_id: The ID of the room where the peer will be created.
171+
options: Configuration options for the peer. Defaults to None.
139172
140-
The possible options to pass for peer are `PeerOptions`.
173+
Returns:
174+
A tuple containing:
175+
- Peer: The created peer object.
176+
- str: The peer token needed to authenticate to Fishjam.
141177
"""
142178
options = options or PeerOptions()
143179

@@ -157,6 +193,15 @@ def create_peer(
157193
return (resp.data.peer, resp.data.token)
158194

159195
def create_agent(self, room_id: str, options: AgentOptions | None = None):
196+
"""Creates an agent in the room.
197+
198+
Args:
199+
room_id: The ID of the room where the agent will be created.
200+
options: Configuration options for the agent. Defaults to None.
201+
202+
Returns:
203+
Agent: The created agent instance initialized with peer ID, room ID, token, and Fishjam URL.
204+
"""
160205
options = options or AgentOptions()
161206
body = AddPeerBody(
162207
type_=PeerType.AGENT,
@@ -181,9 +226,13 @@ def create_agent(self, room_id: str, options: AgentOptions | None = None):
181226
return Agent(resp.data.peer.id, room_id, resp.data.token, self._fishjam_url)
182227

183228
def create_room(self, options: RoomOptions | None = None) -> Room:
184-
"""
185-
Creates a new room
186-
Returns the created `Room`
229+
"""Creates a new room.
230+
231+
Args:
232+
options: Configuration options for the room. Defaults to None.
233+
234+
Returns:
235+
Room: The created Room object.
187236
"""
188237
options = options or RoomOptions()
189238

@@ -207,7 +256,11 @@ def create_room(self, options: RoomOptions | None = None) -> Room:
207256
return Room(config=room.config, id=room.id, peers=room.peers)
208257

209258
def get_all_rooms(self) -> list[Room]:
210-
"""Returns list of all rooms"""
259+
"""Returns list of all rooms.
260+
261+
Returns:
262+
list[Room]: A list of all available Room objects.
263+
"""
211264

212265
rooms = cast(RoomsListingResponse, self._request(room_get_all_rooms)).data
213266

@@ -216,7 +269,14 @@ def get_all_rooms(self) -> list[Room]:
216269
]
217270

218271
def get_room(self, room_id: str) -> Room:
219-
"""Returns room with the given id"""
272+
"""Returns room with the given id.
273+
274+
Args:
275+
room_id: The ID of the room to retrieve.
276+
277+
Returns:
278+
Room: The Room object corresponding to the given ID.
279+
"""
220280

221281
room = cast(
222282
RoomDetailsResponse, self._request(room_get_room, room_id=room_id)
@@ -225,17 +285,34 @@ def get_room(self, room_id: str) -> Room:
225285
return Room(config=room.config, id=room.id, peers=room.peers)
226286

227287
def delete_peer(self, room_id: str, peer_id: str) -> None:
228-
"""Deletes peer"""
288+
"""Deletes a peer from a room.
289+
290+
Args:
291+
room_id: The ID of the room the peer belongs to.
292+
peer_id: The ID of the peer to delete.
293+
"""
229294

230295
return self._request(room_delete_peer, id=peer_id, room_id=room_id)
231296

232297
def delete_room(self, room_id: str) -> None:
233-
"""Deletes a room"""
298+
"""Deletes a room.
299+
300+
Args:
301+
room_id: The ID of the room to delete.
302+
"""
234303

235304
return self._request(room_delete_room, room_id=room_id)
236305

237306
def refresh_peer_token(self, room_id: str, peer_id: str) -> str:
238-
"""Refreshes peer token"""
307+
"""Refreshes a peer token.
308+
309+
Args:
310+
room_id: The ID of the room.
311+
peer_id: The ID of the peer whose token needs refreshing.
312+
313+
Returns:
314+
str: The new peer token.
315+
"""
239316

240317
response = cast(
241318
PeerRefreshTokenResponse,
@@ -245,7 +322,14 @@ def refresh_peer_token(self, room_id: str, peer_id: str) -> str:
245322
return response.data.token
246323

247324
def create_livestream_viewer_token(self, room_id: str) -> str:
248-
"""Generates viewer token for livestream rooms"""
325+
"""Generates a viewer token for livestream rooms.
326+
327+
Args:
328+
room_id: The ID of the livestream room.
329+
330+
Returns:
331+
str: The generated viewer token.
332+
"""
249333

250334
response = cast(
251335
ViewerToken, self._request(viewer_generate_viewer_token, room_id=room_id)
@@ -254,7 +338,14 @@ def create_livestream_viewer_token(self, room_id: str) -> str:
254338
return response.token
255339

256340
def create_livestream_streamer_token(self, room_id: str) -> str:
257-
"""Generates streamer token for livestream rooms"""
341+
"""Generates a streamer token for livestream rooms.
342+
343+
Args:
344+
room_id: The ID of the livestream room.
345+
346+
Returns:
347+
str: The generated streamer token.
348+
"""
258349

259350
response = cast(
260351
StreamerToken,
@@ -264,7 +355,13 @@ def create_livestream_streamer_token(self, room_id: str) -> str:
264355
return response.token
265356

266357
def subscribe_peer(self, room_id: str, peer_id: str, target_peer_id: str):
267-
"""Subscribe a peer to all tracks of another peer."""
358+
"""Subscribes a peer to all tracks of another peer.
359+
360+
Args:
361+
room_id: The ID of the room.
362+
peer_id: The ID of the subscribing peer.
363+
target_peer_id: The ID of the peer to subscribe to.
364+
"""
268365

269366
self._request(
270367
room_subscribe_peer,
@@ -274,7 +371,13 @@ def subscribe_peer(self, room_id: str, peer_id: str, target_peer_id: str):
274371
)
275372

276373
def subscribe_tracks(self, room_id: str, peer_id: str, track_ids: list[str]):
277-
"""Subscribe a peer to specific tracks of another peer."""
374+
"""Subscribes a peer to specific tracks of another peer.
375+
376+
Args:
377+
room_id: The ID of the room.
378+
peer_id: The ID of the subscribing peer.
379+
track_ids: A list of track IDs to subscribe to.
380+
"""
278381

279382
self._request(
280383
room_subscribe_tracks,

0 commit comments

Comments
 (0)