victorious-midnight-79553
10/22/2025, 9:27 AMtall-airline-16756
10/22/2025, 9:27 AMtall-airline-16756
10/22/2025, 9:28 AMDisconnected event from the Room class is a great way to catch disconnections. You can listen for this event like so:
room.events.listen((event) {
if (event is RoomDisconnectedEvent) {
// Handle disconnection
print('Disconnected from room: ${event.reason}');
// Update UI or perform cleanup
}
});
• Monitor Connection State: Another way is to keep an eye on the room's connection state directly and respond to any changes:
// Check current connection state
ConnectionState currentState = room.connectionState;
// Listen for connection state changes
room.events.listen((event) {
if (event is RoomConnectionStateChangedEvent) {
if (event.connectionState == ConnectionState.disconnected) {
// Handle disconnection
print('Connection state changed to disconnected');
}
}
});
• Using ChangeNotifier Pattern: Since Room extends DisposableChangeNotifier, you can also use Flutter’s familiar pattern to listen for changes:
room.addListener(() {
if (room.connectionState == ConnectionState.disconnected) {
// Handle disconnection
}
});
These methods should help you detect disconnections quickly and manage them smoothly in your app. If you have any questions or need further assistance, feel free to ask—I'm here to help!
Sources: Handling events | LiveKit Docs | lib/src/core/room.dart | Connecting to LiveKit | LiveKit Docsvictorious-midnight-79553
10/22/2025, 10:19 AM