Publish an event to all relays in this set. Returns the number of relays that have received the event.
Optional
timeoutMs: numbertimeout in milliseconds for each publish operation and connection operation
A set where the event was successfully published to
const event = new NDKEvent(ndk, {kinds: [NDKKind.Message], "#d": ["123"]});
try {
const publishedToRelays = await relaySet.publish(event);
console.log(`published to ${publishedToRelays.size} relays`)
} catch (error) {
console.error("error publishing to relays", error);
if (error instanceof NDKPublishError) {
for (const [relay, err] of error.errors) {
console.error(`error publishing to relay ${relay.url}`, err);
}
}
}
Static
fromCreates a relay set from a list of relay URLs.
If no connection to the relay is found in the pool it will temporarily connect to it.
list of relay URLs to include in this set
whether to connect to the relay immediately if it was already in the pool but not connected
NDKRelaySet
A relay set is a group of relays. This grouping can be short-living, for a single REQ or can be long-lasting, for example for the explicit relay list the user has specified.
Requests to relays should be sent through this interface.