In my livekit app if there is disconnection due to...
# ask-ai
n
In my livekit app if there is disconnection due to internet Once the internet comes back the app logs out itself instead of reconnecting
✅ 1
t
Thanks for reaching out, Rishabh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m sorry you’re hitting that. I’m responding about the app logging out after an internet drop rather than reconnecting. A few quick questions so I can pinpoint the cause: • Which LiveKit SDK are you using (Web/JS, Flutter, iOS, Android, React Native)? • Do you see any SDK events or errors when the connection is lost/recovered (e.g.,
reconnecting
,
reconnected
,
disconnected
, or a disconnect reason like
STATE_MISMATCH
)? • Does your app call any cleanup or
disconnect()
logic when network changes occur (for example in a network change handler or background/foreground lifecycle event)? • Is this happening every time the network drops or only in certain scenarios (short blips vs long outages)? What to check while I wait: • Ensure your app listens for the SDK’s reconnection events (for example
reconnecting
/
reconnected
) and does not call
disconnect()
or trigger logout on transient
reconnecting
events. • Confirm you’re not treating temporary network loss as a final
disconnected
state in your app logic; only perform full logout/cleanup when you receive the SDK’s confirmed
disconnected
event or a persistent failure. Send the SDK name, any logs/events you see around the disconnect, and a short snippet of the code that handles connection state changes. I’ll then tell you the exact changes to keep sessions connected. Sources: How we built a globally distributed mesh network to scale WebRTC | LiveKit | client-sdk-js | livekit/livekit_composite | DeepWiki | Understanding the STATE_MISMATCH Disconnect Reason | client-sdk-flutter | livekit/livekit_composite | DeepWiki, with interactive elements
n
I am using flutter sdk version 2.7
t
Thanks — helpful detail. I’ll focus on Flutter SDK 2.7 and the reconnection flow. Please share the following so I can diagnose precisely: • The code snippet that handles Room events / connection state (where you listen for
RoomEvent.*
) and any network-change or app-lifecycle handlers. • SDK logs around a disconnect/reconnect attempt (the lines showing
reconnecting
,
reconnected
,
disconnected
, or any error/reason). • Whether your app calls
room.disconnect()
(or performs logout/cleanup) on network change, backgrounding, or a timeout—and where that logic lives. In the meantime, check these common causes and quick fixes: • Ensure you handle
RoomEvent.reconnecting
and do NOT call logout/`disconnect()` when
reconnecting
fires. Only run full cleanup on
RoomEvent.disconnected
. • Avoid treating brief network blips as permanent: add a short grace period before triggering logout/cleanup so the SDK can recover. • If you have a network-change listener, don’t force disconnect there; instead show a “reconnecting” UI and wait for
reconnected
or
disconnected
. • Share the disconnect reason from logs if you see
STATE_MISMATCH
or `PEER_CONNECTION_DISCONNECT`—that helps determine if server-side cleanup or unclean disconnects are occurring. Send the code and logs and I’ll give exact changes for your handlers. , with interactive elements