A client only library for using EventSource or Server-Sent Events (SSE).

This library implements the interface as described here.


This packages is a clone of the eventsource library but because we have not been able to get critical changes merged in, we have had to release this package instead. It drops the incomplete server functionality and we have renamed the library to featurehub_sse_client.

Further, with Dart now supporting target platform detection (when detecting vs dart.html) it makes more sense to use the browser specific SSE client (dart:html / EventSource) as it is native to the browser.

Client usage

For more advanced usage, see the example/ directory. Creating a new EventSource client is as easy as a single call. The http package is used under the hood, so wherever this package works, this lbirary will also work. Browser usage is slightly different.

EventSource eventSource = await EventSource.connect("");
// in browsers, you need to pass a http.BrowserClient:
EventSource eventSource = await EventSource.connect("", 
    client: http.BrowserClient());

If you wish to have it connect only when the first listener attaches (and not otherwise), then pass the optional parameter openOnlyOnFirstListener (as true). If you wish to close it after the last listener detaches, then pass the optional parmeter closeOnLastListener.

EventSource eventSource = await EventSource.connect("", 
  openOnlyOnFirstListener: true, closeOnLastListener: true);

You can also listen for events from the event source now, but you will need to provide your own stream controller. If you wish to listen to the events as the stream opens and closes, please pass in a StreamController<>


This project is available under the MIT license, as can be found in the LICENSE file.