wide-dress-57902
08/11/2025, 11:26 PMtall-airline-16756
08/11/2025, 11:26 PMtall-airline-16756
08/11/2025, 11:26 PMphone_number
is None
. If it is, that means it’s an inbound call, so the agent can speak first. Otherwise, wait for the user’s input before the agent responds.
3. Keep an Eye on Connection States: Use the LiveKit SDK to track the user’s connection status. States like disconnected
, connecting
, and connected
help you know exactly when the user is ready.
4. Manage Agent State Events: Use events like listening
and speaking
to coordinate the conversation. The agent should only start speaking
once the user is fully connected.
Here’s a quick example to illustrate:
# Check if the call is inbound or outbound
if phone_number is None:
# Inbound call: agent can start speaking
await session.generate_reply(
instructions="Greet the user and offer your assistance."
)
else:
# Outbound call: wait for user to speak first
pass # Agent will respond after user's turn
On the frontend side, you can use LiveKit’s client SDK to listen for connection events. Once the user’s state switches to connected
, the agent can move forward if it’s an inbound call. Don’t forget to update the UI to show the agent’s readiness and the user’s connection status—this way, everything feels smooth and clear for both sides.wide-dress-57902
08/11/2025, 11:29 PMtall-airline-16756
08/11/2025, 11:29 PMJOINING
to JOINED
and finally to ACTIVE
, with media transport established and data channels open.
Here are some friendly ways to check if someone is connected:
1. Use Connection State Enums: LiveKit SDKs have handy enums like connected
, disconnected
, and reconnecting
. For example, in Swift:
switch room.connectionState {
case .connected:
print("Participant is fully connected.")
case .disconnected:
print("Participant is disconnected.")
default:
print("Participant is in another state.")
}
1. Listen to Connection Events: The SDKs will let you know when the connection state changes. For example, in JavaScript:
room.on(RoomEvent.Connected, () => {
console.log("Participant is fully connected.");
});
1. Keep an Eye on Participant State Transitions: You can check the participant’s state to see if they’re fully connected. For example, in Swift:
participant.state // Returns ParticipantState.active when fully connected
By keeping track of these states and events, you’ll know when a participant is fully connected and ready to jump into the room. If you want me to walk you through more examples or details for a specific SDK, just let me know—I’m here to help!
Sources: src/room/Room.ts | LiveKit Server Components | livekit/livekit_composite | DeepWiki | Sources/LiveKit/Core/Room+EngineDelegate.swift