Why is on_participant_connected event not being ca...
# ask-ai
a
Why is on_participant_connected event not being called? I am sure my participant is connected to the room.
t
Thanks for reaching out, Chirag. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m looking into why your
on_participant_connected
handler isn’t firing. A few common causes — please check and tell me which apply: • Did you register the
on_participant_connected
listener before connecting to the room (or before the other participant joined)? If the listener is added after the participant already joined, the event won’t fire for that join. • Is the room in Livestream Mode? In Livestream Mode, subscriber-only (viewer) participants do not trigger `on_participant_connected`; only publisher participants (those that publish a track or set metadata/attributes) do. • Is the participant actually publishing any tracks or setting metadata (i.e., a publisher)? If not, they may be treated as viewer/subscriber. • Are you seeing any errors in the client logs around connect or event registration? Any relevant log lines or SDK + version info will help. Please tell me: 1. Which SDK and version you’re using. 2. Whether you’re in Livestream Mode. 3. A short snippet showing where you add the listener and where you call
connect()
(or confirm the order). With that I can give exact, concrete steps to fix it. Sources: Job lifecycle | LiveKit docs | client-sdk-flutter | livekit/livekit_composite | DeepWiki | Livestream Mode
a
My participant has joined at [154809.445] [useVoiceChat] Connection established, mic activated and room joined My agent has joined at 2025-12-31 154810.863 | INFO | src.live_kit.entrypoint.realtime_entrypointlive voice assistant agent322 | PID:27902 | agent connected to room livekit==1.0.12 livekit-agents==1.2.6
t
Thanks — I see the timestamps and your SDK versions. Quick checklist and one small request to pinpoint the cause. Please confirm these two things: 1. Did you register the
on_participant_connected
listener before calling
connect()
(or before the other participant joined)? 2. Is the room running in Livestream Mode? If both are true, please paste the small code snippet that shows where you add the listener and where you call
connect()
(3–6 lines is enough). With that I’ll tell you the exact fix.
a
you mean the @ctx.room.on("participant_connected") should be called before calling ctx.connect?
t
Yes — register
@ctx.room.on("participant_connected")
before calling
ctx.connect()
(or before other participants may join). Event listeners only capture events that occur after they are registered. If you’re in Livestream Mode, note that subscriber-only viewers won’t trigger
participant_connected
— only publisher participants (those that publish a track or set metadata) will. Please paste 3–6 lines showing where you add the listener and where you call
ctx.connect()
if you want me to check the exact ordering.
a
Not using livestream mode
Copy code
class RealtimeEntrypoint():
    async def voice_agent(self, ctx: JobContext):
        await ctx.connect(auto_subscribe=AutoSubscribe.SUBSCRIBE_ALL)
        
        @ctx.room.on("participant_connected")
        def on_participant_connected(participant):
t
Thanks — I see your code snippet and that you’re not in Livestream Mode. You're correct: the listener must be registered before
ctx.connect()
. In your snippet the listener is added after
await ctx.connect(...)
, so it will miss participant join events that happen during or before connect. Please move the listener registration above the connect call, for example:
Copy code
@ctx.room.on("participant_connected")
def on_participant_connected(participant):
    ...
await ctx.connect(auto_subscribe=AutoSubscribe.SUBSCRIBE_ALL)
If you need to detect participants who are already in the room after connecting, fetch current participants after connect and handle them explicitly:
Copy code
for p in ctx.room.participants.values():
    on_participant_connected(p)
If you’d like, paste the updated snippet and I’ll review it.