logs cleanup and notifications set

This commit is contained in:
Tiago Vasconcelos
2025-10-30 12:22:48 +00:00
parent 93bcd25ab7
commit f405d6834a
+49 -22
View File
@@ -194,12 +194,12 @@ window.LNbits = {
try { try {
const ws = new WebSocket(websocketUrlFull) const ws = new WebSocket(websocketUrlFull)
g.activeWebsockets[wallet.id] = ws g.activeWebsockets[wallet.id] = ws
console.log( console.debug(
`[LNbits] Connecting WebSocket for wallet ${wallet.id}... (attempt ${retryCount + 1})` `Connecting WebSocket for wallet ${wallet.name}... (attempt ${retryCount + 1})`
) )
ws.onopen = () => { ws.onopen = () => {
console.log(`[LNbits] WebSocket connected for wallet ${wallet.id}`) console.debug(`WebSocket connected for wallet ${wallet.name}`)
g.disconnectedWallets.delete(wallet.id) g.disconnectedWallets.delete(wallet.id)
updateConnectionWarning() updateConnectionWarning()
} }
@@ -209,15 +209,12 @@ window.LNbits = {
const data = JSON.parse(ev.data) const data = JSON.parse(ev.data)
if (data.payment) cb(data) if (data.payment) cb(data)
} catch (err) { } catch (err) {
console.error('[LNbits] Error parsing WebSocket message:', err) console.error('Error parsing WebSocket message:', err)
} }
} }
ws.onerror = err => { ws.onerror = err => {
console.error( console.error(`WebSocket error for wallet ${wallet.name}:`, err)
`[LNbits] WebSocket error for wallet ${wallet.name}:`,
err
)
ws.close() ws.close()
} }
@@ -227,24 +224,18 @@ window.LNbits = {
if (retryCount < maxRetries) { if (retryCount < maxRetries) {
console.warn( console.warn(
`[LNbits] WebSocket closed for wallet ${wallet.name}. Reconnecting in ${reconnectInterval / 1000}s...` `WebSocket closed for wallet ${wallet.name}. Reconnecting in ${reconnectInterval / 1000}s...`
) )
this.$q.notify({
message: 'Connection lost. Trying to reconnect...',
caption: wallet.name,
color: 'negative',
position: 'top'
})
setTimeout(() => connect(retryCount + 1), reconnectInterval) setTimeout(() => connect(retryCount + 1), reconnectInterval)
} else { } else {
console.error( console.error(
`[LNbits] WebSocket for wallet ${wallet.name} failed after ${maxRetries} attempts. Stopping retries.` `WebSocket for wallet ${wallet.name} failed after ${maxRetries} attempts. Stopping retries.`
) )
} }
} }
} catch (err) { } catch (err) {
console.error( console.error(
`[LNbits] WebSocket connection failed for wallet ${wallet.name}:`, `WebSocket connection failed for wallet ${wallet.name}:`,
err err
) )
g.disconnectedWallets.add(wallet.id) g.disconnectedWallets.add(wallet.id)
@@ -533,7 +524,9 @@ if (!window.g) {
langs: [], langs: [],
walletEventListeners: [], walletEventListeners: [],
updatePayments: false, updatePayments: false,
updatePaymentsHash: '' updatePaymentsHash: '',
wsDisconnectionNotification: false,
wsReconnectedNotification: false
}) })
} }
@@ -568,7 +561,8 @@ window.windowMixin = {
bgimageChoice: this.$q.localStorage.has('lnbits.backgroundImage') bgimageChoice: this.$q.localStorage.has('lnbits.backgroundImage')
? this.$q.localStorage.getItem('lnbits.backgroundImage') ? this.$q.localStorage.getItem('lnbits.backgroundImage')
: USE_DEFAULT_BGIMAGE, : USE_DEFAULT_BGIMAGE,
...WINDOW_SETTINGS ...WINDOW_SETTINGS,
silentConnectionCleanup: false
} }
}, },
@@ -880,9 +874,7 @@ window.windowMixin = {
// Retry timer reference (for cleanup) // Retry timer reference (for cleanup)
this.connectionRetryTimer = setInterval(() => { this.connectionRetryTimer = setInterval(() => {
if (this.g.disconnectedWallets && this.g.disconnectedWallets.size > 0) { if (this.g.disconnectedWallets && this.g.disconnectedWallets.size > 0) {
console.warn( console.warn('Some wallets are still disconnected. Retrying...')
'[LNbits] Some wallets are still disconnected. Retrying...'
)
this.paymentEvents() this.paymentEvents()
} }
}, 60000) }, 60000)
@@ -890,11 +882,46 @@ window.windowMixin = {
}, },
beforeUnmount() { beforeUnmount() {
this.silentConnectionCleanup = true
// Prevent background timers when component is destroyed // Prevent background timers when component is destroyed
if (this.connectionRetryTimer) { if (this.connectionRetryTimer) {
clearInterval(this.connectionRetryTimer) clearInterval(this.connectionRetryTimer)
this.connectionRetryTimer = null this.connectionRetryTimer = null
} }
},
watch: {
'g.connectionWarning': {
handler(newVal, oldVal) {
if (this.silentConnectionCleanup) return
if (newVal && !g.wsDisconnectionNotification) {
this.$q.notify({
message: 'Some wallet connections are lost. Retrying...',
color: 'negative',
icon: null,
position: 'top',
timeout: 5000
})
g.wsDisconnectionNotification = true
g.wsReconnectedNotification = false
} else if (
oldVal === true &&
newVal === false &&
!g.wsReconnectedNotification
) {
this.$q.notify({
message: 'All wallet connections restored.',
color: 'positive',
icon: null,
position: 'top',
timeout: 3000
})
g.wsReconnectedNotification = true
g.wsDisconnectionNotification = false
}
},
immediate: false
}
} }
} }