@ksaa-nlp/gamehub-sdk 0.6.0 → 0.6.1

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,33 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.1 — 2026-04-30
4
+
5
+ Three small, additive fixes that surfaced while porting link-game to the `multiplayer.match` API.
6
+
7
+ - **`MatchCtx.retained: boolean`.** Added a `retained` flag on the context passed into `apply` and `onStart` handlers. It's `true` only when the handler is running for a server-replayed retained frame (a peer reconnecting / joining late catching up on past state) and `false` for live broadcasts and host-initiated calls. Game code uses this to suppress one-shot side effects — sounds, confetti, win animations, draw dialogs on a delay — that would otherwise re-fire for state the peer didn't see live. Also: retained replays no longer trigger a host's `hostHandle` (the host already authored that frame; re-validating against its own snapshot is at best wasteful, at worst incorrect).
8
+
9
+ - **`Peer` identity fields.** The wire payload from the realtime server (`displayName`, `avatar`, `userId`, `guestId`) was already populated from JWT claims, but the public `Peer` type only exposed `peerId`/`role`/`metadata`. Adding the rest as optional fields lets games access player-name and avatar info without an `as any` cast. Optional because anonymous / passcode-joined peers may not carry all four.
10
+
11
+ - **`MatchEventMap` constraint relaxed to a self-mapped form.** `match<TMap, TStart>(...)` previously required `TMap extends Record<string, MatchScopedPayload>`, which TypeScript silently rejects for an `interface LinkMatchMap { ... }` declaration because interfaces with concrete keys don't have an index signature. Switched the constraint everywhere (the `match()` factory, `MatchOptions`, the `Sdk['multiplayer'].match` signature) to the self-mapped pattern `<TMap extends { [K in keyof TMap]: MatchScopedPayload }>`, which accepts both interface-shaped and type-alias-shaped event maps while still enforcing per-key payload safety. The `MatchEventMap` alias is retained as documentation; its docstring now explains why the actual generics use the self-mapped form.
12
+
13
+ ### Why these are 0.6.1 rather than 0.6.0
14
+
15
+ These shipped together with the original `multiplayer.match` API (0.6.0) but emerged only when a real game tried to consume it. Bumping a patch version makes the relationship explicit: 0.6.0 is the API as designed; 0.6.1 is the API as a real game actually uses it.
16
+
17
+ ### Verified
18
+
19
+ - SDK type-check + build clean (53.3 KB IIFE).
20
+ - link-game (Angular, `@ksaa-nlp/gamehub-sdk@0.6.x` consumer) builds clean against the new types.
21
+ - 18/18 realtime tests still green.
22
+
23
+ ### Unchanged
24
+
25
+ - Wire protocol with the realtime server.
26
+ - `Sdk` interface beyond the new `MatchCtx.retained` / `Peer.{userId,guestId,displayName,avatar}` fields and the loosened `match<>` constraint (purely a relaxation, no existing code breaks).
27
+ - `BootstrapData`, `MpMessage`, `multiplayer.send` / `broadcast` / `on` semantics.
28
+
29
+ ---
30
+
3
31
  ## 0.6.0 — 2026-04-30
4
32
 
5
33
  Adds **`multiplayer.match()`** — a host-authoritative match coordinator that owns the lifecycle every multiplayer game otherwise reinvents: peer-ready handshake, host-elected match start, intent → resolve routing, matchId scoping, and idempotent reapply of broadcasts (live and retained replay alike). Plus two helpers (`assignSeats`, `waitForPeers`) that complete the picture.
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  (() => {
3
3
  // src/constants.ts
4
- var SDK_VERSION = "0.6.0";
4
+ var SDK_VERSION = "0.6.1";
5
5
  var MESSAGE_PREFIX = "GAMEHUB_SDK";
6
6
  var PARENT_REQUEST_TIMEOUT_MS = 2e3;
7
7
  var MP_MAX_RECONNECT_ATTEMPTS = 5;
@@ -645,6 +645,9 @@
645
645
  frame.retain = true;
646
646
  if (options.retainKey) frame.retainKey = options.retainKey;
647
647
  }
648
+ if (options.to !== void 0) {
649
+ frame.to = options.to;
650
+ }
648
651
  socket.send(JSON.stringify(frame));
649
652
  return true;
650
653
  }
