StreamChatClient constructor
StreamChatClient(
- String apiKey, {
- Level logLevel = Level.WARNING,
- LogHandlerFunction logHandlerFunction = StreamChatClient.defaultLogHandler,
- RetryPolicy? retryPolicy,
- String? baseURL,
- Duration connectTimeout = const Duration(seconds: 6),
- Duration receiveTimeout = const Duration(seconds: 6),
- StreamChatApi? chatApi,
- WebSocket? ws,
- AttachmentFileUploaderProvider attachmentFileUploaderProvider = StreamAttachmentFileUploader.new,
- Iterable<
Interceptor> ? chatApiInterceptors,
Create a client instance with default options. You should only create the client once and re-use it across your application.
Implementation
StreamChatClient(
String apiKey, {
this.logLevel = Level.WARNING,
this.logHandlerFunction = StreamChatClient.defaultLogHandler,
RetryPolicy? retryPolicy,
String? baseURL,
Duration connectTimeout = const Duration(seconds: 6),
Duration receiveTimeout = const Duration(seconds: 6),
StreamChatApi? chatApi,
WebSocket? ws,
AttachmentFileUploaderProvider attachmentFileUploaderProvider =
StreamAttachmentFileUploader.new,
Iterable<Interceptor>? chatApiInterceptors,
}) {
logger.info('Initiating new StreamChatClient');
final options = StreamHttpClientOptions(
baseUrl: baseURL,
connectTimeout: connectTimeout,
receiveTimeout: receiveTimeout,
headers: {'X-Stream-Client': defaultUserAgent},
);
_chatApi = chatApi ??
StreamChatApi(
apiKey,
options: options,
tokenManager: _tokenManager,
connectionIdManager: _connectionIdManager,
attachmentFileUploaderProvider: attachmentFileUploaderProvider,
logger: detachedLogger('πΈοΈ'),
interceptors: chatApiInterceptors,
);
_ws = ws ??
WebSocket(
apiKey: apiKey,
baseUrl: options.baseUrl,
tokenManager: _tokenManager,
handler: handleEvent,
logger: detachedLogger('π'),
queryParameters: {
'X-Stream-Client': '$defaultUserAgent-$packageVersion',
},
);
_retryPolicy = retryPolicy ??
RetryPolicy(
shouldRetry: (_, __, error) {
return error is StreamChatNetworkError && error.isRetriable;
},
);
state = ClientState(this);
}