sendEventToRelays method
Future<void>
sendEventToRelays(
- NostrEvent event, {
- List<
String> ? relays, - void onOk(
- String relay,
- 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
Future<void> sendEventToRelays(
NostrEvent event, {
List<String>? relays,
void Function(String relay, NostrEventOkCommand ok)? onOk,
}) async {
await _registerNewRelays(relays ?? relaysList!);
final serialized = event.serialized();
if (event.id == null) {
throw Exception('event id cannot be null');
}
_runFunctionOverRelationIteration((relay) {
final relayUrl = relay.url;
if (relays?.containsRelay(relayUrl) ?? true) {
_registerOnOklCallBack(
associatedEventId: event.id!,
onOk: onOk ?? (relay, ok) {},
relay: relayUrl,
);
relay.socket.sink.add(serialized);
utils.log(
'event with id: ${event.id} is sent to relay with url: ${relay.url}',
);
}
});
}