subscribe method
Subscribes to url.
The returned future completes once the connection is established — after
response headers on a native client, on open in the browser — and the
stream it yields then carries events. Splitting the two lets a caller
wait until it is genuinely subscribed before it publishes a connect link,
rather than guessing from the first event to arrive.
The future fails when the connection cannot be established. The stream completes when the server closes a connection this transport will not re-establish, and emits an error for a failure the caller must react to. Cancelling the stream's subscription MUST close the connection.
lastEventId is applied by transports that do not manage their own
replay. Transports that do ignore it, because the browser supplies the
header from its own bookkeeping.
Implementation
@override
Future<Stream<SseEvent>> subscribe(Uri url, {String? lastEventId}) async {
requestedUrls.add(url);
requestedLastEventIds.add(lastEventId);
final failure = failNextWith;
if (failure != null) {
failNextWith = null;
throw failure;
}
final controller = StreamController<SseEvent>();
_connections.add(controller);
return controller.stream;
}