stream method
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: Server-Sent Events
Implementation
// See: <a href="https://www.stellar.org/developers/horizon/learn/responses.html" target="_blank">Response Format documentation</a>
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;
}