sendEventToRelays method

  1. @override
void sendEventToRelays(
  1. NostrEvent event, {
  2. void onOk(
    1. String relay,
    2. NostrEventOkCommand ok
    )?,
})
override

This method is responsible for sending an event to all relays that you did registered with the init method.

It takes a NostrEvent object, then it serializes it internally and sends it to all relays WebSockets.

example:

Nostr.instance.relays.sendEventToRelays(event);

Implementation

@override
void sendEventToRelays(
  NostrEvent event, {
  void Function(String relay, NostrEventOkCommand ok)? onOk,
}) {
  final serialized = event.serialized();

 if(event.id == null) {
    throw Exception('event id cannot be null');
  }

  _runFunctionOverRelationIteration((relay) {

    _registerOnOklCallBack(
      associatedEventId: event.id!,
      onOk: onOk ?? (relay, ok) {},
      relay: relay.url,
    );
    relay.socket.sink.add(serialized);
    utils.log(
      'event with id: ${event.id} is sent to relay with url: ${relay.url}',
    );
  });
}