/** * Relay pool and relay constants. * Extracted into its own module to avoid circular dependencies * between nostr.ts and accounts.ts. */ import { BehaviorSubject } from 'applesauce-core' import { RelayPool } from 'applesauce-relay' // Relay pool for all WebSocket connections export const pool = new RelayPool() /** * Determine app relay URLs at runtime. * * Priority: * 1. VITE_NOSTR_RELAYS env var (set in .env for local dev) * 2. Auto-detect: proxy through same host at /relay (Docker / production) */ function getAppRelays(): string[] { const envRelays = import.meta.env.VITE_NOSTR_RELAYS as string | undefined if (envRelays) { const parsed = envRelays.split(',').map((r: string) => r.trim()).filter(Boolean) if (parsed.length > 0) return parsed } // Production / Docker: relay is proxied through nginx at /relay const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:' return [`${protocol}//${window.location.host}/relay`] } // App relays (local dev relay or proxied production relay) export const APP_RELAYS = getAppRelays() // Lookup relays for profile metadata export const LOOKUP_RELAYS = ['wss://purplepag.es'] // Observable relay list for reactive subscriptions export const appRelays = new BehaviorSubject([...APP_RELAYS])