Analytics viewer: auth-aware reconnect, wake recovery, sliding time window

- Expired session dropped the socket into an endless paced retry loop the
  WS handshake can never escape: probe /_api/settings on close, run the
  paskia login flow on 401/403 and reconnect the moment it resolves; an
  aborted login leaves for the front page (history replace).
- Follow paskia's auth-success/auth-logout window messages: logins anywhere
  in the page reconnect at once instead of waiting out the backoff; logout
  leaves /_a. pagerite.js re-probes its pens on the same events.
- Recycle the socket on visibilitychange/online/bfcache restore: a socket
  that survived sleep looks OPEN but is dead, so no updates ever landed.
- The stats range window was frozen at mount (no reactive time dependency);
  it now slides on a minute clock.
- Transition map beads: fast-forward emitter schedules after long gaps
  instead of spawning a bead per missed interval in one tick.
This commit is contained in:
LeoVasanko committed 2026-09-25 18:01:05 +00:00
1 parent 204c6ab608
commit 7780d190d0
5 files changed
+216 -34

No files matched your search

+19 -2
View File
@@ -341,8 +341,8 @@ the edit pens) links to `/_a`, the analytics page. It is a normal site page:
the standard banner, navigation and footer stay in place, and the analytics
content is rendered inside `#main`. The page itself is public, but the data
stream comes from `WebSocket /_api/ws/analytics`, which remains admin-gated
like the rest of the management API; visitors without access see the viewer
with a "could not be loaded" message.
like the rest of the management API; without a session the viewer starts the
paskia login flow instead of loading data.
Because it is a real page, fetch-navigation handles it like any other internal
link: clicking the 📊 pen (or any link to `/_a`) fetches the server-rendered
@@ -355,6 +355,23 @@ spans less than 24 hours, otherwise `week`.
`AnalyticsView.vue` is no longer a full-screen overlay; the `body.analytics-open`
page-chrome hiding and `#/analytics/<range>` hash routing have been removed.
The viewer owns its connection lifecycle. When the socket drops it probes
`/_api/settings` (plain `fetchJson`, never pops a dialog) to tell an expired
session from a dead network: a 401/403 runs the paskia login flow instead of
retrying (the WS handshake cannot open the login dialog) and the stream
reconnects the moment the login completes; an aborted login (declined, or a
proxy offering no paskia flow) leaves for the front page with a history
replace, so Back does not return to `/_a` just to pop the login again.
Anything else retries with the shared paced backoff (`reconnect.js`).
paskia's `auth-success`/`auth-logout` window messages are followed too: a
login anywhere in the page (the banner's 🔑 button included) reconnects the
stream at once, never waiting out a backoff timer, and a logout leaves for
the front page. Waking the page (`visibilitychange`, `online`, a bfcache
restore) recycles the socket immediately — one that survived sleep still
looks open but is dead — so the fresh snapshot lands right away, and the
stats window slides on a minute clock so an open page never leaves
"last 24 hours" frozen at mount.
Charts are SVG curves (Catmull-Rom over an edge-aware Gaussian — a
change-point detector splits the series at traffic-level shifts, then each
segment is smoothed independently with a fixed sigma chosen so N events in