Warn when trying to connect to bad urls

This commit is contained in:
Jon Staab
2024-11-08 14:35:26 -08:00
parent 8b320e7c9f
commit 07b439eef2
4 changed files with 15 additions and 4 deletions
+5
View File
@@ -1,4 +1,5 @@
import {Emitter} from '@welshman/lib'
import {normalizeRelayUrl} from '@welshman/util'
import {Socket} from './Socket'
import type {Message} from './Socket'
import {ConnectionEvent} from './ConnectionEvent'
@@ -27,6 +28,10 @@ export class Connection extends Emitter {
constructor(url: string) {
super()
if (url !== normalizeRelayUrl(url)) {
console.warn(`Attempted to open connection to non-normalized url ${url}`)
}
this.url = url
this.socket = new Socket(this)
this.sender = new ConnectionSender(this)
+1 -1
View File
@@ -69,7 +69,7 @@ export class Socket {
// Allow the socket to start closing before waiting
await sleep(100)
// Wait for the socket to fully clos
// Wait for the socket to fully close
await this.wait()
this.ws = undefined
+7 -1
View File
@@ -1,5 +1,5 @@
import {ctx, Emitter, max, chunk, randomId, once, groupBy, uniq} from '@welshman/lib'
import {matchFilters, unionFilters, TrustedEvent} from '@welshman/util'
import {LOCAL_RELAY_URL, matchFilters, normalizeRelayUrl, unionFilters, TrustedEvent} from '@welshman/util'
import type {Filter} from '@welshman/util'
import {Tracker} from "./Tracker"
import {Connection} from './Connection'
@@ -354,6 +354,12 @@ export type SubscribeRequestWithHandlers = SubscribeRequest & {
export const subscribe = ({onEvent, onEose, onClose, onComplete, ...request}: SubscribeRequestWithHandlers) => {
const sub: Subscription = makeSubscription({delay: 50, ...request})
for (const relay of request.relays) {
if (relay !== LOCAL_RELAY_URL && relay !== normalizeRelayUrl(relay)) {
console.warn(`Attempted to open subscription to non-normalized url ${relay}`)
}
}
if (request.delay === 0) {
executeSubscription(sub)
} else {