Ensure messages are sent to all relays
To be compatible to wallets that only listen on 'relay.cauldron.quest', we need to make sure we send our messages to all connected relay servers.
This commit is contained in:
parent
053f515b8f
commit
9028384177
1 changed files with 27 additions and 13 deletions
|
|
@ -246,26 +246,40 @@ export class RelayClient extends EventEmitter {
|
|||
this.pairedPubkeyHex,
|
||||
);
|
||||
|
||||
try {
|
||||
await Promise.any(
|
||||
this.pool.publish(this.config.explicitRelayUrls, wrapped),
|
||||
);
|
||||
if (this.config.logNetworkActivity) {
|
||||
debug(Scope.Relay, `Published message ${message.action} to relay`);
|
||||
}
|
||||
} catch (error) {
|
||||
if (this.config.logNetworkActivity) {
|
||||
const results = await Promise.allSettled(
|
||||
this.pool.publish(this.config.explicitRelayUrls, wrapped),
|
||||
);
|
||||
|
||||
const fulfilled = results.filter((r) => r.status === "fulfilled");
|
||||
const rejected = results.filter((r) => r.status === "rejected");
|
||||
|
||||
if (rejected.length > 0 && this.config.logNetworkActivity) {
|
||||
for (const r of rejected) {
|
||||
logError(
|
||||
Scope.Relay,
|
||||
`Failed to publish message ${message.action}:`,
|
||||
error,
|
||||
`Failed to publish ${message.action} to a relay:`,
|
||||
(r as PromiseRejectedResult).reason,
|
||||
);
|
||||
}
|
||||
this.emitDisconnect(
|
||||
error instanceof Error ? error : new Error(`Publish failed: ${error}`),
|
||||
}
|
||||
|
||||
if (fulfilled.length === 0) {
|
||||
const error = new Error(
|
||||
`Failed to publish ${message.action} to all relays`,
|
||||
);
|
||||
if (this.config.logNetworkActivity) {
|
||||
logError(Scope.Relay, error.message);
|
||||
}
|
||||
this.emitDisconnect(error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (this.config.logNetworkActivity) {
|
||||
debug(
|
||||
Scope.Relay,
|
||||
`Published message ${message.action} to ${fulfilled.length}/${results.length} relay(s)`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private handleWrappedEvent(wrappedEvent: NostrEvent): void {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue