castle-web-cli 0.4.240 → 0.4.242

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.
Files changed (42) hide show
  1. package/dist/bundle.d.ts +9 -1
  2. package/dist/bundle.js +214 -25
  3. package/dist/init.js +1 -1
  4. package/dist/multiplayerDoc.d.ts +1 -1
  5. package/dist/multiplayerDoc.js +2 -0
  6. package/dist/platformDoc.js +3 -3
  7. package/dist/playPagePolicy.js +7 -6
  8. package/dist/roomLogs.d.ts +1 -0
  9. package/dist/roomLogs.js +30 -6
  10. package/dist/save-deck.js +20 -3
  11. package/kits/base/castle.json +1 -1
  12. package/kits/base/sdk/README.md +7 -0
  13. package/kits/base/sdk/context.d.ts +5 -0
  14. package/kits/base/sdk/debugConsole.d.ts +1 -0
  15. package/kits/base/sdk/debugConsole.js +87 -14
  16. package/kits/base/sdk/runtime.js +5 -4
  17. package/kits/hub-game/code/client/chrome.js +8 -4
  18. package/kits/hub-game/code/client/padCues.js +11 -7
  19. package/kits/hub-game/code/client/padReadability.js +3 -3
  20. package/kits/hub-game/code/client/visibility.js +14 -4
  21. package/kits/hub-game/code/server/hub.js +146 -30
  22. package/kits/hub-game/code/server/players.js +6 -1
  23. package/kits/hub-game/code/server/standing.js +7 -3
  24. package/kits/hub-game/code/systems/hub.js +11 -3
  25. package/kits/hub-game/docs/contract.md +25 -4
  26. package/kits/hub-game/scripts/test-ballot.mjs +1 -1
  27. package/kits/hub-game/scripts/test-hub-trip.mjs +24 -0
  28. package/kits/hub-game/scripts/test-pad-cues.mjs +39 -0
  29. package/kits/hub-game/scripts/test-placeat-server.mjs +259 -6
  30. package/kits/hub-game/scripts/test-rehello.mjs +5 -3
  31. package/kits/hub-game/scripts/test-standing.mjs +135 -2
  32. package/kits/hub-game/scripts/test-stuck.mjs +5 -1
  33. package/kits/hub-game/scripts/test-visibility.mjs +54 -0
  34. package/kits/multiplayer-3d/castle.json +1 -1
  35. package/kits/multiplayer-3d/code/client/resumeGate.js +18 -1
  36. package/kits/multiplayer-3d/code/systems/multiplayer.js +41 -7
  37. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +226 -0
  38. package/kits/physics-3d/castle.json +1 -1
  39. package/kits/physics-3d/package.json +1 -1
  40. package/kits/physics-3d/scripts/test-coaxial-escape.mjs +176 -0
  41. package/kits/physics-3d/systems/physics3d.js +8 -0
  42. package/package.json +1 -1
