feat(client): name prompt, connection badge, reconnect and resync (#68)

T5 of the M4 client (spec #63). All of it at the existing seams: the pure
reducer slice, the WS client and the browser e2e.

- First sign-in: a live player with `me.name === null` gets a name prompt
  instead of the HUD and no Pixi stage (the server sends no scene until named).
  `player.setname` is acked before the second `hello` (#33); `name-taken`,
  `invalid` and `not-allowed` become visible text and the prompt stays put.
  Acceptance is followed by `hello` + the 6.3 resync, so the prompt is keyed on
  state and is asked once.
- Badge (`#badge[data-state]`): connected / reconnecting / offline. Offline is
  driven by `navigator.onLine` (a phone with no network) and by terminal close
  outcomes; reconnecting keeps the stale map on screen.
- Reconnect: a transport close after a live connection retries with
  1/2/4/8/10 s base delays +/-20% jitter, then the cap. `revoked` and
  `proto-mismatch` stay terminal; pending `reqId`s die with the socket; the
  browser `online` event skips the rest of the wait. A drop does not clear the
  view: `hello` resets every slice and the resync rebuilds tokens, fog,
  explored, markers and lists.
- Two devices on one player key both stay live and receive the same frames.

Proof: new unit tests for the schedule/retry machine (`test/ws.test.ts`) and the
badge/reconnect/name transitions (`test/reducer.test.ts`); new
`client/e2e/session.test.mjs` runs the real server and TLS/HTTP2 vhost, kills
and restarts the server under a live page, drops the browser network with
`context.setOffline`, and asserts the full resync frames (roster, encountered,
vision, explored, marker, token) plus two pages on one key.

Refs #68
This commit is contained in:
2026-11-21 00:18:17 +01:00
parent 2727617db9
commit 465259c853
9 changed files with 1040 additions and 38 deletions
+42 -3
View File
@@ -28,6 +28,7 @@ body {
#boot,
#signin,
#name,
#fatal {
position: absolute;
inset: 0;
@@ -40,14 +41,16 @@ body {
text-align: center;
}
#signin form {
#signin form,
#name form {
display: flex;
flex-direction: column;
gap: 8px;
width: min(360px, 90vw);
}
#key {
#key,
#name-input {
font: inherit;
padding: 10px 12px;
border-radius: 6px;
@@ -58,7 +61,13 @@ body {
text-transform: uppercase;
}
#name-input {
letter-spacing: normal;
text-transform: none;
}
#signin button,
#name button,
#fatal button {
font: inherit;
padding: 10px 12px;
@@ -68,7 +77,8 @@ body {
color: inherit;
}
#signin-error {
#signin-error,
#name-error {
color: #ff8a8a;
}
@@ -102,3 +112,32 @@ body {
#roster-state {
opacity: 0.6;
}
/* Story 7: connected / reconnecting / offline. The dot carries the state at a glance; the text is
the accessible label. */
#badge {
margin-left: auto;
display: inline-flex;
align-items: center;
gap: 5px;
}
#badge::before {
content: '';
width: 8px;
height: 8px;
border-radius: 50%;
background: currentColor;
}
#badge[data-state='connected'] {
color: #7ee787;
}
#badge[data-state='reconnecting'] {
color: #e3b341;
}
#badge[data-state='offline'] {
color: #ff7b72;
}