startEventsSubscription method

  1. @override
NostrEventsStream startEventsSubscription({
  1. required NostrRequest request,
})
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,
}) {
  final serialized = request.serialized();

  _runFunctionOverRelationIteration((relay) {
    relay.socket.add(serialized);
    NostrClientUtils.log(
      "request with subscription id: ${request.subscriptionId} is sent to relay with url: ${relay.url}",
    );
  });

  final requestSubId = request.subscriptionId;
  final subStream = eventsStream.where(
    (event) => _filterNostrEventsWithId(event, requestSubId),
  );

  return NostrEventsStream(
    request: request,
    stream: subStream,
    subscriptionId: request.subscriptionId!,
  );
}