melodic-zoo-29246
09/04/2025, 5:08 AMasync def entrypoint(ctx: JobContext):
async def write_transcript():
participant = ctx.room.local_participant
user_id = participant.metadata
room_id = ctx.room.name
ctx.add_shutdown_callback(write_transcript)
await ctx.connect()tall-airline-16756
09/04/2025, 5:08 AMtall-airline-16756
09/04/2025, 5:09 AMadd_shutdown_callback() method, you'll want to make sure you’ve already got a reference to the participant saved earlier in your job’s lifecycle. Here’s a friendly step-by-step on how to do that:
Steps:
1. Use ctx.wait_for_participant() to wait for someone to join and get their metadata. This way, you have their info before the shutdown callback kicks in.
2. Save the participant’s metadata or identity in a variable or some structure you can easily access later inside the shutdown callback.
3. Then, inside the add_shutdown_callback() method, just pull that stored metadata or refresh it from ctx.room.remote_participants if you need to.
Here’s a little example to make it clearer:
async def entrypoint(ctx: JobContext):
# Wait for the first participant to join
participant = await ctx.wait_for_participant()
# Store participant metadata
participant_data = {
"identity": participant.identity,
"metadata": participant.metadata
}
# Define shutdown callback
async def shutdown_callback(reason: str):
print(f"Shutting down: {reason}")
print(f"Metadata for {participant_data['identity']}: {participant_data['metadata']}")
# Register the shutdown callback
ctx.add_shutdown_callback(shutdown_callback)
# Connect to the room
await ctx.connect()
This way, you’ll have the participant’s metadata handy when the shutdown happens. If anything’s unclear or you want to dive deeper, just give me a shout—I’m here to help!
Sources: Participant attributes and metadata | LiveKit Docs | livekit-rtc/livekit/rtc/_proto/room_pb2.pyi | livekit-agents/livekit/agents/job.pymelodic-zoo-29246
09/04/2025, 5:14 AMtall-airline-16756
09/04/2025, 5:14 AMRuntimeError: room is not connected pops up because wait_for_participant is being called before the room actually connects to the LiveKit server. To fix this, just make sure you connect the room first by calling await ctx.connect() before using ctx.wait_for_participant(). Easy fix!
Here’s how the sequence should look:
async def entrypoint(ctx: JobContext):\n # Connect to the room first\n await ctx.connect()\n\n # Now wait for a participant to join\n participant = await ctx.wait_for_participant()\n\n # Store participant metadata\n participant_data = {\n \"identity\": participant.identity,\n \"metadata\": participant.metadata\n }\n\n # Define shutdown callback\n async def shutdown_callback(reason: str):\n print(f\"Shutting down: {reason}\")\n print(f\"Metadata for {participant_data['identity']}: {participant_data['metadata']}\")\n\n # Register the shutdown callback\n ctx.add_shutdown_callback(shutdown_callback)
By connecting the room first, you’ll sidestep this error for sure. If you have any other questions or need a hand, just let me know—I’m here to help!
Sources: livekit-rtc/livekit/rtc/room.py | livekit-agents/livekit/agents/voice/avatar/_datastream_io.py | Inside a session | LiveKit Docs