polite-oil-10264
08/02/2025, 5:05 AMtall-airline-16756
08/02/2025, 5:05 AMtall-airline-16756
08/02/2025, 5:06 AMRoomCompositeEgressRequest with the desired parameters (e.g., room name, layout, and storage configuration). Additionally, ensure that the room is closed when the last participant leaves by calling room.Close().
If you need further assistance with the setup or code examples, let me know!polite-oil-10264
08/02/2025, 5:07 AMtall-airline-16756
08/02/2025, 5:07 AMimport os
from livekit import api
async def entrypoint(ctx):
# Set up RoomComposite recording
req = api.RoomCompositeEgressRequest(
room_name="my-room",
layout="speaker", # Choose layout (e.g., "speaker", "grid")
preset=api.EncodingOptionsPreset.H264_720P_30, # Video encoding preset
audio_only=False, # Set to True if you only need audio
segment_outputs=[
api.SegmentedFileOutput(
filename_prefix="my-output",
playlist_name="my-playlist.m3u8",
live_playlist_name="my-live-playlist.m3u8",
segment_duration=5, # Duration of each segment in seconds
gcp=api.GCPUpload(
bucket="my-bucket", # Your Google Cloud Storage bucket
credentials="path/to/credentials.json", # Path to GCP credentials
),
)
],
)
# Initialize LiveKit API
lkapi = api.LiveKitAPI()
# Start RoomComposite recording
res = await lkapi.egress.start_room_composite_egress(req)
# Listen for participant disconnections
async def on_participant_disconnected(participant):
# Check if this is the last participant
if len(ctx.room.GetParticipants()) == 1:
# Close the room to stop recording
await ctx.room.CloseIfEmpty()
ctx.room.on("participant_disconnected", on_participant_disconnected)
# Start the agent's logic here
# ...
Here’s a quick rundown:
• RoomCompositeEgressRequest: This sets up the recording with your room name, layout, and where you want to save it.
• Event Listener: Keeps an eye on when participants leave and closes the room to stop recording if it’s empty.
• Storage: This example uses Google Cloud Storage, but feel free to swap it out for Amazon S3 or Azure Blob Storage if that’s what you prefer.
If anything’s unclear or you want me to tailor this example to your specific needs, just let me know—I’m happy to help!polite-oil-10264
08/02/2025, 5:08 AMtall-airline-16756
08/02/2025, 5:09 AMasync def on_participant_disconnected(participant):
# Check if only the agent remains in the room
non_agent_participants = [p for p in ctx.room.GetParticipants() if p.role != "agent"]
if len(non_agent_participants) == 0:
# Close the room to stop recording
await ctx.room.CloseIfEmpty()
ctx.room.on("participant_disconnected", on_participant_disconnected)
This way, the room will close and the recording will stop as soon as all the non-agent participants have left, even if the agent is still there.
If you want, I’m happy to help you set this up or explain it further—just let me know!polite-oil-10264
08/03/2025, 2:23 AMtall-airline-16756
08/03/2025, 2:24 AMRoom object doesn’t have a method called GetParticipants. No worries though! You can use the listParticipants method from the RoomServiceClient to get the list of participants in a room. Here’s a simple example in Python to help you out: