@couch-kit/client 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,39 @@
1
1
  # @couch-kit/client
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Fix player state not restored on page refresh
8
+
9
+ Players now maintain their identity across page refreshes and network reconnections. The library uses a stable player ID derived from a persistent session secret (stored in localStorage) instead of the ephemeral WebSocket socket ID.
10
+
11
+ **New features:**
12
+ - `__PLAYER_RECONNECTED__` internal action: dispatched when a returning player reconnects, preserving all game data (hand, score, turn, etc.)
13
+ - `__PLAYER_REMOVED__` internal action: dispatched when a disconnected player times out (default: 5 minutes), permanently removing them from state
14
+ - Race-safe disconnect handling: prevents marking a player as disconnected if they've already reconnected on a new socket
15
+ - Secret validation: malformed session secrets are rejected at the JOIN boundary
16
+
17
+ **Breaking changes:**
18
+ - `state.players` keys are now stable derived player IDs instead of ephemeral socket IDs
19
+ - `playerId` returned by `useGameClient()` and sent in `WELCOME` messages is now a stable identifier that persists across reconnections
20
+ - `secret` field in `JOIN` payload is now required (was optional)
21
+
22
+ **Security:**
23
+ - Raw session secret is never stored on `IPlayer` or broadcast to clients
24
+ - Only the derived public player ID is shared in game state
25
+
26
+ ### Patch Changes
27
+
28
+ - Updated dependencies
29
+ - @couch-kit/core@0.5.0
30
+
31
+ ## 0.5.1
32
+
33
+ ### Patch Changes
34
+
35
+ - Fix duplicate React bundling by marking react and @couch-kit/core as external in build
36
+
3
37
  ## 0.5.0
4
38
 
5
39
  ### Minor Changes
package/README.md CHANGED
@@ -40,7 +40,7 @@ Returns:
40
40
 
41
41
  - `status`: `'connecting' | 'connected' | 'disconnected' | 'error'`
42
42
  - `state`: current controller state (optimistic + hydrated)
43
- - `playerId`: server-assigned player id (after `WELCOME`)
43
+ - `playerId`: stable public identifier derived from the session secret. Persists across page refreshes and reconnections (the same player always gets the same `playerId`).
44
44
  - `sendAction(action)`: optimistic dispatch + send to host
45
45
  - `getServerTime()`: NTP-ish server time based on periodic ping/pong
46
46
  - `rtt`: round-trip time (ms) to the server, updated periodically via PING/PONG
@@ -94,7 +94,7 @@ export default function Controller() {
94
94
  const {
95
95
  status, // 'connecting' | 'connected' | 'disconnected' | 'error'
96
96
  state, // The current game state (synced with Host)
97
- playerId, // Your unique session ID
97
+ playerId, // Stable identifier, persists across reconnections
98
98
  sendAction, // Function to send actions to Host
99
99
  } = useGameClient({
100
100
  reducer: gameReducer,