glamorous-oil-12326
12/14/2025, 9:33 PMtall-airline-16756
12/14/2025, 9:33 PMtall-airline-16756
12/14/2025, 9:33 PMTransferSIPParticipant call completes, immediately call StopEgress with the egress ID:
• JavaScript: await egressClient.stopEgress(egressId);
• Go: egressClient.StopEgress(ctx, &livekit.StopEgressRequest{EgressId: egressID})
• CLI: lk egress stop --id <egress_id>
a. This stops the egress immediately regardless of room/participant state.
• Stop egress when a client leaves
a. Enable webhooks and listen for participant_left (or room_finished for room-level egress).
b. In your webhook handler, detect if the left participant is tied to the egress and call StopEgress with that egress ID.
Recommended best practice: delete the room when the call ends (if possible) — that will cause the egress participant to leave and stop recording. If you can’t delete the room, use the webhook + StopEgress flow to guarantee immediate stop.
Would you like the exact webhook payload example or a code sample for your language (JS/Go/Ruby) to plug into your handler?
Sources: Call forwarding | LiveKit docs | Egress API | LiveKit docs | Webhooks | LiveKit docsglamorous-oil-12326
12/14/2025, 9:34 PMtall-airline-16756
12/14/2025, 9:34 PMTransferSIPParticipant completes, call StopEgress with the egress ID.
Example (Python, synchronous style):
from livekit import EgressServiceStub, StopEgressRequest
import grpc
def stop_egress(egress_id, channel):
client = EgressServiceStub(channel)
req = StopEgressRequest(egress_id=egress_id)
client.StopEgress(req)
Call stop_egress(egress_id, channel) immediately after your transfer call returns.
Option B — Stop egress when participant leaves (webhook / agent event)
1. Use the agent framework to handle participant leave events or room finished events.
2. When you detect the participant tied to an egress has left, call StopEgress.
Example (agent event handler):
from livekit import EgressServiceStub, StopEgressRequest
import grpc
def on_participant_left(event, channel):
# event should include participant identity and any metadata you set linking to egress_id
egress_id = event.metadata.get("egress_id") # adapt to how you track it
if not egress_id:
return
client = EgressServiceStub(channel)
req = StopEgressRequest(egress_id=egress_id)
client.StopEgress(req)
Notes and tips
• You must track which egress_id corresponds to which participant/session (store in participant metadata, a DB, or in-memory map) so the handler can look it up.
• StopEgress stops immediately regardless of room state.
• If you create egress from the agent, capture and persist the returned egress_id when starting the egress so you can stop it later.
If you want, tell me:
• how you start egress in your agent (RoomComposite/TrackComposite/custom), and
• how you currently track egress IDs
—I can provide a tailored code snippet showing where to store the egress_id and how to wire it into your agent event handlers.