SSEClient constructor

SSEClient(
  1. Uri uri,
  2. Set<String> eventTypes, {
  3. Map<String, String> headers = defaultHeaders,
  4. Duration connectTimeout = defaultConnectTimeout,
  5. Duration readTimeout = defaultReadTimeout,
})

Factory constructor to return the platform implementation.

On all platforms, the uri and eventTypes arguments are required. On majority of platforms, the optional arguments are used. On web, the optional arguments are not used.

The uri specifies where to connect. The eventTypes determines which event types will be emitted. For non-web platforms, pass in headers to customize the HTTP headers of the connection request. The connectTimeout is how long to try establishing the connection and the readTimeout is how long the connection can be silent before it is torn down.

Implementation

factory SSEClient(Uri uri, Set<String> eventTypes,
    {Map<String, String> headers = defaultHeaders,
    Duration connectTimeout = defaultConnectTimeout,
    Duration readTimeout = defaultReadTimeout}) {
  // merge headers so consumer gets reasonable defaults
  var mergedHeaders = <String, String>{};
  mergedHeaders.addAll(defaultHeaders);
  mergedHeaders.addAll(headers);
  return getSSEClient(
      uri, eventTypes, mergedHeaders, connectTimeout, readTimeout);
}