@@ -1154,7 +1157,7 @@
1154
1157
  function localPeers() {
1155
1158
  return getPeers();
1156
1159
  }
1157
- function makeCtx() {
1160
+ function makeCtx(retained = false) {
1158
1161
  return {
1159
1162
  get matchId() {
1160
1163
  return matchId ?? "";
@@ -1168,6 +1171,7 @@
1168
1171
  get peers() {
1169
1172
  return localPeers();
1170
1173
  },
1174
+ retained,
1171
1175
  peer(peerId) {
1172
1176
  return localPeers().find((p) => p.peerId === peerId) ?? null;
1173
1177
  },
@@ -1191,13 +1195,13 @@
1191
1195
  }
1192
1196
  return `${eventName}:${payload.matchId}:${seq ?? "local"}`;
1193
1197
  }
1194
- function maybeApply(eventName, def, payload, fromPeerId, seq) {
1198
+ function maybeApply(eventName, def, payload, fromPeerId, seq, retained) {
1195
1199
  if (!def?.apply) return;
1196
1200
  const key = idKeyFor(eventName, def, payload, seq);
1197
1201
  if (appliedIdKeys.has(key)) return;
1198
1202
  appliedIdKeys.add(key);
1199
1203
  try {
1200
- def.apply(makeCtx(), payload, fromPeerId);
1204
+ def.apply(makeCtx(retained), payload, fromPeerId);
1201
1205
  } catch (err) {
1202
1206
  error(`multiplayer.match apply('${eventName}') threw:`, err);
1203
1207
  }
@@ -1255,7 +1259,7 @@
1255
1259
  const payload = { ...payloadIn, matchId };
1256
1260
  const def = eventDefFor(String(name));
1257
1261
  const me = localSelfId() ?? "";
1258
- maybeApply(String(name), def, payload, me, void 0);
1262
+ maybeApply(String(name), def, payload, me, void 0, false);
1259
1263
  const retain = callerOptions.retain ?? def?.retain ?? false;
1260
1264
  let retainKey;
1261
1265
  if (retain) {
@@ -1336,8 +1340,9 @@
1336
1340
  matchId = payload.matchId;
1337
1341
  appliedIdKeys.clear();
1338
1342
  setState("active");
1343
+ const retained = msg?.retained === true;
1339
1344
  try {
1340
- options.onStart(makeCtx(), payload);
1345
+ options.onStart(makeCtx(retained), payload);
1341
1346
  } catch (err) {
1342
1347
  error("multiplayer.match onStart threw:", err);
1343
1348
  }
@@ -1360,10 +1365,11 @@
1360
1365
  const def = eventDefFor(eventName);
1361
1366
  const fromPeerId = msg?.fromPeerId ?? "";
1362
1367
  const seq = msg?.seq;
1363
- if (def?.hostHandle && localIsHost() && fromPeerId !== localSelfId()) {
1368
+ const retained = msg?.retained === true;
1369
+ if (def?.hostHandle && localIsHost() && fromPeerId !== localSelfId() && !retained) {
1364
1370
  try {
1365
1371
  Promise.resolve(
1366
- def.hostHandle(makeCtx(), payload, fromPeerId)
1372
+ def.hostHandle(makeCtx(false), payload, fromPeerId)
1367
1373
  ).catch(
1368
1374
  (err) => error(
1369
1375
  `multiplayer.match hostHandle('${eventName}') threw:`,
@@ -1375,7 +1381,7 @@
1375
1381
  }
1376
1382
  return;
1377
1383
  }
1378
- maybeApply(eventName, def, payload, fromPeerId, seq);
1384
+ maybeApply(eventName, def, payload, fromPeerId, seq, retained);
1379
1385
  }
1380
1386
  offHandlers.push(
1381
1387
  on("peer_joined", () => {