Warn when trying to connect to bad urls
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import {Emitter} from '@welshman/lib'
|
import {Emitter} from '@welshman/lib'
|
||||||
|
import {normalizeRelayUrl} from '@welshman/util'
|
||||||
import {Socket} from './Socket'
|
import {Socket} from './Socket'
|
||||||
import type {Message} from './Socket'
|
import type {Message} from './Socket'
|
||||||
import {ConnectionEvent} from './ConnectionEvent'
|
import {ConnectionEvent} from './ConnectionEvent'
|
||||||
@@ -27,6 +28,10 @@ export class Connection extends Emitter {
|
|||||||
constructor(url: string) {
|
constructor(url: string) {
|
||||||
super()
|
super()
|
||||||
|
|
||||||
|
if (url !== normalizeRelayUrl(url)) {
|
||||||
|
console.warn(`Attempted to open connection to non-normalized url ${url}`)
|
||||||
|
}
|
||||||
|
|
||||||
this.url = url
|
this.url = url
|
||||||
this.socket = new Socket(this)
|
this.socket = new Socket(this)
|
||||||
this.sender = new ConnectionSender(this)
|
this.sender = new ConnectionSender(this)
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ export class Socket {
|
|||||||
// Allow the socket to start closing before waiting
|
// Allow the socket to start closing before waiting
|
||||||
await sleep(100)
|
await sleep(100)
|
||||||
|
|
||||||
// Wait for the socket to fully clos
|
// Wait for the socket to fully close
|
||||||
await this.wait()
|
await this.wait()
|
||||||
|
|
||||||
this.ws = undefined
|
this.ws = undefined
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {ctx, Emitter, max, chunk, randomId, once, groupBy, uniq} from '@welshman/lib'
|
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 type {Filter} from '@welshman/util'
|
||||||
import {Tracker} from "./Tracker"
|
import {Tracker} from "./Tracker"
|
||||||
import {Connection} from './Connection'
|
import {Connection} from './Connection'
|
||||||
@@ -354,6 +354,12 @@ export type SubscribeRequestWithHandlers = SubscribeRequest & {
|
|||||||
export const subscribe = ({onEvent, onEose, onClose, onComplete, ...request}: SubscribeRequestWithHandlers) => {
|
export const subscribe = ({onEvent, onEose, onClose, onComplete, ...request}: SubscribeRequestWithHandlers) => {
|
||||||
const sub: Subscription = makeSubscription({delay: 50, ...request})
|
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) {
|
if (request.delay === 0) {
|
||||||
executeSubscription(sub)
|
executeSubscription(sub)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import type {HashedEvent, TrustedEvent} from './Events'
|
|||||||
|
|
||||||
// Constants and types
|
// Constants and types
|
||||||
|
|
||||||
export const LOCAL_RELAY_URL = "local://welshman.relay"
|
export const LOCAL_RELAY_URL = "local://welshman.relay/"
|
||||||
|
|
||||||
export const BOGUS_RELAY_URL = "bogus://welshman.relay"
|
export const BOGUS_RELAY_URL = "bogus://welshman.relay/"
|
||||||
|
|
||||||
export type RelayProfile = {
|
export type RelayProfile = {
|
||||||
url: string
|
url: string
|
||||||
|
|||||||
Reference in New Issue
Block a user