Skip to content

Commit d976d67

Browse files
added new APIs in SIP, Egress, and Room (#403)
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 1831dbb commit d976d67

File tree

18 files changed

+792
-286
lines changed

18 files changed

+792
-286
lines changed

livekit-api/livekit/api/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,6 @@
5252
"AccessToken",
5353
"TokenVerifier",
5454
"WebhookReceiver",
55+
"TwirpError",
56+
"TwirpErrorCode",
5557
]

livekit-api/livekit/api/_service.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
from typing import Dict
43
import aiohttp
54
from abc import ABC
65
from .twirp_client import TwirpClient
@@ -17,7 +16,7 @@ def __init__(self, session: aiohttp.ClientSession, host: str, api_key: str, api_
1716

1817
def _auth_header(
1918
self, grants: VideoGrants | None, sip: SIPGrants | None = None
20-
) -> Dict[str, str]:
19+
) -> dict[str, str]:
2120
tok = AccessToken(self.api_key, self.api_secret)
2221
if grants:
2322
tok.with_grants(grants)

livekit-api/livekit/api/egress_service.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def __init__(self, session: aiohttp.ClientSession, url: str, api_key: str, api_s
3737
super().__init__(session, url, api_key, api_secret)
3838

3939
async def start_room_composite_egress(self, start: RoomCompositeEgressRequest) -> EgressInfo:
40+
"""Starts a composite recording of a room."""
4041
return await self._client.request(
4142
SVC,
4243
"StartRoomCompositeEgress",
@@ -46,6 +47,7 @@ async def start_room_composite_egress(self, start: RoomCompositeEgressRequest) -
4647
)
4748

4849
async def start_web_egress(self, start: WebEgressRequest) -> EgressInfo:
50+
"""Starts a recording of a web page."""
4951
return await self._client.request(
5052
SVC,
5153
"StartWebEgress",
@@ -55,6 +57,7 @@ async def start_web_egress(self, start: WebEgressRequest) -> EgressInfo:
5557
)
5658

5759
async def start_participant_egress(self, start: ParticipantEgressRequest) -> EgressInfo:
60+
"""Starts a recording of a participant."""
5861
return await self._client.request(
5962
SVC,
6063
"StartParticipantEgress",
@@ -64,6 +67,7 @@ async def start_participant_egress(self, start: ParticipantEgressRequest) -> Egr
6467
)
6568

6669
async def start_track_composite_egress(self, start: TrackCompositeEgressRequest) -> EgressInfo:
70+
"""Starts a composite recording with audio and video tracks."""
6771
return await self._client.request(
6872
SVC,
6973
"StartTrackCompositeEgress",
@@ -73,6 +77,7 @@ async def start_track_composite_egress(self, start: TrackCompositeEgressRequest)
7377
)
7478

7579
async def start_track_egress(self, start: TrackEgressRequest) -> EgressInfo:
80+
"""Starts a recording of a single track."""
7681
return await self._client.request(
7782
SVC,
7883
"StartTrackEgress",
@@ -82,6 +87,7 @@ async def start_track_egress(self, start: TrackEgressRequest) -> EgressInfo:
8287
)
8388

8489
async def update_layout(self, update: UpdateLayoutRequest) -> EgressInfo:
90+
"""Updates the layout of a composite recording."""
8591
return await self._client.request(
8692
SVC,
8793
"UpdateLayout",
@@ -91,6 +97,7 @@ async def update_layout(self, update: UpdateLayoutRequest) -> EgressInfo:
9197
)
9298

9399
async def update_stream(self, update: UpdateStreamRequest) -> EgressInfo:
100+
"""Updates the stream of a RoomComposite, Web, or Participant recording."""
94101
return await self._client.request(
95102
SVC,
96103
"UpdateStream",
@@ -100,6 +107,14 @@ async def update_stream(self, update: UpdateStreamRequest) -> EgressInfo:
100107
)
101108

102109
async def list_egress(self, list: ListEgressRequest) -> ListEgressResponse:
110+
"""Lists all active egress and recently completed recordings.
111+
112+
Args:
113+
list (ListEgressRequest): arg contains optional filters:
114+
- room_name: str - List all egresses for a specific room
115+
- egress_id: str - Only list egress with matching ID
116+
- active: bool - Only list active egresses
117+
"""
103118
return await self._client.request(
104119
SVC,
105120
"ListEgress",
@@ -109,6 +124,7 @@ async def list_egress(self, list: ListEgressRequest) -> ListEgressResponse:
109124
)
110125

111126
async def stop_egress(self, stop: StopEgressRequest) -> EgressInfo:
127+
"""Stops an active egress recording."""
112128
return await self._client.request(
113129
SVC,
114130
"StopEgress",

livekit-api/livekit/api/livekit_api.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,13 @@ def __init__(
5050
if not api_key or not api_secret:
5151
raise ValueError("api_key and api_secret must be set")
5252

53-
if not timeout:
54-
timeout = aiohttp.ClientTimeout(total=60)
55-
56-
self._custom_session = True if session is None else False
57-
self._session = session or aiohttp.ClientSession(timeout=timeout)
53+
self._custom_session = True
54+
self._session = session
55+
if not self._session:
56+
self._custom_session = False
57+
if not timeout:
58+
timeout = aiohttp.ClientTimeout(total=60)
59+
self._session = aiohttp.ClientSession(timeout=timeout)
5860

5961
self._room = RoomService(self._session, url, api_key, api_secret)
6062
self._ingress = IngressService(self._session, url, api_key, api_secret)

livekit-api/livekit/api/room_service.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
UpdateRoomMetadataRequest,
1919
RemoveParticipantResponse,
2020
UpdateSubscriptionsResponse,
21+
ForwardParticipantRequest,
22+
ForwardParticipantResponse,
2123
)
2224
from livekit.protocol.models import Room, ParticipantInfo
2325
from ._service import Service
@@ -197,6 +199,26 @@ async def remove_participant(
197199
RemoveParticipantResponse,
198200
)
199201

202+
async def forward_participant(self, forward: ForwardParticipantRequest) -> None:
203+
"""Forwards a participant and their published tracks from one room to another.
204+
205+
This feature is only available for LiveKit Cloud/Private Cloud.
206+
207+
Args:
208+
forward (ForwardParticipantRequest): arg containing:
209+
- room: str - Room name
210+
- identity: str - identity of Participant to forward
211+
- destination_room: str - Destination room name
212+
"""
213+
# currently nothing is returned
214+
await self._client.request(
215+
SVC,
216+
"ForwardParticipant",
217+
forward,
218+
self._auth_header(VideoGrants(room_admin=True, room=forward.room)),
219+
ForwardParticipantResponse,
220+
)
221+
200222
async def mute_published_track(
201223
self,
202224
update: MuteRoomTrackRequest,

0 commit comments

Comments
 (0)