From a64611377c646415bc0c21a8bb96b9a079c4ce2b Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 1 Aug 2026 17:44:38 -0700 Subject: Add an NWC subscription watchdog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The pool's reconnect doesn't heal every socket death (an errored socket sets skipReconnection and gives up), and a wallet service with a dead subscription looks exactly like one that's closed — the client spins with no error, which is what happened to tonight's zaps. Re-subscribe every 90s and on online/visibility transitions; the since window plus the replay guard make the churn and any duplicate deliveries harmless. Co-Authored-By: Claude Fable 5 --- src/features/nwc.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/features/nwc.js b/src/features/nwc.js index 20b0dd3..a4fcc03 100644 --- a/src/features/nwc.js +++ b/src/features/nwc.js @@ -463,6 +463,24 @@ export function nwcFeature(ctx) { }); } + // Watchdog: relay sockets can die in ways the pool's reconnect never heals + // (an errored socket sets skipReconnection and gives up), and a wallet + // service with a dead subscription is indistinguishable from one that's + // closed — clients just spin. Re-subscribing is cheap and duplicate + // deliveries are absorbed by the replay guard, so re-listen on a timer and + // whenever the network or the tab comes back. + let watchdog = null; + function startWatchdog() { + if (watchdog) return; + watchdog = setInterval(() => { if (conns().length) listen(); }, 90 * 1000); + if (typeof window !== 'undefined') { + window.addEventListener('online', () => listen()); + document.addEventListener('visibilitychange', () => { + if (document.visibilityState === 'visible' && conns().length) listen(); + }); + } + } + // ---- UI --------------------------------------------------------------- function nwcCard() { @@ -538,8 +556,8 @@ export function nwcFeature(ctx) { return { id: 'nwc', - init() { listen(); }, - stop() { stop(); }, + init() { listen(); startWatchdog(); }, + stop() { stop(); if (watchdog) { clearInterval(watchdog); watchdog = null; } }, settingsCards() { return [nwcCard()]; }, }; } -- cgit v1.2.3