diff --git a/src/components/RelayStatusIndicator.tsx b/src/components/RelayStatusIndicator.tsx index 57520066..1ba2056a 100644 --- a/src/components/RelayStatusIndicator.tsx +++ b/src/components/RelayStatusIndicator.tsx @@ -25,6 +25,18 @@ export const RelayStatusIndicator: React.FC = ({ rela const localOnlyMode = hasLocalRelay && !hasRemoteRelay const offlineMode = connectedUrls.length === 0 + // Debug logging + React.useEffect(() => { + if (localOnlyMode || offlineMode) { + console.log('✈️ Relay Status Indicator:', { + mode: offlineMode ? 'OFFLINE' : 'LOCAL_ONLY', + connectedUrls, + hasLocalRelay, + hasRemoteRelay + }) + } + }, [localOnlyMode, offlineMode, connectedUrls.length]) + // Don't show indicator when fully connected if (!localOnlyMode && !offlineMode) return null diff --git a/src/services/relayStatusService.ts b/src/services/relayStatusService.ts index f41a5323..3a624a44 100644 --- a/src/services/relayStatusService.ts +++ b/src/services/relayStatusService.ts @@ -18,29 +18,48 @@ const relayLastSeen = new Map() export function updateAndGetRelayStatuses(relayPool: RelayPool): RelayStatus[] { const statuses: RelayStatus[] = [] const now = Date.now() - const currentRelayUrls = new Set() + const currentlyConnectedUrls = new Set() - // Update relays currently in the pool + // Check all relays in the pool for their actual connection status for (const relay of relayPool.relays.values()) { - currentRelayUrls.add(relay.url) - relayLastSeen.set(relay.url, now) + const isConnected = relay.connected + + if (isConnected) { + currentlyConnectedUrls.add(relay.url) + relayLastSeen.set(relay.url, now) + } statuses.push({ url: relay.url, - isInPool: true, - lastSeen: now + isInPool: isConnected, + lastSeen: isConnected ? now : (relayLastSeen.get(relay.url) || now) }) } - // Add recently seen relays that are no longer in the pool + // Debug logging + const connectedCount = statuses.filter(s => s.isInPool).length + const disconnectedCount = statuses.filter(s => !s.isInPool).length + if (connectedCount === 0 || disconnectedCount > 0) { + console.log(`🔌 Relay status: ${connectedCount} connected, ${disconnectedCount} disconnected`) + const connected = statuses.filter(s => s.isInPool).map(s => s.url.replace(/^wss?:\/\//, '')) + const disconnected = statuses.filter(s => !s.isInPool).map(s => s.url.replace(/^wss?:\/\//, '')) + if (connected.length > 0) console.log('✅ Connected:', connected.join(', ')) + if (disconnected.length > 0) console.log('❌ Disconnected:', disconnected.join(', ')) + } + + // Add recently seen relays that are no longer connected const cutoffTime = now - RECENT_CONNECTION_WINDOW for (const [url, lastSeen] of relayLastSeen.entries()) { - if (!currentRelayUrls.has(url) && lastSeen >= cutoffTime) { - statuses.push({ - url, - isInPool: false, - lastSeen - }) + if (!currentlyConnectedUrls.has(url) && lastSeen >= cutoffTime) { + // Check if this relay is already in statuses (might be in pool but not connected) + const existingStatus = statuses.find(s => s.url === url) + if (!existingStatus) { + statuses.push({ + url, + isInPool: false, + lastSeen + }) + } } }