can we make the egress start by default when room ...
# ask-ai
n
can we make the egress start by default when room starts? like can i just specify this in the token itself?
t
Thanks for reaching out, Hari. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I’m happy to help you with this! Egress can be set up to start automatically when a room begins, although this option isn’t something you can specify directly in the token. Instead, you can configure auto egress during the room creation by using the
egress
field in the
CreateRoom
API. This way, you can choose to automatically record the room as a composite or capture each published track separately. If you’d like, I’m here to walk you through the details or answer any questions you might have! Sources: Auto egress | LiveKit Docs | SIP Integration & Telephony | livekit/livekit_composite | DeepWiki | How to enable auto-egress with SIP | rpc/egress.pb.go
n
can you provide an example?
t
I'd love to help you with configuring auto egress during room creation using the
CreateRoom
API. Here's a friendly example to guide you through it:
Copy code
import { RoomServiceClient } from 'livekit-server-sdk';

const roomService = new RoomServiceClient(
  <BASE_API_URL>,
  'your-api-key',
  'your-api-secret'
);

// Complete auto egress configuration
await roomService.createRoom({
  name: 'my-room',
  egress: {
    // Room composite recording - records entire room
    room: {
      fileOutputs: [{
        fileType: 'MP4',
        filepath: '/recordings/room-{room_name}-{time}.mp4'
      }],
      streamOutputs: [{
        protocol: 'RTMP',
        urls: ['rtmp://your-streaming-server/live/stream-key']
      }]
    },
    
    // Auto track recording - records each published track
    tracks: {
      fileOutputs: [{
        fileType: 'MP4',
        filepath: '/recordings/tracks/{room_name}/{track_id}-{time}.mp4'
      }]
    },
    
    // Auto participant recording - records each participant
    participant: {
      fileOutputs: [{
        fileType: 'MP4',
        filepath: '/recordings/participants/{room_name}/{participant_identity}-{time}.mp4'
      }]
    }
  }
});
This example covers how to set up auto egress for room composite recording, auto track recording, and auto participant recording. If anything feels unclear or if you'd like me to walk you through more examples, please don't hesitate to ask—I'm here to help! Sources: livekit/livekit_room.pb.go | packages/livekit-server-sdk/src/RoomServiceClient.ts | livekit-protocol/src/livekit.rs | lib/livekit/room_service_client.rb | livekit-protocol/livekit/protocol/room.pyi
n
room_config = api.RoomConfiguration(agents=[api.RoomAgentDispatch(agent_name=room_details.agent_name, metadata=json_utils.dumps(room_details.room_metadata))], departure_timeout=room_details.departure_timeout_in_seconds) token.with_room_config(room_config) cant i do something here?
t
Absolutely, you can configure egress using
RoomConfiguration
along with the
with_room_config
method. The
RoomConfiguration
object has an
egress
field where you can set up auto-egress options. These settings will take effect as soon as the room is created. Here’s a friendly example in Python:
Copy code
token = (
    api.AccessToken()
    .with_identity("my_participant")
    .with_grants(api.VideoGrants(room_join=True, room=room_name))
    .with_room_config(
        api.RoomConfiguration(
            agents=[api.RoomAgentDispatch(agent_name="test-agent", metadata="my_metadata")],
            egress=api.RoomEgress(
                room=api.RoomCompositeEgressRequest(
                    file_outputs=[
                        api.EncodedFileOutput(
                            file_type=api.EncodedFileType.MP4,
                            filepath="/recordings/room-{room_name}-{time}.mp4"
                        )
                    ]
                )
            )
        )
    )
    .to_jwt()
)
This way, you can seamlessly include egress settings right in the token, making it easy to start recording or streaming automatically when the room begins. If you’d like, I’m here to help with more details or other examples—just let me know! Sources: SIP Integration & Telephony | livekit/livekit_composite | DeepWiki | livekit-protocol/src/livekit.rs | src/test/kotlin/io/livekit/server/AccessTokenTest.kt | examples/agent_dispatch.py