Agent disconnected and closed but no event was fir...
# ask-ai
l
Agent disconnected and closed but no event was fired for server-sdk , events are already subscribed.
t
Thanks for reaching out, Piyush. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Could you please share a bit more about the issue you're experiencing? For instance, which specific event are you hoping to trigger, and under what circumstances? Also, it would be really helpful to know if you're using a particular version of the server SDK. This info will definitely help us get to the bottom of things together.
l
it should have triggered Participant disconnected event
t
I'm here to help you understand why the
OnParticipantDisconnected
event in the server SDK might not be firing as expected. There are a few common reasons this could happen: • Callback Not Properly Registered: It’s important to double-check that the
OnParticipantDisconnected
callback is explicitly set in the
RoomCallback
struct during initialization. Sometimes this step can be missed. • Participant Already Disconnected: If the participant object is missing or has already been cleaned up before the disconnect event fires, the callback might not get called. This can happen if the disconnect is processed elsewhere first. • Room Restart or Reconnection: When a room restarts, make sure your callback is still properly registered and survives any lifecycle changes. This ensures it continues to listen for events. • Incorrect Scope or Goroutine Handling: Since the callback runs within a goroutine, it’s good to verify there aren’t any race conditions or premature context cancellations that might interfere with the callback executing. • Client-Side Disconnection Without Signaling: If a participant disconnects abruptly without signaling (like a network drop), the server might delay or even miss the event. But don’t worry—automatic disconnection triggered by timeout should eventually call the event. To help you move forward, I recommend confirming that the callback is properly set and hasn’t been accidentally overridden. Also, take a look at your server logs to see if the event handler is being invoked. Finally, check your code to ensure nothing unregisters the callback after it’s set up. If you need any more guidance, I’m here to support you! Sources: room.go | lib/src/core/room.dart | Connecting to LiveKit | LiveKit Docs
l
fetch roomCallback how to do later on/ subscription status
t
RoomCallbacks in the LiveKit server SDK aren’t something you “fetch,” but rather you define and assign them to handle room events. Let me guide you through how you can set them up: 1. Start by initializing a
RoomCallback
using
lksdk.NewRoomCallback()
. 2. Then, assign event handler functions to the callback’s fields, like
OnParticipantConnected
or
OnParticipantDisconnected
. 3. Next, pass this callback to
lksdk.NewRoom()
when you create the room. 4. Finally, join the room using a token to begin receiving those events. Here’s a quick example to illustrate:
Copy code
cb := lksdk.NewRoomCallback()
cb.OnParticipantDisconnected = func(rp *lksdk.RemoteParticipant) {
    log.Printf("Participant disconnected: %s", rp.Identity())
}
room := lksdk.NewRoom(cb)
room.JoinWithToken("<wss://your-livekit-server>", "your-jwt-token")
If you’d like, I’m here to help with more examples or to walk you through specific callbacks—just let me know! Sources: livekit-rtc/livekit/rtc/room.py | Webhooks | LiveKit Docs | room.go | packages/livekit-server-sdk/README.md