@@ -263,6 +263,12 @@ class WebSocket with TimerHelper {
263
263
setTimer (
264
264
Duration (milliseconds: delay),
265
265
() async {
266
+ // If the user is null, it means either the connection was never
267
+ // established or it was disconnected manually.
268
+ //
269
+ // In either case, we should not attempt to reconnect.
270
+ if (_user == null ) return ;
271
+
266
272
final uri = await _buildUri (
267
273
refreshToken: refreshToken,
268
274
includeUserDetails: false ,
@@ -475,21 +481,18 @@ class WebSocket with TimerHelper {
475
481
/// Disconnects the WS and releases eventual resources
476
482
void disconnect () {
477
483
if (connectionStatus == ConnectionStatus .disconnected) return ;
478
-
479
- _resetRequestFlags (resetAttempts: true );
480
-
481
484
_connectionStatus = ConnectionStatus .disconnected;
482
485
483
486
_logger? .info ('Disconnecting web-socket connection' );
484
487
488
+ _manuallyClosed = true ;
489
+ _resetRequestFlags (resetAttempts: true );
490
+ _stopMonitoringEvents ();
491
+
485
492
// resetting user
486
493
_user = null ;
487
494
connectionCompleter = null ;
488
495
489
- _stopMonitoringEvents ();
490
-
491
- _manuallyClosed = true ;
492
-
493
496
_closeWebSocketChannel ();
494
497
}
495
498
}
0 commit comments