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: Streaming
Implementation
Stream<EffectResponse> stream() {
StreamController<EffectResponse> listener =
new StreamController.broadcast();
EventSource.connect(this.buildUri()).then((eventSource) {
eventSource.listen((Event event) {
if (event.data == "\"hello\"" || event.event == "close") {
return null;
}
EffectResponse effectResponse =
EffectResponse.fromJson(json.decode(event.data));
listener.add(effectResponse);
});
});
return listener.stream;
}