feat: Enhance peer subscription and logging in Nostr chat
- Improve the subscription process for peers by adding detailed logging for subscription attempts and results. - Update the ChatComponent to provide a summary of successful and failed subscriptions. - Enhance the useNostrChat composable with additional logging for subscription filters and incoming message handling. - Ensure better visibility into connection state changes and subscription readiness.
This commit is contained in:
parent
d48cbbeec0
commit
a0ae70670d
2 changed files with 68 additions and 18 deletions
|
|
@ -538,16 +538,30 @@ const subscribeToAllPeers = async () => {
|
|||
}
|
||||
|
||||
console.log(`Subscribing to ${peers.value.length} peers for notifications`)
|
||||
console.log('Peers to subscribe to:', peers.value.map(p => ({ pubkey: p.pubkey, username: p.username })))
|
||||
|
||||
let successCount = 0
|
||||
let errorCount = 0
|
||||
|
||||
for (const peer of peers.value) {
|
||||
try {
|
||||
console.log(`Attempting to subscribe to peer: ${peer.pubkey} (${peer.username})`)
|
||||
// Subscribe to peer for notifications only (don't load full history)
|
||||
await subscribeToPeerForNotifications(peer.pubkey)
|
||||
console.log(`Successfully subscribed to notifications for peer: ${peer.pubkey}`)
|
||||
const subscription = await subscribeToPeerForNotifications(peer.pubkey)
|
||||
if (subscription) {
|
||||
console.log(`Successfully subscribed to notifications for peer: ${peer.pubkey}`)
|
||||
successCount++
|
||||
} else {
|
||||
console.warn(`Failed to create subscription for peer: ${peer.pubkey}`)
|
||||
errorCount++
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn(`Failed to subscribe to peer ${peer.pubkey}:`, error)
|
||||
errorCount++
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Subscription summary: ${successCount} successful, ${errorCount} failed`)
|
||||
}
|
||||
|
||||
const refreshPeers = () => {
|
||||
|
|
@ -646,8 +660,22 @@ onMounted(async () => {
|
|||
}
|
||||
}
|
||||
|
||||
console.log('Starting connection and peer loading...')
|
||||
await connect()
|
||||
console.log('Connection established, loading peers...')
|
||||
await loadPeers()
|
||||
console.log('Peers loaded, checking if we should subscribe...')
|
||||
|
||||
// If we're connected and have peers, subscribe to them
|
||||
if (isConnected.value && peers.value.length > 0) {
|
||||
console.log('Connection and peers ready, subscribing to all peers for notifications')
|
||||
await subscribeToAllPeers()
|
||||
} else {
|
||||
console.log('Not ready to subscribe yet:', {
|
||||
isConnected: isConnected.value,
|
||||
peerCount: peers.value.length
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
|
|
@ -656,9 +684,10 @@ onUnmounted(() => {
|
|||
})
|
||||
|
||||
// Watch for connection state changes and subscribe to peers when connected
|
||||
watch(isConnected, async (connected) => {
|
||||
if (connected && peers.value.length > 0) {
|
||||
console.log('Connection established, subscribing to peers for notifications')
|
||||
watch(isConnected, async (connected, prevConnected) => {
|
||||
console.log('Connection state changed:', { connected, prevConnected, peerCount: peers.value.length })
|
||||
if (connected && peers.value.length > 0 && !prevConnected) {
|
||||
console.log('Connection established and peers available, subscribing to peers for notifications')
|
||||
await subscribeToAllPeers()
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue