Skip to content

Commit

Permalink
Add change connection data
Browse files Browse the repository at this point in the history
  • Loading branch information
Danil Abdrafikov committed Aug 30, 2024
1 parent daa40bc commit 6aba96e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ abstract class Client {
///
void setToken(String token);

/// Set allows updating connection data.
///
void setData(List<int> data);

/// Ready resolves when client successfully connected.
/// Throws exceptions if called not in connecting or connected state.
Future<void> ready();
Expand Down Expand Up @@ -197,6 +201,11 @@ class ClientImpl implements Client {
_token = token;
}

@override
void setData(List<int> data) {
_data = data;
}

@override
Future<void> disconnect() async {
_reconnectAttempts = 0;
Expand Down Expand Up @@ -463,8 +472,9 @@ class ClientImpl implements Client {
if (_token != '') {
request.token = _token;
}
if (_data != null) {
request.data = _data!;
final data = await _config.getData?.call() ?? _data;
if (data != null) {
request.data = data;
}
request.name = _config.name;
request.version = _config.version;
Expand Down
6 changes: 6 additions & 0 deletions lib/src/client_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ClientConfig {
this.token = '',
this.getToken,
this.data,
this.getData,
this.headers = const <String, dynamic>{},
this.tlsSkipVerify = false,
this.timeout = const Duration(seconds: 10),
Expand All @@ -32,6 +33,9 @@ class ClientConfig {
/// The data send for the first request
List<int>? data;

/// Callback to get/refresh connection data
final ConnectDataCallback? getData;

/// The connection timeout
final Duration timeout;

Expand All @@ -53,3 +57,5 @@ class ClientConfig {
}

typedef ConnectionTokenCallback = Future<String> Function(ConnectionTokenEvent);

typedef ConnectDataCallback = Future<List<int>>? Function();

0 comments on commit 6aba96e

Please sign in to comment.