chore: clean up relay related debug logs
This commit is contained in:
parent
7829635de8
commit
786e27ab61
4 changed files with 23 additions and 24 deletions
|
|
@ -58,7 +58,6 @@ onMounted(async () => {
|
|||
// Initialize relay hub
|
||||
try {
|
||||
await relayHub.initialize()
|
||||
console.log('Relay hub initialized successfully')
|
||||
} catch (error) {
|
||||
console.error('Failed to initialize relay hub:', error)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ export function useRelayHub() {
|
|||
connectionStatus.value = 'connected'
|
||||
isConnected.value = true
|
||||
|
||||
console.log('RelayHub initialized successfully')
|
||||
|
||||
} catch (err) {
|
||||
const errorObj = err instanceof Error ? err : new Error('Failed to initialize RelayHub')
|
||||
error.value = errorObj
|
||||
|
|
@ -160,7 +160,7 @@ export function useRelayHub() {
|
|||
// Set up event listeners for relay hub events
|
||||
const setupEventListeners = (): void => {
|
||||
relayHub.on('connected', (count: number) => {
|
||||
console.log('Connected to relays:', count)
|
||||
|
||||
isConnected.value = true
|
||||
connectionStatus.value = 'connected'
|
||||
error.value = null
|
||||
|
|
@ -170,7 +170,7 @@ export function useRelayHub() {
|
|||
})
|
||||
|
||||
relayHub.on('disconnected', () => {
|
||||
console.log('Disconnected from all relays')
|
||||
|
||||
isConnected.value = false
|
||||
connectionStatus.value = 'disconnected'
|
||||
error.value = null
|
||||
|
|
@ -218,12 +218,12 @@ export function useRelayHub() {
|
|||
|
||||
// Subscription events
|
||||
relayHub.on('subscriptionCreated', ({ count }: { id: string; count: number }) => {
|
||||
console.log('Subscription created, total count:', count)
|
||||
|
||||
totalSubscriptionCount.value = count
|
||||
})
|
||||
|
||||
relayHub.on('subscriptionRemoved', ({ count }: { id: string; count: number }) => {
|
||||
console.log('Subscription removed, total count:', count)
|
||||
|
||||
totalSubscriptionCount.value = count
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ export class NostrClient {
|
|||
disconnect(): void {
|
||||
// Note: We don't disconnect the relay hub here as other components might be using it
|
||||
// The relay hub will be managed at the app level
|
||||
console.log('Client disconnected (relay hub remains active)')
|
||||
|
||||
}
|
||||
|
||||
async fetchNotes(options: {
|
||||
|
|
@ -126,7 +126,7 @@ export class NostrClient {
|
|||
|
||||
try {
|
||||
const result = await relayHub.publishEvent(event)
|
||||
console.log(`Published event ${event.id} to ${result.success}/${result.total} relays`)
|
||||
|
||||
} catch (error) {
|
||||
console.error('Failed to publish event:', error)
|
||||
throw error
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ export class RelayHub extends EventEmitter {
|
|||
this.startHealthCheck()
|
||||
this.isInitialized = true
|
||||
|
||||
console.log(`RelayHub initialized with ${relayUrls.length} relays`)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -159,7 +159,7 @@ export class RelayHub extends EventEmitter {
|
|||
|
||||
try {
|
||||
this._connectionAttempts++
|
||||
console.log(`Connecting to ${this.relayConfigs.size} relays (attempt ${this._connectionAttempts})`)
|
||||
|
||||
|
||||
// Connect to relays in priority order
|
||||
const sortedRelays = Array.from(this.relayConfigs.values())
|
||||
|
|
@ -169,7 +169,7 @@ export class RelayHub extends EventEmitter {
|
|||
try {
|
||||
const relay = await this.pool.ensureRelay(config.url)
|
||||
this.connectedRelays.set(config.url, relay)
|
||||
console.log(`Connected to relay: ${config.url}`)
|
||||
|
||||
return { url: config.url, success: true }
|
||||
} catch (error) {
|
||||
console.error(`Failed to connect to relay ${config.url}:`, error)
|
||||
|
|
@ -186,7 +186,7 @@ export class RelayHub extends EventEmitter {
|
|||
this._isConnected = true
|
||||
this._connectionAttempts = 0
|
||||
this.emit('connected', successfulConnections.length)
|
||||
console.log(`Successfully connected to ${successfulConnections.length}/${this.relayConfigs.size} relays`)
|
||||
|
||||
} else {
|
||||
throw new Error('Failed to connect to any relay')
|
||||
}
|
||||
|
|
@ -209,7 +209,7 @@ export class RelayHub extends EventEmitter {
|
|||
* Disconnect from all relays
|
||||
*/
|
||||
disconnect(): void {
|
||||
console.log('Disconnecting from all relays')
|
||||
|
||||
|
||||
// Clear intervals
|
||||
if (this.reconnectInterval) {
|
||||
|
|
@ -254,7 +254,7 @@ export class RelayHub extends EventEmitter {
|
|||
throw new Error('No available relays for subscription')
|
||||
}
|
||||
|
||||
console.log(`Creating subscription ${config.id} on ${availableRelays.length} relays`)
|
||||
|
||||
|
||||
// Create subscription using the pool
|
||||
const subscription = this.pool.subscribeMany(availableRelays, config.filters, {
|
||||
|
|
@ -288,7 +288,7 @@ export class RelayHub extends EventEmitter {
|
|||
if (subscription) {
|
||||
subscription.close()
|
||||
this.subscriptions.delete(subscriptionId)
|
||||
console.log(`Unsubscribed from ${subscriptionId}`)
|
||||
|
||||
|
||||
// Emit subscription removed event
|
||||
this.emit('subscriptionRemoved', { id: subscriptionId, count: this.subscriptions.size })
|
||||
|
|
@ -311,7 +311,7 @@ export class RelayHub extends EventEmitter {
|
|||
const successful = results.filter(result => result.status === 'fulfilled').length
|
||||
const total = results.length
|
||||
|
||||
console.log(`Published event ${event.id} to ${successful}/${total} relays`)
|
||||
|
||||
this.emit('eventPublished', { eventId: event.id, success: successful, total })
|
||||
|
||||
return { success: successful, total }
|
||||
|
|
@ -339,7 +339,7 @@ export class RelayHub extends EventEmitter {
|
|||
const events = await this.pool.querySync(availableRelays, filter)
|
||||
allEvents.push(...events)
|
||||
}
|
||||
console.log(`Queried ${allEvents.length} events from ${availableRelays.length} relays`)
|
||||
|
||||
return allEvents
|
||||
} catch (error) {
|
||||
console.error('Query failed:', error)
|
||||
|
|
@ -365,7 +365,7 @@ export class RelayHub extends EventEmitter {
|
|||
* Force reconnection to all relays
|
||||
*/
|
||||
async reconnect(): Promise<void> {
|
||||
console.log('Forcing reconnection to all relays')
|
||||
|
||||
this.disconnect()
|
||||
await this.connect()
|
||||
}
|
||||
|
|
@ -379,7 +379,7 @@ export class RelayHub extends EventEmitter {
|
|||
}
|
||||
|
||||
this.reconnectInterval = setTimeout(async () => {
|
||||
console.log('Attempting automatic reconnection...')
|
||||
|
||||
await this.connect()
|
||||
}, this.reconnectDelay)
|
||||
}
|
||||
|
|
@ -403,7 +403,7 @@ export class RelayHub extends EventEmitter {
|
|||
private async performHealthCheck(): Promise<void> {
|
||||
if (!this._isConnected) return
|
||||
|
||||
console.log('Performing relay health check...')
|
||||
|
||||
const disconnectedRelays: string[] = []
|
||||
|
||||
// Check each relay connection
|
||||
|
|
@ -423,7 +423,7 @@ export class RelayHub extends EventEmitter {
|
|||
// Remove disconnected relays
|
||||
disconnectedRelays.forEach(url => {
|
||||
this.connectedRelays.delete(url)
|
||||
console.log(`Removed disconnected relay: ${url}`)
|
||||
|
||||
})
|
||||
|
||||
// Update connection status
|
||||
|
|
@ -448,7 +448,7 @@ export class RelayHub extends EventEmitter {
|
|||
if (typeof document !== 'undefined') {
|
||||
this.mobileVisibilityHandler = () => {
|
||||
if (document.hidden) {
|
||||
console.log('Page hidden, maintaining WebSocket connections')
|
||||
|
||||
// Keep connections alive but reduce activity
|
||||
} else {
|
||||
console.log('Page visible, resuming normal WebSocket activity')
|
||||
|
|
@ -463,7 +463,7 @@ export class RelayHub extends EventEmitter {
|
|||
// Handle online/offline events
|
||||
if (typeof window !== 'undefined') {
|
||||
window.addEventListener('online', () => {
|
||||
console.log('Network online, checking relay connections...')
|
||||
|
||||
this.performHealthCheck()
|
||||
})
|
||||
|
||||
|
|
@ -479,7 +479,7 @@ export class RelayHub extends EventEmitter {
|
|||
* Cleanup resources
|
||||
*/
|
||||
destroy(): void {
|
||||
console.log('Destroying RelayHub...')
|
||||
|
||||
|
||||
// Remove event listeners
|
||||
if (this.mobileVisibilityHandler && typeof document !== 'undefined') {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue