stream method

Stream<OperationResponse> stream ()

Allows to stream SSE events from horizon. Certain endpoints in Horizon can be called in streaming mode using Server-Sent Events. This mode will keep the connection to horizon open and horizon will continue to return responses as ledgers close. See: Streaming

Implementation

Stream<OperationResponse> stream() {
  StreamController<OperationResponse> listener =
      new StreamController.broadcast();
  EventSource.connect(this.buildUri()).then((eventSource) {
    eventSource.listen((Event event) {
      if (event.data == "\"hello\"" || event.event == "close") {
        return null;
      }
      OperationResponse operationResponse =
          OperationResponse.fromJson(json.decode(event.data));
      listener.add(operationResponse);
    });
  });
  return listener.stream;
}