startEventsSubscription method

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

  _registerOnEoselCallBack(request.subscriptionId!, onEose);

  _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 = NostrStreamsControllers.instance.events.where(
    (event) => _filterNostrEventsWithId(event, requestSubId),
  );

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