diff --git a/src/lib/url.ts b/src/lib/url.ts index bc72309..8e002eb 100644 --- a/src/lib/url.ts +++ b/src/lib/url.ts @@ -20,6 +20,13 @@ export function normalizeUrl(url: string): string { } else if (p.protocol === 'http:') { p.protocol = 'ws:' } + + // Normalize localhost and local network addresses to always use ws:// instead of wss:// + // This fixes the common typo where people use wss:// for local relays + if (isLocalNetworkUrl(p.toString())) { + p.protocol = 'ws:' + } + if ((p.port === '80' && p.protocol === 'ws:') || (p.port === '443' && p.protocol === 'wss:')) { p.port = '' } diff --git a/src/services/client.service.ts b/src/services/client.service.ts index 83bf620..e2705db 100644 --- a/src/services/client.service.ts +++ b/src/services/client.service.ts @@ -1570,9 +1570,15 @@ class ClientService extends EventTarget { return relays } - const normalizedBlocked = blockedRelays.map(url => normalizeUrl(url) || url) + // Helper function to safely normalize URLs + const safeNormalize = (url: string): string => { + const normalized = normalizeUrl(url) + return normalized || url + } + + const normalizedBlocked = blockedRelays.map(safeNormalize) return relays.filter(relay => { - const normalizedRelay = normalizeUrl(relay) || relay + const normalizedRelay = safeNormalize(relay) return !normalizedBlocked.includes(normalizedRelay) }) } diff --git a/src/services/relay-selection.service.ts b/src/services/relay-selection.service.ts index 89cb0a5..d4b552c 100644 --- a/src/services/relay-selection.service.ts +++ b/src/services/relay-selection.service.ts @@ -482,9 +482,15 @@ class RelaySelectionService { return relays } - const normalizedBlocked = blockedRelays.map(url => normalizeUrl(url) || url) + // Helper function to safely normalize URLs + const safeNormalize = (url: string): string => { + const normalized = normalizeUrl(url) + return normalized || url + } + + const normalizedBlocked = blockedRelays.map(safeNormalize) return relays.filter(relay => { - const normalizedRelay = normalizeUrl(relay) || relay + const normalizedRelay = safeNormalize(relay) return !normalizedBlocked.includes(normalizedRelay) }) }