package/dist/save-deck.js CHANGED
@@ -534,11 +534,28 @@ async function storeMediaAsset(deckId, asset, busyRetryMs) {
534
534
  // write. Each newly stored asset is fetched once through the CDN, these waits
535
535
  // apart, before a page naming it is published.
536
536
  export const ASSET_SERVED_RETRY_MS = [1000, 2000];
537
+ // A deck reads an asset cross-origin (fetch, a CORS <img>, Web Audio), so served
538
+ // means served with CORS: asked with an Origin, as the deck's browser asks.
539
+ const ASSET_PROBE_ORIGIN = 'https://castle.xyz';
540
+ const servedWithCors = (res) => (res.status === 200 || res.status === 206) && res.headers.get('access-control-allow-origin') === '*';
537
541
  async function assetServed(url) {
538
542
  try {
539
- const res = await fetch(url, { headers: { Range: 'bytes=0-0' }, signal: AbortSignal.timeout(15_000) });
543
+ const res = await fetch(url, {
544
+ headers: { Range: 'bytes=0-0', Origin: ASSET_PROBE_ORIGIN },
545
+ signal: AbortSignal.timeout(15_000),
546
+ });
540
547
  await res.body?.cancel();
541
- return res.status === 200 || res.status === 206;
548
+ return servedWithCors(res);
549
+ }
550
+ catch {
551
+ return false;
552
+ }
553
+ }
554
+ /** An asset already stored and served with CORS (HEAD); anything else is stored again and probed. */
555
+ async function assetAlreadyServed(url) {
556
+ try {
557
+ const res = await fetch(url, { method: 'HEAD', headers: { Origin: ASSET_PROBE_ORIGIN }, signal: AbortSignal.timeout(15_000) });
558
+ return res.status === 200 && servedWithCors(res);
542
559
  }
543
560
  catch {
544
561
  return false;
@@ -575,7 +592,7 @@ export async function uploadMediaAssets(deckId, assets, { busyRetryMs = CHUNK_BU
575
592
  result.refused.push({ asset, code: ASSET_TOO_LARGE });
576
593
  return;
577
594
  }
578
- if (await alreadyStored(asset.url)) {
595
+ if (await assetAlreadyServed(asset.url)) {
579
596
  result.skipped++;
580
597
  return;
581
598
  }
@@ -82,7 +82,7 @@
82
82
  "title": "base",
83
83
  "deckId": "yRcmH4_aYllE",
84
84
  "cardId": "zkFdingmIm3m",
85
- "publishedVersion": "2026-11-15T00:40:25.157Z",
85
+ "publishedVersion": "2026-11-18T02:15:05.726Z",
86
86
  "provides": [
87
87
  "castle-web-sdk"
88
88
  ]
@@ -2018,6 +2018,13 @@ window.addEventListener("touchstart", (event) => {
2018
2018
  });
2019
2019
  ```
2020
2020
 
2021
+ To open it without changing the deck, the deck's owner adds `?debug=1`
2022
+ to the deck's address on castle.xyz (`https://castle.xyz/d/<deck id>?debug=1`).
2023
+ The page checks that the signed-in viewer owns the deck, and only then
2024
+ opens the console as the deck starts; anyone else gets the deck as
2025
+ usual. It needs a deck saved with SDK 0.4.56 or later, and it works on
2026
+ the website only. In the Castle app, use `DebugConsole.show()`.
2027
+
2021
2028
  ## Setup
2022
2029
 
2023
2030
  Startup, editor-mode check, and a file-write call for editor UI.
@@ -13,6 +13,11 @@ export interface CastleEmbed {
13
13
  * `experiments.get` command instead (experiments.ts).
14
14
  */
15
15
  experiments?: Record<string, string>;
16
+ /**
17
+ * Opens `DebugConsole` as the deck starts. castle.xyz sets it only for the
18
+ * deck's owner, when they add `?debug=1` to the deck's URL.
19
+ */
20
+ debugConsole?: boolean;
16
21
  }
17
22
  declare global {
18
23
  interface Window {
@@ -10,6 +10,7 @@ export interface DebugConsoleApi {
10
10
  hide(): void;
11
11
  lines(): DebugConsoleLine[];
12
12
  }
13
+ export declare const originalConsole: Record<DebugConsoleLevel, (...args: unknown[]) => void>;
13
14
  export declare function formatConsoleArgs(args: unknown[]): string;
14
15
  export declare function recordConsoleLine(level: DebugConsoleLevel, text: string): void;
15
16
  export declare function noteConsoleHooked(): void;
@@ -6,6 +6,10 @@
6
6
  // `setup()` records every console line and uncaught error from the start, so
7
7
  // `show()` reveals what happened before it was called. A deck that never calls
8
8
  // `setup()` gets recording from its first `show()` on.
9
+ //
10
+ // The host can also open it without any deck code (`openForHost` below): on
11
+ // castle.xyz the deck's owner adds `?debug=1` to the deck's URL.
12
+ import { getCastleEmbed } from "./context";
9
13
  const MAX_LINES = 300;
10
14
  const MAX_LINE_CHARS = 2000;
11
15
  const COLORS = {
@@ -13,27 +17,49 @@ const COLORS = {
13
17
  warn: "#ffd66b",
14
18
  error: "#ff8a80",
15
19
  };
20
+ // The console as it was before anything here or in runtime.ts wrapped it.
21
+ // runtime.ts writes through these, so a line is never recorded twice when the
22
+ // host opened the console before the deck called `setup()`.
23
+ export const originalConsole = {
24
+ log: console.log,
25
+ warn: console.warn,
26
+ error: console.error,
27
+ };
16
28
  const recorded = [];
17
29
  let consoleHooked = false;
18
30
  let errorsHooked = false;
19
31
  let panel = null;
20
32
  let list = null;
21
- export function formatConsoleArgs(args) {
22
- return args
23
- .map((arg) => {
33
+ // Never throws, and always a string: a console call the deck makes must not
34
+ // fail because of what it logged (a cyclic object with no prototype, a revoked
35
+ // proxy, an Error whose stack is not a string).
36
+ const UNPRINTABLE = "[unprintable]";
37
+ function formatConsoleArg(arg) {
38
+ try {
24
39
  if (typeof arg === "string")
25
40
  return arg;
26
- if (arg instanceof Error)
27
- return arg.stack || arg.message;
28
- try {
29
- const json = JSON.stringify(arg);
30
- return json ?? String(arg);
41
+ if (arg instanceof Error) {
42
+ const text = arg.stack || arg.message;
43
+ if (typeof text === "string")
44
+ return text;
31
45
  }
32
- catch {
33
- return String(arg);
34
- }
35
- })
36
- .join(" ");
46
+ const json = JSON.stringify(arg);
47
+ if (typeof json === "string")
48
+ return json;
49
+ }
50
+ catch {
51
+ // fall through to String()
52
+ }
53
+ try {
54
+ const text = String(arg);
55
+ return typeof text === "string" ? text : UNPRINTABLE;
56
+ }
57
+ catch {
58
+ return UNPRINTABLE;
59
+ }
60
+ }
61
+ export function formatConsoleArgs(args) {
62
+ return args.map(formatConsoleArg).join(" ");
37
63
  }
38
64
  // runtime.ts's own console hook calls this, so the line is formatted once for
39
65
  // both the dev serve and this buffer.
@@ -74,6 +100,8 @@ function hookConsole() {
74
100
  return;
75
101
  consoleHooked = true;
76
102
  for (const level of ["log", "warn", "error"]) {
103
+ // The console as it is now, so a wrapper the deck installed before
104
+ // calling show() keeps getting its lines.
77
105
  const original = console[level];
78
106
  console[level] = (...args) => {
79
107
  original(...args);
@@ -131,8 +159,12 @@ function show() {
131
159
  return;
132
160
  hookConsole();
133
161
  captureErrors();
134
- if (panel)
162
+ if (panel?.isConnected)
135
163
  return;
164
+ // A deck that replaces the body (innerHTML, replaceChildren) takes the
165
+ // panel with it; draw a new one.
166
+ panel?.remove();
167
+ panel = null;
136
168
  panel = buildPanel();
137
169
  (document.body ?? document.documentElement).appendChild(panel);
138
170
  for (const line of recorded) {
@@ -143,6 +175,7 @@ function show() {
143
175
  }
144
176
  }
145
177
  function hide() {
178
+ stopKeepingOpen();
146
179
  panel?.remove();
147
180
  panel = null;
148
181
  list = null;
@@ -152,3 +185,43 @@ export const DebugConsole = {
152
185
  hide,
153
186
  lines: () => recorded.slice(),
154
187
  };
188
+ // The host decides who sees the console: castle.xyz sets
189
+ // `CastleEmbed.debugConsole` only when the viewer who added `?debug=1` owns the
190
+ // deck (castle-www DeckPlayer). It is in the document before any deck script,
191
+ // so recording starts with the deck. Nothing here reads the deck's own URL:
192
+ // anyone can add a query string, only the host knows who is watching. A deck
193
+ // that sets the flag itself only shows its own console to its own players.
194
+ //
195
+ // Opened this way, the panel comes back when the deck's own startup clears the
196
+ // body (or replaces it), until the owner presses Hide.
197
+ let keepOpen = null;
198
+ function stopKeepingOpen() {
199
+ keepOpen?.disconnect();
200
+ keepOpen = null;
201
+ }
202
+ function openForHost() {
203
+ if (typeof document === "undefined" || getCastleEmbed()?.debugConsole !== true)
204
+ return;
205
+ hookConsole();
206
+ captureErrors();
207
+ const open = () => {
208
+ show();
209
+ if (keepOpen || typeof MutationObserver === "undefined")
210
+ return;
211
+ keepOpen = new MutationObserver(() => {
212
+ if (panel && !panel.isConnected)
213
+ show();
214
+ });
215
+ keepOpen.observe(document.documentElement, { childList: true, subtree: true });
216
+ };
217
+ // A classic script in the head runs before there is a body to draw into.
218
+ // A module deck runs once the document is parsed, still ahead of its own
219
+ // first pass over the body: the observer puts the panel back after that.
220
+ if (document.readyState === "loading") {
221
+ document.addEventListener("DOMContentLoaded", open, { once: true });
222
+ }
223
+ else {
224
+ open();
225
+ }
226
+ }
227
+ openForHost();
@@ -1,6 +1,6 @@
1
1
  import { CASTLE_SDK_PROTOCOL, } from "./commands";
2
2
  import { getCastleEmbed, isEdit } from "./context";
3
- import { captureErrors, formatConsoleArgs, noteConsoleHooked, recordConsoleLine } from "./debugConsole";
3
+ import { captureErrors, formatConsoleArgs, noteConsoleHooked, originalConsole, recordConsoleLine, } from "./debugConsole";
4
4
  import { cardUnit, fitStage, getDisplay } from "./display";
5
5
  import { appliedNotice, applyTunedParams, } from "./paramsRegistry";
6
6
  export const CARD_RATIO = 5 / 7;
@@ -20,9 +20,10 @@ const pendingRequests = new Map();
20
20
  // screenshot/write_file request map above. transport.ts owns the timeouts.
21
21
  const SOCKET_WAIT_TIMEOUT_MS = 10000;
22
22
  const localCommandListeners = new Map();
23
- const origLog = console.log;
24
- const origWarn = console.warn;
25
- const origError = console.error;
23
+ // Not `console.log` itself: the host may have had debugConsole.ts wrap it already.
24
+ const origLog = originalConsole.log;
25
+ const origWarn = originalConsole.warn;
26
+ const origError = originalConsole.error;
26
27
  // Indirected dynamic import so deck bundlers don't statically rewrite it.
27
28
  // eslint-disable-next-line @typescript-eslint/no-implied-eval
28
29
  const dynamicImport = new Function("u", "return import(u)");
@@ -205,7 +205,8 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
205
205
  // scores. A tap on the board, or walking away, closes it. Over the labels,
206
206
  // so a pad's words never cut through a row; it is never drawn during a
207
207
  // trip, so the door cover needs not hide it.
208
- const cabinet = el('div', { position: 'absolute', display: 'none', transform: 'translate(-50%, -100%)', boxSizing: 'border-box', background: 'rgba(18,14,24,0.92)', border: '1px solid rgba(255,255,255,0.18)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)', font: '600 13px/1.25 system-ui, sans-serif', cursor: 'pointer', touchAction: 'manipulation', userSelect: 'none' }, root);
208
+ const CABINET_CHIP_PAINT = 'rgba(18,14,24,0.92)', CABINET_BOARD_PAINT = 'rgb(18,14,24)';
209
+ const cabinet = el('div', { position: 'absolute', display: 'none', transform: 'translate(-50%, -100%)', boxSizing: 'border-box', background: CABINET_CHIP_PAINT, border: '1px solid rgba(255,255,255,0.18)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)', font: '600 13px/1.25 system-ui, sans-serif', cursor: 'pointer', touchAction: 'manipulation', userSelect: 'none' }, root);
209
210
  cabinet.dataset.hub = 'cabinet';
210
211
  let cabinetKey = '';
211
212
  // Whose board this player opened, if any: one at a time (`cabinets.js`).
@@ -247,7 +248,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
247
248
  if (!best) {
248
249
  return false;
249
250
  }
250
- Object.assign(cabinet.style, { width: 'auto', padding: '3px 9px 3px 4px', borderRadius: '15px', pointerEvents: 'auto' });
251
+ Object.assign(cabinet.style, { width: 'auto', padding: '3px 9px 3px 4px', borderRadius: '15px', pointerEvents: 'auto', background: CABINET_CHIP_PAINT });
251
252
  cabinet.setAttribute('role', 'button');
252
253
  cabinet.setAttribute('aria-label', `${card.title || 'Arcade'}: show the scores`);
253
254
  const line = el('div', { display: 'flex', alignItems: 'center', gap: '7px', fontSize: '12px', whiteSpace: 'nowrap' }, cabinet);
@@ -260,7 +261,8 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
260
261
  }
261
262
  function buildCabinetBoard(card, imageOf) {
262
263
  cabinet.replaceChildren();
263
- Object.assign(cabinet.style, { width: '204px', padding: '10px', borderRadius: '12px', pointerEvents: 'auto' });
264
+ // v1.217: opaque, so no plate or area label under it shows through a row.
265
+ Object.assign(cabinet.style, { width: '204px', padding: '10px', borderRadius: '12px', pointerEvents: 'auto', background: CABINET_BOARD_PAINT });
264
266
  cabinet.setAttribute('role', 'button');
265
267
  cabinet.setAttribute('aria-label', `${card.title || 'Arcade'}: hide the scores`);
266
268
  const head = el('div', { display: 'flex', gap: '10px', alignItems: 'center' }, cabinet);
@@ -2262,7 +2264,9 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
2262
2264
  setPadContext(item) {
2263
2265
  const blocked = pickerOpen || sayOpen || emotesOpen || peopleOpen || doorsOpen || talkOpen ||
2264
2266
  !!textAsk?.card || !!placeMenu?.sheet || sound?.open || actionOverflow?.isOpen?.() ||
2265
- externalEntries().some(([, surface]) => surface.kind === 'card' && shownRect(surface.node));
2267
+ externalEntries().some(([, surface]) => surface.kind === 'card' && shownRect(surface.node)) ||
2268
+ // v1.217: an open cabinet board is read whole; the plate waits under it.
2269
+ (cabinet.style.display !== 'none' && cabinet.dataset.drawn === 'board');
2266
2270
  if (!item || blocked) {
2267
2271
  if (padContext && padContext.node.style.visibility !== 'hidden') {padContext.node.style.visibility = 'hidden';}
2268
2272
  return;
@@ -15,7 +15,7 @@ export function collectPadCues(actors, hidden) {
15
15
  const doors = new Map();
16
16
  for (const actor of actors) {
17
17
  const door = actor.components?.HubDoor;
18
- if (door) {doors.set(door.id, door.title);}
18
+ if (door) {doors.set(door.id, door);}
19
19
  }
20
20
  const cues = [];
21
21
  for (const actor of actors) {
@@ -27,7 +27,8 @@ export function collectPadCues(actors, hidden) {
27
27
  const shape = c.Shape;
28
28
  cues.push({ id: actor.id, x: c.Transform.x, z: c.Transform.z, radius: spec.radius,
29
29
  y: (c.Transform.y ?? 0) + (shape?.kind === 'cylinder' ? (shape.height ?? 1) / 2 : 0) + 0.03,
30
- title: explicit ? spec.title : doors.get(spec.door), door: !explicit,
30
+ title: explicit ? spec.title : doors.get(spec.door)?.title, door: !explicit,
31
+ cabinet: !explicit && doors.get(spec.door)?.kind === 'cabinet',
31
32
  color: shape?.color ?? '#d9a441' });
32
33
  }
33
34
  return cues;
@@ -53,9 +54,12 @@ export function selectPadCue(cues, body, current = null) {
53
54
  return cue ? { cue, on: edge(cue, body) <= 0 } : null;
54
55
  }
55
56
 
56
- export function padContextText(active) {
57
- return active?.cue.title ? { id: active.cue.id, title: active.cue.title,
58
- secondary: !active.on && active.cue.door ? 'Step on to join' : '' } : null;
57
+ // v1.217: a guest (signed out, or an anonymous visitor) cannot play a
58
+ // cabinet's classic deck, so its plate says so rather than inviting a step.
59
+ export function padContextText(active, guest = false) {
60
+ if (!active?.cue.title) {return null;}
61
+ const secondary = guest && active.cue.cabinet ? 'Sign in to play' : !active.on && active.cue.door ? 'Step on to join' : '';
62
+ return { id: active.cue.id, title: active.cue.title, secondary };
59
63
  }
60
64
 
61
65
  // Called each frame, but unchanged inputs allocate nothing and do not select
@@ -73,11 +77,11 @@ export function makePadCueTracker() {
73
77
  const hidden = hiddenNow?.has(actor.id) === true;
74
78
  if (!r || r.actor !== actor || !Object.is(r.x, t?.x) || !Object.is(r.y, t?.y) || !Object.is(r.z, t?.z) ||
75
79
  !Object.is(r.radius, p?.radius) || r.door !== p?.door || r.explicit !== Object.hasOwn(c, 'HubPadCue') ||
76
- !Object.is(r.cueRadius, q?.radius) || r.title !== q?.title || r.doorId !== d?.id || r.doorTitle !== d?.title ||
80
+ !Object.is(r.cueRadius, q?.radius) || r.title !== q?.title || r.doorId !== d?.id || r.doorTitle !== d?.title || r.doorKind !== d?.kind ||
77
81
  r.kind !== s?.kind || !Object.is(r.height, s?.height) || r.color !== s?.color || r.hidden !== hidden) {
78
82
  r = { actor, x: t?.x, y: t?.y, z: t?.z, radius: p?.radius, door: p?.door,
79
83
  explicit: Object.hasOwn(c, 'HubPadCue'), cueRadius: q?.radius, title: q?.title, doorId: d?.id,
80
- doorTitle: d?.title, kind: s?.kind, height: s?.height, color: s?.color, hidden };
84
+ doorTitle: d?.title, doorKind: d?.kind, kind: s?.kind, height: s?.height, color: s?.color, hidden };
81
85
  records[count] = r; dirty = true;
82
86
  }
83
87
  count += 1;
@@ -8,13 +8,13 @@ export function makePadReadability(engine, options) {
8
8
  const tracker = engine.hubPadContext === true || engine.hubPadRing === true ? makePadCueTracker() : null;
9
9
  const rings = engine.hubPadRing === true || engine.hubSpawnRing === true
10
10
  ? makePadRings(world, { active: engine.hubPadRing === true, arrival: engine.hubSpawnRing === true ? arrival : null }) : null;
11
- let previous = null, text = null;
11
+ let previous = null, previousGuest = false, text = null;
12
12
  return {
13
- frame(actors, hidden, body, traveling, captionBlocked = false) {
13
+ frame(actors, hidden, body, traveling, captionBlocked = false, guest = false) {
14
14
  const active = tracker?.frame(actors, hidden, body) ?? null;
15
15
  rings?.frame(traveling ? null : active?.cue);
16
16
  if (engine.hubPadContext === true) {
17
- if (active !== previous) {text = padContextText(active); previous = active;}
17
+ if (active !== previous || guest !== previousGuest) {text = padContextText(active, guest); previous = active; previousGuest = guest;}
18
18
  chrome.setPadContext(traveling || captionBlocked ? null : text);
19
19
  }
20
20
  },
@@ -4,11 +4,16 @@ export function makeVisibility(doc = globalThis.document, now = Date.now) {
4
4
  let target = null;
5
5
  let last = null;
6
6
  let listening = false;
7
+ // v1.219: a connection that is not up forgets what was last sent. A send
8
+ // into a socket that died (an app switch) reads as sent; after the rejoin
9
+ // the state is sent again, so the server never keeps a stale hidden.
10
+ const down = () => Boolean(target.net.closed?.() || (target.net.status && target.net.status().state !== 'connected'));
7
11
  const changed = () => {
8
- if (!target || target.net.closed?.()) {
12
+ if (!target) {
9
13
  return;
10
14
  }
11
- if (target.net.status && target.net.status().state !== 'connected') {
15
+ if (down()) {
16
+ last = null;
12
17
  return;
13
18
  }
14
19
  const visible = doc.visibilityState !== 'hidden';
@@ -19,7 +24,9 @@ export function makeVisibility(doc = globalThis.document, now = Date.now) {
19
24
  last = visible;
20
25
  };
21
26
  return {
22
- sync(net, key, enabled) {
27
+ // `admitted`: the hub's count of this connection's re-admissions; a
28
+ // rejoin between two frames, never seen as down, sends again too.
29
+ sync(net, key, enabled, admitted = 0) {
23
30
  if (!enabled || !net || !doc?.addEventListener) {
24
31
  if (listening) {
25
32
  doc.removeEventListener('visibilitychange', changed);
@@ -30,7 +37,10 @@ export function makeVisibility(doc = globalThis.document, now = Date.now) {
30
37
  return;
31
38
  }
32
39
  if (target?.net !== net || target?.key !== key) {
33
- target = { net, key };
40
+ target = { net, key, admitted };
41
+ last = null;
42
+ } else if (target.admitted !== admitted) {
43
+ target.admitted = admitted;
34
44
  last = null;
35
45
  }
36
46
  if (!listening) {