Update WebSocket configuration and enhance logging in WalletWebSocketService

- Modified WebSocket configuration to allow enabling/disabling via environment variable, improving flexibility.
- Enhanced logging in WalletWebSocketService to provide clearer messages during reconnection attempts and notify users of WebSocket issues.

These changes improve the configurability and user experience of the wallet's WebSocket interactions.
This commit is contained in:
padreug 2025-09-18 10:25:17 +02:00
parent 71cec00bfc
commit 6a1e70303d
2 changed files with 10 additions and 3 deletions

View file

@ -76,7 +76,7 @@ export const appConfig: AppConfig = {
baseUrl: import.meta.env.VITE_LNBITS_BASE_URL || 'http://localhost:5000'
},
websocket: {
enabled: true,
enabled: import.meta.env.VITE_WEBSOCKET_ENABLED !== 'false', // Can be disabled via env var
reconnectDelay: 1000, // 1 second
maxReconnectAttempts: 5
}

View file

@ -308,8 +308,15 @@ export class WalletWebSocketService extends BaseService {
private scheduleReconnect(): void {
// Don't reconnect if we've exceeded max attempts
if (this.reconnectAttempts >= this.config.maxReconnectAttempts) {
console.log('WalletWebSocketService: Max reconnection attempts reached')
console.log('WalletWebSocketService: Max reconnection attempts reached - disabling WebSocket')
this.connectionStatus.value = 'failed'
// Show user notification about WebSocket issues
if (this.toast) {
this.toast.info('Real-time balance updates temporarily unavailable', {
description: 'WebSocket connection failed. Balance will update on page refresh.'
})
}
return
}
@ -322,7 +329,7 @@ export class WalletWebSocketService extends BaseService {
const delay = this.config.reconnectDelay * Math.pow(2, this.reconnectAttempts)
this.reconnectAttempts++
console.log(`WalletWebSocketService: Reconnecting in ${delay}ms (attempt ${this.reconnectAttempts})`)
console.log(`WalletWebSocketService: Reconnecting in ${delay}ms (attempt ${this.reconnectAttempts}/${this.config.maxReconnectAttempts})`)
this.connectionStatus.value = 'reconnecting'
this.reconnectTimer = setTimeout(() => {