chore(llc): minor changes

Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
Sahil Kumar
2021-07-23 14:53:43 +05:30
committed by xsahil03x
parent 49ebb1e085
commit 44b4358c3d
6 changed files with 17 additions and 26 deletions
@@ -25,6 +25,7 @@ import 'package:stream_chat/src/core/models/member.dart';
import 'package:stream_chat/src/core/models/message.dart'; import 'package:stream_chat/src/core/models/message.dart';
import 'package:stream_chat/src/core/models/own_user.dart'; import 'package:stream_chat/src/core/models/own_user.dart';
import 'package:stream_chat/src/core/models/user.dart'; import 'package:stream_chat/src/core/models/user.dart';
import 'package:stream_chat/src/core/platform_detector/platform_detector.dart';
import 'package:stream_chat/src/core/util/utils.dart'; import 'package:stream_chat/src/core/util/utils.dart';
import 'package:stream_chat/src/db/chat_persistence_client.dart'; import 'package:stream_chat/src/db/chat_persistence_client.dart';
import 'package:stream_chat/src/event_type.dart'; import 'package:stream_chat/src/event_type.dart';
@@ -43,6 +44,10 @@ final _levelEmojiMapper = {
Level.SEVERE: '🚨', Level.SEVERE: '🚨',
}; };
final _userAgent = 'stream-chat-dart-client-'
'${CurrentPlatform.name}-'
'${PACKAGE_VERSION.split('+')[0]}';
/// The official Dart client for Stream Chat, /// The official Dart client for Stream Chat,
/// a service for building chat applications. /// a service for building chat applications.
/// This library can be used on any Dart project and on both mobile and web apps /// This library can be used on any Dart project and on both mobile and web apps
@@ -81,9 +86,7 @@ class StreamChatClient {
location: location, location: location,
connectTimeout: connectTimeout, connectTimeout: connectTimeout,
receiveTimeout: receiveTimeout, receiveTimeout: receiveTimeout,
headers: { headers: {'X-Stream-Client': _userAgent},
'X-Stream-Client': userAgent,
},
); );
_chatApi = chatApi ?? _chatApi = chatApi ??
@@ -103,9 +106,7 @@ class StreamChatClient {
tokenManager: _tokenManager, tokenManager: _tokenManager,
handler: handleEvent, handler: handleEvent,
logger: detachedLogger('🔌'), logger: detachedLogger('🔌'),
queryParams: { queryParameters: {'X-Stream-Client': _userAgent},
'X-Stream-Client': userAgent,
},
); );
_retryPolicy = retryPolicy ?? _retryPolicy = retryPolicy ??
@@ -33,7 +33,7 @@ class StreamHttpClient {
..options.connectTimeout = _options.connectTimeout.inMilliseconds ..options.connectTimeout = _options.connectTimeout.inMilliseconds
..options.queryParameters = { ..options.queryParameters = {
'api_key': apiKey, 'api_key': apiKey,
..._options.queryParams, ..._options.queryParameters,
} }
..options.headers = { ..options.headers = {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@@ -10,7 +10,7 @@ class StreamHttpClientOptions {
this.location, this.location,
this.connectTimeout = const Duration(seconds: 6), this.connectTimeout = const Duration(seconds: 6),
this.receiveTimeout = const Duration(seconds: 6), this.receiveTimeout = const Duration(seconds: 6),
this.queryParams = const {}, this.queryParameters = const {},
this.headers = const {}, this.headers = const {},
}) : _baseUrl = baseUrl ?? _defaultBaseURL; }) : _baseUrl = baseUrl ?? _defaultBaseURL;
@@ -40,7 +40,7 @@ class StreamHttpClientOptions {
/// ///
/// The value can be overridden per parameter by adding a [MultiParam] /// The value can be overridden per parameter by adding a [MultiParam]
/// object wrapping the actual List value and the desired format. /// object wrapping the actual List value and the desired format.
final Map<String, Object?> queryParams; final Map<String, Object?> queryParameters;
/// Http request headers. /// Http request headers.
/// The keys of initial headers will be converted to lowercase, /// The keys of initial headers will be converted to lowercase,
@@ -41,14 +41,14 @@ class WebSocket with TimerHelper {
this.reconnectionMonitorInterval = 10, this.reconnectionMonitorInterval = 10,
this.healthCheckInterval = 20, this.healthCheckInterval = 20,
this.reconnectionMonitorTimeout = 40, this.reconnectionMonitorTimeout = 40,
this.queryParams = const {}, this.queryParameters = const {},
}) : _logger = logger; }) : _logger = logger;
/// ///
final String apiKey; final String apiKey;
/// Additional query parameters to be added to the websocket url /// Additional query parameters to be added to the websocket url
final Map<String, Object?> queryParams; final Map<String, Object?> queryParameters;
/// WS base url /// WS base url
final String baseUrl; final String baseUrl;
@@ -160,7 +160,7 @@ class WebSocket with TimerHelper {
'api_key': apiKey, 'api_key': apiKey,
'authorization': token.rawValue, 'authorization': token.rawValue,
'stream-auth-type': token.authType.raw, 'stream-auth-type': token.authType.raw,
...queryParams, ...queryParameters,
}; };
final scheme = baseUrl.startsWith('https') ? 'wss' : 'ws'; final scheme = baseUrl.startsWith('https') ? 'wss' : 'ws';
final host = baseUrl.replaceAll(RegExp(r'(^\w+:|^)\/\/'), ''); final host = baseUrl.replaceAll(RegExp(r'(^\w+:|^)\/\/'), '');
-6
View File
@@ -1,12 +1,6 @@
import 'package:stream_chat/src/client/client.dart'; import 'package:stream_chat/src/client/client.dart';
import 'package:stream_chat/src/core/platform_detector/platform_detector.dart';
/// Current package version /// Current package version
/// Used in [StreamChatClient] to build the `x-stream-client` header /// Used in [StreamChatClient] to build the `x-stream-client` header
// ignore: constant_identifier_names // ignore: constant_identifier_names
const PACKAGE_VERSION = '2.0.0'; const PACKAGE_VERSION = '2.0.0';
/// Get the current user agent
String get userAgent => 'stream-chat-dart-client-'
'${CurrentPlatform.name}-'
'${PACKAGE_VERSION.split('+')[0]}';
@@ -9,7 +9,7 @@ void main() {
expect(options.baseUrl, 'https://chat-us-east-1.stream-io-api.com'); expect(options.baseUrl, 'https://chat-us-east-1.stream-io-api.com');
expect(options.connectTimeout, const Duration(seconds: 6)); expect(options.connectTimeout, const Duration(seconds: 6));
expect(options.receiveTimeout, const Duration(seconds: 6)); expect(options.receiveTimeout, const Duration(seconds: 6));
expect(options.queryParams, const {}); expect(options.queryParameters, const {});
expect(options.headers, const {}); expect(options.headers, const {});
}); });
@@ -18,19 +18,15 @@ void main() {
baseUrl: 'base-url', baseUrl: 'base-url',
connectTimeout: Duration(seconds: 3), connectTimeout: Duration(seconds: 3),
receiveTimeout: Duration(seconds: 3), receiveTimeout: Duration(seconds: 3),
headers: { headers: {'test': 'test'},
'test': 'test', queryParameters: {'123': '123'},
},
queryParams: {
'123': '123',
},
); );
expect(options.location, isNull); expect(options.location, isNull);
expect(options.baseUrl, 'base-url'); expect(options.baseUrl, 'base-url');
expect(options.connectTimeout, const Duration(seconds: 3)); expect(options.connectTimeout, const Duration(seconds: 3));
expect(options.receiveTimeout, const Duration(seconds: 3)); expect(options.receiveTimeout, const Duration(seconds: 3));
expect(options.headers, {'test': 'test'}); expect(options.headers, {'test': 'test'});
expect(options.queryParams, {'123': '123'}); expect(options.queryParameters, {'123': '123'});
}); });
group('should create baseUrl according to provided location', () { group('should create baseUrl according to provided location', () {