StreamChatClient constructor

StreamChatClient(
  1. String apiKey, {
  2. Level logLevel = Level.WARNING,
  3. LogHandlerFunction logHandlerFunction = StreamChatClient.defaultLogHandler,
  4. RetryPolicy? retryPolicy,
  5. String? baseURL,
  6. Duration connectTimeout = const Duration(seconds: 6),
  7. Duration receiveTimeout = const Duration(seconds: 6),
  8. StreamChatApi? chatApi,
  9. WebSocket? ws,
  10. AttachmentFileUploaderProvider attachmentFileUploaderProvider = StreamAttachmentFileUploader.new,
  11. 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);
}