sse method

Future sse(
  1. String api,
  2. Map<String, dynamic> map,
  3. dynamic eventHandler, {
  4. Function? onError,
  5. void onDone()?,
})

Implementation

Future sse(
  String api,
  Map<String, dynamic> map,
  eventHandler, {
  Function? onError,
  void Function()? onDone,
}) async {
  var uri = Uri(
    scheme: _scheme,
    host: _host,
    path: _pathRoot + api,
    queryParameters: _queryMap,
  );
  var postBody = json.encode(map);
  var es = await EventSource.connect(
    uri,
    headers: {"content-type": "application/json"},
    method: "POST",
    body: postBody,
  );
  es.listen((event) {
    eventHandler(event);
  }, onError: (e) {
    log(e.toString());
    if (onError != null) {
      onError(e);
    }
  });
}