@@ -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/own_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/db/chat_persistence_client.dart';
|
||||
import 'package:stream_chat/src/event_type.dart';
|
||||
@@ -43,6 +44,10 @@ final _levelEmojiMapper = {
|
||||
Level.SEVERE: '🚨',
|
||||
};
|
||||
|
||||
final _userAgent = 'stream-chat-dart-client-'
|
||||
'${CurrentPlatform.name}-'
|
||||
'${PACKAGE_VERSION.split('+')[0]}';
|
||||
|
||||
/// The official Dart client for Stream Chat,
|
||||
/// a service for building chat applications.
|
||||
/// This library can be used on any Dart project and on both mobile and web apps
|
||||
@@ -81,9 +86,7 @@ class StreamChatClient {
|
||||
location: location,
|
||||
connectTimeout: connectTimeout,
|
||||
receiveTimeout: receiveTimeout,
|
||||
headers: {
|
||||
'X-Stream-Client': userAgent,
|
||||
},
|
||||
headers: {'X-Stream-Client': _userAgent},
|
||||
);
|
||||
|
||||
_chatApi = chatApi ??
|
||||
@@ -103,9 +106,7 @@ class StreamChatClient {
|
||||
tokenManager: _tokenManager,
|
||||
handler: handleEvent,
|
||||
logger: detachedLogger('🔌'),
|
||||
queryParams: {
|
||||
'X-Stream-Client': userAgent,
|
||||
},
|
||||
queryParameters: {'X-Stream-Client': _userAgent},
|
||||
);
|
||||
|
||||
_retryPolicy = retryPolicy ??
|
||||
|
||||
@@ -33,7 +33,7 @@ class StreamHttpClient {
|
||||
..options.connectTimeout = _options.connectTimeout.inMilliseconds
|
||||
..options.queryParameters = {
|
||||
'api_key': apiKey,
|
||||
..._options.queryParams,
|
||||
..._options.queryParameters,
|
||||
}
|
||||
..options.headers = {
|
||||
'Content-Type': 'application/json',
|
||||
|
||||
@@ -10,7 +10,7 @@ class StreamHttpClientOptions {
|
||||
this.location,
|
||||
this.connectTimeout = const Duration(seconds: 6),
|
||||
this.receiveTimeout = const Duration(seconds: 6),
|
||||
this.queryParams = const {},
|
||||
this.queryParameters = const {},
|
||||
this.headers = const {},
|
||||
}) : _baseUrl = baseUrl ?? _defaultBaseURL;
|
||||
|
||||
@@ -40,7 +40,7 @@ class StreamHttpClientOptions {
|
||||
///
|
||||
/// The value can be overridden per parameter by adding a [MultiParam]
|
||||
/// object wrapping the actual List value and the desired format.
|
||||
final Map<String, Object?> queryParams;
|
||||
final Map<String, Object?> queryParameters;
|
||||
|
||||
/// Http request headers.
|
||||
/// The keys of initial headers will be converted to lowercase,
|
||||
|
||||
@@ -41,14 +41,14 @@ class WebSocket with TimerHelper {
|
||||
this.reconnectionMonitorInterval = 10,
|
||||
this.healthCheckInterval = 20,
|
||||
this.reconnectionMonitorTimeout = 40,
|
||||
this.queryParams = const {},
|
||||
this.queryParameters = const {},
|
||||
}) : _logger = logger;
|
||||
|
||||
///
|
||||
final String apiKey;
|
||||
|
||||
/// Additional query parameters to be added to the websocket url
|
||||
final Map<String, Object?> queryParams;
|
||||
final Map<String, Object?> queryParameters;
|
||||
|
||||
/// WS base url
|
||||
final String baseUrl;
|
||||
@@ -160,7 +160,7 @@ class WebSocket with TimerHelper {
|
||||
'api_key': apiKey,
|
||||
'authorization': token.rawValue,
|
||||
'stream-auth-type': token.authType.raw,
|
||||
...queryParams,
|
||||
...queryParameters,
|
||||
};
|
||||
final scheme = baseUrl.startsWith('https') ? 'wss' : 'ws';
|
||||
final host = baseUrl.replaceAll(RegExp(r'(^\w+:|^)\/\/'), '');
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
import 'package:stream_chat/src/client/client.dart';
|
||||
import 'package:stream_chat/src/core/platform_detector/platform_detector.dart';
|
||||
|
||||
/// Current package version
|
||||
/// Used in [StreamChatClient] to build the `x-stream-client` header
|
||||
// ignore: constant_identifier_names
|
||||
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.connectTimeout, const Duration(seconds: 6));
|
||||
expect(options.receiveTimeout, const Duration(seconds: 6));
|
||||
expect(options.queryParams, const {});
|
||||
expect(options.queryParameters, const {});
|
||||
expect(options.headers, const {});
|
||||
});
|
||||
|
||||
@@ -18,19 +18,15 @@ void main() {
|
||||
baseUrl: 'base-url',
|
||||
connectTimeout: Duration(seconds: 3),
|
||||
receiveTimeout: Duration(seconds: 3),
|
||||
headers: {
|
||||
'test': 'test',
|
||||
},
|
||||
queryParams: {
|
||||
'123': '123',
|
||||
},
|
||||
headers: {'test': 'test'},
|
||||
queryParameters: {'123': '123'},
|
||||
);
|
||||
expect(options.location, isNull);
|
||||
expect(options.baseUrl, 'base-url');
|
||||
expect(options.connectTimeout, const Duration(seconds: 3));
|
||||
expect(options.receiveTimeout, const Duration(seconds: 3));
|
||||
expect(options.headers, {'test': 'test'});
|
||||
expect(options.queryParams, {'123': '123'});
|
||||
expect(options.queryParameters, {'123': '123'});
|
||||
});
|
||||
|
||||
group('should create baseUrl according to provided location', () {
|
||||
|
||||
Reference in New Issue
Block a user