SSEClient constructor
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.
An optional body
. It is recommended only to use the body with REPORT
or POST
methods. A GET
accompanied by a body is non-standard. On html
platforms the body will be ignored, as the html
implementation uses
the standard EventSource
which does not support a body.
An optional httpMethod
, if not included then the GET
method will be
used. On html
platforms the httpMethod will be ignored, as the html
implementation uses the standard EventSource
which only uses GET
.
Implementation
factory SSEClient(Uri uri, Set<String> eventTypes,
{Map<String, String> headers = defaultHeaders,
Duration connectTimeout = defaultConnectTimeout,
Duration readTimeout = defaultReadTimeout,
String? body,
SseHttpMethod httpMethod = SseHttpMethod.get}) {
// merge headers so consumer gets reasonable defaults
var mergedHeaders = <String, String>{};
mergedHeaders.addAll(defaultHeaders);
mergedHeaders.addAll(headers);
return getSSEClient(uri, eventTypes, mergedHeaders, connectTimeout,
readTimeout, body, httpMethod.toString());
}