StreamChatClient constructor

StreamChatClient(
  1. String apiKey, {
  2. Level logLevel = Level.WARNING,
  3. LogHandlerFunction? logHandlerFunction,
  4. RetryPolicy? retryPolicy,
  5. @Deprecated(''' Location is now deprecated in favor of the new edge server. Will be removed in v4.0.0. Read more here: https://getstream.io/blog/chat-edge-infrastructure ''') Location? location,
  6. String? baseURL,
  7. Duration connectTimeout = const Duration(seconds: 6),
  8. Duration receiveTimeout = const Duration(seconds: 6),
  9. StreamChatApi? chatApi,
  10. WebSocket? ws,
  11. AttachmentFileUploader? attachmentFileUploader,
})

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,
  LogHandlerFunction? logHandlerFunction,
  RetryPolicy? retryPolicy,
  @Deprecated('''
  Location is now deprecated in favor of the new edge server. Will be removed in v4.0.0.
  Read more here: https://getstream.io/blog/chat-edge-infrastructure
  ''') Location? location,
  String? baseURL,
  Duration connectTimeout = const Duration(seconds: 6),
  Duration receiveTimeout = const Duration(seconds: 6),
  StreamChatApi? chatApi,
  WebSocket? ws,
  AttachmentFileUploader? attachmentFileUploader,
}) {
  this.logHandlerFunction = logHandlerFunction ?? _defaultLogHandler;
  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,
        attachmentFileUploader: attachmentFileUploader,
        logger: detachedLogger('πŸ•ΈοΈ'),
      );

  _ws = ws ??
      WebSocket(
        apiKey: apiKey,
        baseUrl: options.baseUrl,
        tokenManager: _tokenManager,
        handler: handleEvent,
        logger: detachedLogger('πŸ”Œ'),
        queryParameters: {'X-Stream-Client': defaultUserAgent},
      );

  _retryPolicy = retryPolicy ??
      RetryPolicy(
        shouldRetry: (_, attempt, __) => attempt < 5,
        retryTimeout: (_, attempt, __) => Duration(seconds: attempt),
      );

  state = ClientState(this);
}