HOW TO check from my frontend on when the agent ha...
# ask-ai
h
HOW TO check from my frontend on when the agent has joined the room
t
Thanks for reaching out, Ahmed. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! If you want to know right from your frontend when an agent joins the room in LiveKit, you can tap into the
participantConnected
event from LiveKit's Room API. Let me walk you through it: 1. Listen for the Participant Connected Event: Use the
room.on()
method to catch the
participantConnected
event. This fires every time someone new joins the room. 2. Spot if the Participant is an Agent: When this event happens, check the participant’s
kind
property. If it says
"AGENT"
, you’ve got yourself an agent joining. 3. Take Action When an Agent Joins: Once you know it’s an agent, you can update your UI, log the event, or trigger any other logic you need. Here’s a quick example in JavaScript to get you started:
Copy code
room.on('participantConnected', (participant) => {
  if (participant.kind === 'AGENT') {
    console.log('Agent has joined the room:', participant.identity);
    // Feel free to update your UI or handle the agent’s presence here
  }
});
This way, you’ll be in the loop right away when an agent joins, and your frontend can respond smoothly. Hope this helps!