@@ -29,9 +29,7 @@ class ConnectionCubit extends Cubit<ConnectionState> {
29
29
30
30
_api = Injector ()< BaseAPI > ();
31
31
32
- _connectionInformation = connectionInformation;
33
-
34
- _connect (_connectionInformation);
32
+ connect (_connectionInformation = connectionInformation);
35
33
}
36
34
37
35
final String _key = '${UniqueKey ()}' ;
@@ -60,27 +58,25 @@ class ConnectionCubit extends Cubit<ConnectionState> {
60
58
/// Gets app id of websocket.
61
59
static String get appId => _connectionInformation.appId;
62
60
63
- /// Reconnect to Websocket with new [connectionInformation] .
64
- Future <void > reconnect ({ConnectionInformation ? connectionInformation}) async {
65
- if (connectionInformation != null ) {
66
- _connectionInformation = connectionInformation;
67
- }
68
-
69
- await _connect (_connectionInformation);
70
- }
61
+ /// Connect to Websocket with new [connectionInformation] .
62
+ Future <void > connect ([ConnectionInformation ? connectionInformation]) async {
63
+ try {
64
+ if (connectionInformation != null ) {
65
+ _connectionInformation = connectionInformation;
66
+ }
71
67
72
- Future <void > _connect (ConnectionInformation connectionInformation) async {
73
- if (state is ConnectionConnectingState ) {
74
- return ;
75
- }
68
+ await _api! .disconnect ();
76
69
77
- await _api! .connect (
78
- _connectionInformation,
79
- printResponse: enableDebug && printResponse,
80
- onError: (String error) => emit (ConnectionErrorState (error)),
81
- );
70
+ await _api! .connect (
71
+ _connectionInformation,
72
+ printResponse: enableDebug && printResponse,
73
+ onError: (String error) => emit (ConnectionErrorState (error)),
74
+ );
82
75
83
- _handleConnectionStatus ();
76
+ _handleConnectionStatus ();
77
+ } on Exception catch (e) {
78
+ emit (ConnectionErrorState ('$e ' ));
79
+ }
84
80
}
85
81
86
82
void _handleConnectionStatus () {
0 commit comments