SSEClient class abstract

An SSEClient that works to maintain a SSE connection to a server.

You can receive Eventss by listening to the stream object. The SSEClient will connect when there is a nonzero number of subscribers on the stream and will disconnect when there are zero subscribers on the stream. In certain cases, unrecoverable errors will be reported on the stream at which point the stream will be done.

On html platforms the client is incapable of reporting unrecoverable errors: the browser's native EventSource exposes no HTTP status codes or response headers, so every failure is treated as recoverable and retried with backoff indefinitely, and no error is ever reported on the stream.

The SSEClient will make best effort to maintain the streaming connection.

Implementers

Constructors

SSEClient(Uri uri, Set<String> eventTypes, {Map<String, String> headers = defaultHeaders, Duration connectTimeout = defaultConnectTimeout, Duration readTimeout = defaultReadTimeout, String? body, SseHttpMethod httpMethod = SseHttpMethod.get, EventSourceLogger? logger, Uri uriProvider()?})
Factory constructor to return the platform implementation.
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stream Stream<Event>
Subscribe to this stream to receive events and sometimes errors. subscribe triggers the connection, so expect network delay initially.
no setter

Methods

close() Future
Closes the SSEClient and tears down connections and resources. Do not use the SSEClient after close is called, behavior is undefined at that point.
hasCapability(SSECapability capability) bool
Whether this implementation supports the given capability. Lets callers detect transport limitations at runtime — for example, the browser native EventSource does not support SSECapability.requestHeaders, so callers that need to authenticate must fall back to a URL-based scheme.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
restart() → void
Request that the SSEClient drops the current connection and then establishes a new connection respecting delay/backoff as if this was an error condition with the connection.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

testClient(Uri uri, Set<String> eventTypes, {Map<String, String> headers = defaultHeaders, Duration connectTimeout = defaultConnectTimeout, Duration readTimeout = defaultReadTimeout, String? body, SseHttpMethod httpMethod = SseHttpMethod.get, Stream<Event>? sourceStream, Set<SSECapability>? capabilities}) TestSseClient
Get an SSE client for use in unit tests.