diff --git a/ndk/src/relay/connectivity.ts b/ndk/src/relay/connectivity.ts index 71838784..a1bd43aa 100644 --- a/ndk/src/relay/connectivity.ts +++ b/ndk/src/relay/connectivity.ts @@ -139,6 +139,8 @@ export class NDKRelayConnectivity { public disconnect(): void { this._status = NDKRelayStatus.DISCONNECTING; + if (!this.relay.connected) return; + try { this.relay.close(); } catch (e) { @@ -174,21 +176,6 @@ export class NDKRelayConnectivity { } private async handleNotice(notice: string) { - // This is a prototype; if the relay seems to be complaining - // remove it from relay set selection for a minute. - if (notice.includes("oo many") || notice.includes("aximum")) { - this.disconnect(); - - // fixme - setTimeout(() => this.connect(), 2000); - this.debug(this.relay.url, "Relay complaining?", notice); - // this.complaining = true; - // setTimeout(() => { - // this.complaining = false; - // console.log(this.relay.url, 'Reactivate relay'); - // }, 60000); - } - this.ndkRelay.emit("notice", notice); } diff --git a/ndk/src/relay/index.ts b/ndk/src/relay/index.ts index 07158532..fe79c0f9 100644 --- a/ndk/src/relay/index.ts +++ b/ndk/src/relay/index.ts @@ -156,7 +156,7 @@ export class NDKRelay extends EventEmitter<{ * @param filters Filters to execute */ public subscribe(subscription: NDKSubscription, filters: NDKFilter[]): void { - this.debug("Subscribing to %o", filters); + // this.debug("Subscribing to %o", filters); this.subs.subscribe(subscription, filters); } diff --git a/ndk/src/relay/subscriptions.ts b/ndk/src/relay/subscriptions.ts index 22217bc7..84f36147 100644 --- a/ndk/src/relay/subscriptions.ts +++ b/ndk/src/relay/subscriptions.ts @@ -371,7 +371,7 @@ export class NDKRelaySubscriptions { groupableId: NDKFilterGroupingId | null, groupedSubscriptions: NDKGroupedSubscriptions, mergedFilters: NDKFilter[] - ): Subscription { + ): Subscription | undefined { const subscriptions: NDKSubscription[] = []; for (const { subscription } of groupedSubscriptions) { @@ -407,7 +407,13 @@ export class NDKRelaySubscriptions { // subOptions.skipVerification = true; // } - const sub = this.conn.relay.subscribe(mergedFilters, subOptions); + let sub: Subscription; + const connected = this.conn.relay.connected; + if (!connected) { + this.debug('was about to send to a disconnected relay', this.conn.relay.url, mergedFilters); + return; + } + sub = this.conn.relay.subscribe(mergedFilters, subOptions); this.activeSubscriptions.set(sub, groupedSubscriptions); if (groupableId) { @@ -423,7 +429,7 @@ export class NDKRelaySubscriptions { } }); - this.executeSubscriptionsWhenConnected(groupableId, groupedSubscriptions, mergedFilters); + // this.executeSubscriptionsWhenConnected(groupableId, groupedSubscriptions, mergedFilters); return sub; }