startEventsSubscription method
NostrEventsStream
startEventsSubscription({
- required NostrRequest request,
- void onEose(
- String relay,
- NostrRequestEoseCommand ease
- bool useConsistentSubscriptionIdBasedOnRequestData = false,
override
This method will send a request
to all relays that you did registered with the init method, and gets your a Stream of NostrEvents that will be filtered by the request
's subscriptionId
automatically.
if the you do not specify a subscriptionId
in the request
, it will be generated automatically from the library. (This is recommended only of you're not planning to use the closeEventsSubscription method.
example:
Nostr.instance.relays.startEventsSubscription(request);
Implementation
@override
NostrEventsStream startEventsSubscription({
required NostrRequest request,
void Function(String relay, NostrRequestEoseCommand ease)? onEose,
bool useConsistentSubscriptionIdBasedOnRequestData = false,
}) {
final serialized = request.serialized(
subscriptionId: useConsistentSubscriptionIdBasedOnRequestData
? null
: Nostr.instance.utilsService.random64HexChars(),
);
_runFunctionOverRelationIteration((relay) {
_registerOnEoselCallBack(
subscriptionId: request.subscriptionId!,
onEose: onEose ?? (relay, eose) {},
relay: relay.url,
);
relay.socket.sink.add(serialized);
utils.log(
'request with subscription id: ${request.subscriptionId} is sent to relay with url: ${relay.url}',
);
});
final requestSubId = request.subscriptionId;
final subStream = streamsController.events.where(
(event) => _filterNostrEventsWithId(event, requestSubId),
);
return NostrEventsStream(
request: request,
stream: subStream,
subscriptionId: request.subscriptionId!,
);
}