feat: Enhance socket reconnection and chat screen lifecycle management, and refine agent detail and home screen UI.
This commit is contained in:
@@ -68,9 +68,9 @@ class SocketService {
|
||||
.setAuth({'token': token})
|
||||
.disableAutoConnect()
|
||||
.enableReconnection()
|
||||
.setReconnectionAttempts(5)
|
||||
.setReconnectionAttempts(double.maxFinite.toInt())
|
||||
.setReconnectionDelay(1000)
|
||||
.setReconnectionDelayMax(5000)
|
||||
.setReconnectionDelayMax(10000)
|
||||
.build(),
|
||||
);
|
||||
|
||||
@@ -97,6 +97,18 @@ class SocketService {
|
||||
_connectionController.add(false);
|
||||
});
|
||||
|
||||
_socket!.onReconnect((_) {
|
||||
_log.i('Socket reconnected successfully');
|
||||
});
|
||||
|
||||
_socket!.onReconnectAttempt((attempt) {
|
||||
_log.w('Socket reconnection attempt #$attempt');
|
||||
});
|
||||
|
||||
_socket!.onReconnectError((error) {
|
||||
_log.e('Socket reconnection error: $error');
|
||||
});
|
||||
|
||||
// Listen for events
|
||||
_socket!.on('new_message', (data) {
|
||||
try {
|
||||
@@ -172,6 +184,12 @@ class SocketService {
|
||||
_socket?.connect();
|
||||
}
|
||||
|
||||
/// Ensure socket is connected — reconnect if needed.
|
||||
Future<void> ensureConnected() async {
|
||||
if (_socket?.connected == true) return;
|
||||
await connect();
|
||||
}
|
||||
|
||||
void disconnect() {
|
||||
_intentionalDisconnect = true;
|
||||
_socket?.disconnect();
|
||||
|
||||
Reference in New Issue
Block a user