@@ -21,7 +21,7 @@ const forcedReconnectionRequested = 4002;
21
21
/// necessary.
22
22
class SocketConnectionManager {
23
23
SocketConnectionManager ({
24
- required Future < WebSocketChannel > Function () factory ,
24
+ required WebSocketChannelFactory factory ,
25
25
required List <Duration > reconnectDelays,
26
26
required void Function (String ) onMessage,
27
27
required void Function (WebSocketConnectionState ) onStateChange,
@@ -51,9 +51,11 @@ class SocketConnectionManager {
51
51
52
52
bool _disposed = false ;
53
53
54
- /// Requests to start connecting to the socket. Returns a future
54
+ /// Requests to start connecting to the socket. Returns a future that
55
+ /// completes when a WebSocket connection has been established.
55
56
///
56
- /// Has no effect if the connection is already established.
57
+ /// If [immediately] is false, and a connection is already established, then
58
+ /// this method does not have any effect.
57
59
///
58
60
/// If [immediately] is set to true, then an attempt to connect is made
59
61
/// immediately. This might result in dropping the current connection and
@@ -84,16 +86,26 @@ class SocketConnectionManager {
84
86
/// Sends a message to the socket. Will start connecting to the socket if
85
87
/// necessary.
86
88
///
87
- /// Returns a future that completes when the message is successfully added to
88
- /// the socket .
89
+ /// Returns a future that completes when the message is successfully passed to
90
+ /// an established WebSocket .
89
91
///
90
- /// If after call to [addMessage] a call to [dispose] or [stop] is made, then
91
- /// this future will complete with an error instead.
92
+ /// The future will complete with error if the message couldn't be added to
93
+ /// a WebSocket, either because this connection manager was disposed, or the
94
+ /// WebSocket could not accept messages.
92
95
Future <void > addMessage (String message) async {
93
96
final connection = await _maybeConnect ();
94
97
return connection.send (message);
95
98
}
96
99
100
+ /// Forces reconnection to the WebSocket. Returns a future that completes when
101
+ /// a WebSocket connection has been established.
102
+ ///
103
+ /// If a connection was already established, it gets closed with the provided
104
+ /// code and optional reason.
105
+ ///
106
+ /// If [immediately] is true, then the new connection attempt is executed
107
+ /// immediately, irrespective of ordinary reconnection delays provided to the
108
+ /// constructor.
97
109
Future <void > reconnect (int code, {String ? reason, bool immediately = false }) {
98
110
final currentConnection = _connectionsStream.valueOrNull;
99
111
final connectFuture = _connect ();
0 commit comments