castle-web-cli 0.4.241 → 0.4.243

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.
@@ -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-18T04:23:12.485Z",
86
86
  "provides": [
87
87
  "castle-web-sdk"
88
88
  ]
@@ -233,7 +233,8 @@ dev serve.
233
233
  - `session.hub.place`, `.title` and `.result` are the place and the result shape
234
234
  as published (`result` is `null` for a place that reports none, such as a town).
235
235
  - `session.hub.reconnectWindowMs`, when present, is Castle's pinned hub-place
236
- reconnect grace in milliseconds, inclusive at the deadline. It is absent on
236
+ reconnect grace in milliseconds, inclusive at the deadline (at most 180000, or
237
+ 300000 on an owner house that opted into `houseResume`). It is absent on
237
238
  sessions without a pinned grace and older hosts. Kits use it to match visit retention to the
238
239
  transport window; deck code does not choose it.
239
240
  - `session.hub.arrival(playerId)` is how a player came in when Castle placed them
@@ -2018,6 +2019,13 @@ window.addEventListener("touchstart", (event) => {
2018
2019
  });
2019
2020
  ```
2020
2021
 
2022
+ To open it without changing the deck, the deck's owner adds `?debug=1`
2023
+ to the deck's address on castle.xyz (`https://castle.xyz/d/<deck id>?debug=1`).
2024
+ The page checks that the signed-in viewer owns the deck, and only then
2025
+ opens the console as the deck starts; anyone else gets the deck as
2026
+ usual. It needs a deck saved with SDK 0.4.56 or later, and it works on
2027
+ the website only. In the Castle app, use `DebugConsole.show()`.
2028
+
2021
2029
  ## Setup
2022
2030
 
2023
2031
  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)");
@@ -46,9 +46,13 @@ function unavailable(op, what) {
46
46
  operation: `session.hub.${op}`,
47
47
  });
48
48
  }
49
+ // An opted-in owner house may be pinned up to 300 s (a three-minute app switch keeps
50
+ // it); every other hub place keeps the host's 180 s cap.
49
51
  function reconnectMetadata(pinned) {
50
52
  const value = pinned.reconnectWindowMs;
51
- return pinned.result === null && typeof value === "number" && Number.isInteger(value) && value > 0 && value <= 180_000
53
+ const cap = pinned.houseResume === true && typeof pinned.owner === "string" && pinned.owner.length > 0
54
+ ? 300_000 : 180_000;
55
+ return pinned.result === null && typeof value === "number" && Number.isInteger(value) && value > 0 && value <= cap
52
56
  ? { reconnectWindowMs: value } : {};
53
57
  }
54
58
  export function createServerHub(platformHandle, arrivals, hiddenPair = () => false) {
@@ -126,6 +126,8 @@ export interface PlatformHubPlace {
126
126
  version: 1;
127
127
  };
128
128
  owner?: string;
129
+ /** Ghost's trusted owner-house opt-in; such a house may pin up to 300 s of grace. */
130
+ houseResume?: true;
129
131
  reconnectWindowMs?: number;
130
132
  place?: string;
131
133
  title?: string | null;
@@ -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) {
@@ -424,9 +424,10 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
424
424
  typeof data.visible !== 'boolean' || !Number.isFinite(data.at) || data.at < 0) {
425
425
  return;
426
426
  }
427
- if (entry.visibility && (data.at < entry.visibility.at || data.visible === entry.visibility.visible)) {
427
+ if (entry.visibility && (data.at < entry.visibility.at || (data.visible === entry.visibility.visible && !entry.visibilityRejoined))) {
428
428
  return;
429
429
  }
430
+ delete entry.visibilityRejoined;
430
431
  entry.visibility = { visible: data.visible, at: data.at };
431
432
  entry.visibilityPending = true;
432
433
  notifyVisibility(h, player.playerId);
@@ -1549,7 +1550,9 @@ function hello(h, player, data, synthetic = false) {
1549
1550
  !accountProgressBlocked(h, progressUser);
1550
1551
  const entry = {
1551
1552
  // Who this is, kept for `leave`: by then the session has forgotten them.
1552
- ...(h.place.visibility === true && known?.visibility ? { visibility: known.visibility, visibilityPending: known.visibilityPending } : {}),
1553
+ // v1.219: a rejoin's first signal is taken even when it repeats the kept
1554
+ // value: the client may have sent its change into the socket that died.
1555
+ ...(h.place.visibility === true && known?.visibility ? { visibility: known.visibility, visibilityPending: known.visibilityPending, ...(data.again !== true ? { visibilityRejoined: true } : known.visibilityRejoined ? { visibilityRejoined: true } : {}) } : {}),
1553
1556
  userId: progressUser,
1554
1557
  ...((known || poseBack) && claimedPose ? { arrivalPose: { ...claimedPose, userId: poseOwner } } : {}),
1555
1558
  username: usernameOf(h, player.playerId),
@@ -646,7 +646,7 @@ class HubSystem {
646
646
  }
647
647
  if (Hub.hub.place?.visibility === true || this.visibility) {
648
648
  this.visibility ??= makeVisibility();
649
- this.visibility.sync(mp.net, this.sceneKey, Hub.hub.place?.visibility === true && !this.trip);
649
+ this.visibility.sync(mp.net, this.sceneKey, Hub.hub.place?.visibility === true && !this.trip, this.admitEpoch ?? 0);
650
650
  }
651
651
  const held = Hub.hub.held.has(mp.net?.selfId?.());
652
652
  const fallY = activeFallY(Hub.hub.place?.fallY, held, Boolean(this.trip));
@@ -1748,6 +1748,7 @@ class HubSystem {
1748
1748
  // cover, and what the page holds is the place as it was before they left:
1749
1749
  // the way back starts under the trip's cover, with no door beat over it.
1750
1750
  const covered = mp.returning?.() === true;
1751
+ const placeTitle = Hub.hub.place?.title;
1751
1752
  Hub.clear();
1752
1753
  if (inGame && scene.persistent.hubTickets.length) {
1753
1754
  this.toast = { text: 'The game ended', until: performance.now() + TOAST_MS };
@@ -1760,8 +1761,14 @@ class HubSystem {
1760
1761
  } else if (!inGame && !refused && mp.target?.mode === 'hub') {
1761
1762
  console.warn('[hub-door] this place ended under a hub join behind a door: leaving by its way back');
1762
1763
  const title = scene.persistent.hubTickets.at(-1)?.title;
1764
+ // Seen on coming back from away, the place most likely ended because it
1765
+ // stood empty past its reconnect window (an owner's House left alone),
1766
+ // not because a new version was saved: say what the player can know.
1767
+ const ended = covered
1768
+ ? `${placeTitle || 'This place'} closed while you were away.`
1769
+ : 'This place was updated.';
1763
1770
  this.toast = {
1764
- text: title ? `This place was updated. Back to ${title}…` : 'This place was updated. Going back…',
1771
+ text: title ? `${ended} Back to ${title}…` : `${ended} Going back…`,
1765
1772
  until: performance.now() + TOAST_MS,
1766
1773
  };
1767
1774
  this.back(scene, { covered });
@@ -721,7 +721,11 @@ suppressed. The chip fits within 94vw and its personal line ellipsizes.
721
721
  server stopped): a game is left as before ("The game ended", then its way
722
722
  back); any other place reached through a door (the host's trail holds the
723
723
  trip) is left by its way back at once, with a line saying it was updated
724
- ("This place was updated. Back to <the place left>…"), and is entered again
724
+ ("This place was updated. Back to <the place left>…"), or, when the ending
725
+ is seen as the player comes back from away (`multiplayer.returning()`), that
726
+ it closed while they were away (v1.220; "<this place's title> closed while you
727
+ were away. Back to <the place left>…"; an owner's House left empty past its
728
+ reconnect window ends this way, nothing was saved), and is entered again
725
729
  through its door, which acquires the new version and its content. A join
726
730
  cannot be made again from inside such a place: its handoff is spent, and
727
731
  only a door's acquisition names the release to mount. The way back is asked
@@ -3685,7 +3689,10 @@ the deck's arrival hook. The kit calls the optional server hook
3685
3689
  The sender identity comes from the session; a payload cannot name another player.
3686
3690
  Malformed, duplicate-state and older-timestamp messages are ignored. `at` is
3687
3691
  untrusted metadata, never server simulation time or proof of elapsed time.
3688
- A place may pause its own guidance clocks while hidden and restore its UI on
3692
+ After any reconnect (v1.219) the client sends its current state again, and
3693
+ the server delivers a retained rejoin's first signal even when it repeats the
3694
+ kept value, so a change sent into a socket that died unseen is not lost and a
3695
+ place never keeps a stale hidden or visible. A place may pause its own guidance clocks while hidden and restore its UI on
3689
3696
  visible. This does not itself reconnect, arrive, leave or change progression;
3690
3697
  the existing `resume` hook remains independent.
3691
3698
 
@@ -5305,6 +5312,8 @@ a deck written before them remains valid.
5305
5312
 
5306
5313
  | date | change |
5307
5314
  | --- | --- |
5315
+ | 2026-11-18 (v1.220) | §"A place replaced under its players" copy: when the ending is seen as the player comes back from away (`multiplayer.returning()`), the line is "<this place's title> closed while you were away. Back to <the place left>…" ("This place closed while you were away…" with no title) instead of "This place was updated", which was not true for an owner's House left empty past its reconnect window. A player who was present still sees the updated line. Copy only: no key, API or wire change. |
5316
+ | 2026-11-18 (v1.219) | §12 page visibility after a rejoin: a client whose connection is not up forgets the state it last sent and sends its current state once it is connected again (a send into a socket that died unseen, as on an app switch, no longer leaves the server holding a stale hidden); the server takes a rejoin's first `hub-visibility` even when it repeats the kept value, then coalesces as before. An avatar-change hello is not a rejoin. No new key or wire field. |
5308
5317
  | 2026-11-17 (v1.218) | Kit-internal, server only, no deck-facing key or API and no wire change: §5 two bodies never start on one spot. A body admitted with no pose where another body takes the scene spawn or the slot its lone arrival would take starts where that arrival will put it (the arrival slot if free, else the free spot beside it; one helper decides both) before its WORLD goes out, so that WORLD is the one placement its client makes, at once; arriving alone it stays there while the spot is still free, and a group with such a member takes the row's slots in the order its members stand along it. An arrival slot (an arrival, and the arrival a fall or a Stuck? unstick puts a player at) or stored pose (cold `resumePose`, arrival pose, retained visit) that another body takes is likewise stepped off on every place, not only on authored floors (`ground.none: true`); a free slot or pose is used exactly. A body takes a spot when it is nearer than two radii and overlaps it in height (one on a floor above or below does not), and only while its player is on the roster (real-time admits a joiner before it removes the bodies of players who left that tick). A group row's later slots are held where a body would stand in them. The search uses the place's own body size and treats a spot past the ground slab's edge (`ground.half`, 100 m by default) as unsupported unless an authored solid holds it; when every candidate fails the slot is shared, as before. Ground-backed places (the Town) kept the spawn for everyone, so two lone joiners stood on exactly the same point; on each client the two capsules were coaxial, Rapier pushed the local one into the ground under the other's avatar, and it could not walk until one left (Nov 17 Market check, reproduced locally). A stepped-off cold restore still reaches its client as the restore always has. Tests: `test-placeat-server` stepoff, arrivalFree and arrivalTaken (WORLD before hello, reports and corrections on: the client moves once), restoreFree, restoreOccupied; `test-standing` slab edge, floors, a leaver on the same tick and an elevated row, `test-rehello` and `test-stuck` updated; physics-3d `test-coaxial-escape`. |
5309
5318
  | 2026-11-10 | `hub.loadingCover` copy and timing: a return's cover (backgrounded 30 s or more, or a dropped connection, after the first load lifted) is plain black, with no title, words or spinner, while hidden and for its first 2.5 s after the page shows; then it says "Reconnecting…" with the spinner. The first load keeps the deck title. The multiplayer-3d kit's return cover is quiet for the same 2.5 s. Most returns are back sooner (measured 2.1-2.4 s past a 180 s app switch). No wire change. Within `hub.contract: 1`. |
5310
5319
  | 2026-11-10 | Kit-internal, no deck-facing key or API: a connection that comes back under a new player id on the same page (a drop past the place's hold, such as 180 s backgrounded) keeps the camera yaw and the avatar's facing through the new session's `hub-arrived`, instead of turning to the arrival facing (the Town turned every such return to its spawn bearing). A trip's arrival, the first join and an arrival on another connection face as before. Within `hub.contract: 1`. |
@@ -5575,7 +5584,11 @@ for a place without a result. Ghost grants it to the host only on a trusted
5575
5584
  owner-house instance. Key absent keeps existing manifest and wire bytes.
5576
5585
 
5577
5586
  Ghost stamps the grace value `reconnectWindowMs: 180000` into the owner-house
5578
- session spec. A capable host retains each disconnected participant and token
5587
+ session spec, or `300000` when the chosen host advertises
5588
+ `supportsHouseResumeWindowMs: 300000` (so an owner's three-minute app switch,
5589
+ whose socket closes a few seconds after the page hides, keeps the house); the
5590
+ base SDK passes a value up to 300000 to `session.hub.reconnectWindowMs` only on
5591
+ such an owner house, and every other place keeps the 180000 cap. A capable host retains each disconnected participant and token
5579
5592
  through that deadline and keeps an empty opted-in house alive for that window. A guest reconnect is
5580
5593
  admitted only into that same live instance while its owner has a live connection;
5581
5594
  otherwise the existing spent-handoff recovery returns through the Town ticket.
@@ -960,10 +960,34 @@ await test('a place behind a door whose server is replaced under a player: left
960
960
  system.lastNet = closedNet();
961
961
  system.watchSession(scene, scene.multiplayer);
962
962
  assert.ok(system.trip, `${place.title}: on its way back`);
963
+ assert.equal(system.toast.text, place.result
964
+ ? 'The game ended'
965
+ : `${place.title} closed while you were away. Back to Town…`);
963
966
  system.stepTrip(scene, scene.multiplayer, null, performance.now());
964
967
  assert.equal(covers[0], 1, `${place.title}: the first cover drawn is fully down`);
965
968
  await flush();
966
969
  }
970
+ // An owner's House torn down while they were away (empty past its reconnect
971
+ // window): the line says it closed, not that it was updated; with no title
972
+ // or no ticket it still reads true.
973
+ for (const [place, tickets, text] of [
974
+ [{ title: 'House' }, undefined, 'House closed while you were away. Back to Town…'],
975
+ [{ title: null }, undefined, 'This place closed while you were away. Back to Town…'],
976
+ [{ title: 'House' }, [], 'House closed while you were away. Going back…'],
977
+ ]) {
978
+ const { system, scene } = setup();
979
+ scene.multiplayer = { ...mpStub(scene), net: null, returning: () => true };
980
+ scene.multiplayer.target = { mode: 'hub', handoff: { sessionId: 'house-1' } };
981
+ scene.persistent.hubDepth = 1;
982
+ scene.persistent.hubTickets = tickets ?? [{ scene: 'scenes/main.scene', title: 'Town', door: 'home', hub: true, join: { mode: 'public' } }];
983
+ HubState.hub.place = place;
984
+ answers.back = handoff();
985
+ system.lastNet = closedNet();
986
+ system.watchSession(scene, scene.multiplayer);
987
+ assert.equal(system.toast.text, text);
988
+ assert.ok(system.trip, 'on its way back');
989
+ await flush();
990
+ }
967
991
  // Not returning: the beat plays, and the cover comes down over it.
968
992
  {
969
993
  const { system, scene } = setup();
@@ -131,4 +131,58 @@ assert.deepEqual(mounted, [false, true]);
131
131
  secondClient.sync(null, null, false);
132
132
  shownDoc.visibilityState = 'hidden'; shownDoc.dispatchEvent(new Event('visibilitychange'));
133
133
  assert.deepEqual(mounted, [false, true], 'disposed listener cannot send to its old net');
134
+ // v1.219: an app switch kept the socket while hidden; the return's visible
135
+ // went into the dead socket, which still read connected. After the rejoin
136
+ // the client sends its state again.
137
+ {
138
+ const got = [];
139
+ const doc2 = new EventTarget(); doc2.visibilityState = 'visible';
140
+ let state = 'connected', dead = false;
141
+ const net2 = { status: () => ({ state }), send: (data) => { if (!dead) got.push(data.visible); } };
142
+ const v = makeVisibility(doc2, () => ++at);
143
+ v.sync(net2, 'main', true);
144
+ doc2.visibilityState = 'hidden'; doc2.dispatchEvent(new Event('visibilitychange'));
145
+ dead = true; // the socket died while away, unseen
146
+ doc2.visibilityState = 'visible'; doc2.dispatchEvent(new Event('visibilitychange'));
147
+ state = 'reconnecting'; v.sync(net2, 'main', true);
148
+ dead = false; state = 'connected'; v.sync(net2, 'main', true);
149
+ v.sync(net2, 'main', true);
150
+ assert.deepEqual(got, [true, false, true], 'the rejoin sends visible again, once');
151
+ v.sync(null, null, false);
152
+ }
153
+ // v1.219: a rejoin between two frames is never seen as down; the hub's
154
+ // re-admission count says it, and the state is sent again.
155
+ {
156
+ const got = [];
157
+ const doc3 = new EventTarget(); doc3.visibilityState = 'visible';
158
+ let dead = false;
159
+ const net3 = { status: () => ({ state: 'connected' }), send: (data) => { if (!dead) got.push(data.visible); } };
160
+ const v = makeVisibility(doc3, () => ++at);
161
+ v.sync(net3, 'main', true, 0);
162
+ doc3.visibilityState = 'hidden'; doc3.dispatchEvent(new Event('visibilitychange'));
163
+ dead = true;
164
+ doc3.visibilityState = 'visible'; doc3.dispatchEvent(new Event('visibilitychange'));
165
+ dead = false;
166
+ v.sync(net3, 'main', true, 0);
167
+ assert.deepEqual(got, [true, false], 'no rejoin seen yet');
168
+ v.sync(net3, 'main', true, 1);
169
+ v.sync(net3, 'main', true, 1);
170
+ assert.deepEqual(got, [true, false, true], 'the re-admission sends visible again, once');
171
+ v.sync(null, null, false);
172
+ }
173
+ // v1.219: the server takes a rejoin's first signal even when it repeats the
174
+ // kept value, then coalesces again.
175
+ {
176
+ const seen = [];
177
+ const s = boot({ visibility: true }, { hooks: { visibility(hub, info) { seen.push(info.visible); } } });
178
+ s.tick();
179
+ s.say('p1', { k: 'hub-visibility', visible: false, at: 5000 }); s.tick();
180
+ s.say('p1', { k: 'hub-hello', avatar: 0, resume: true }); s.tick();
181
+ s.say('p1', { k: 'hub-visibility', visible: false, at: 5001 }); s.tick();
182
+ s.say('p1', { k: 'hub-visibility', visible: false, at: 5002 }); s.tick();
183
+ assert.deepEqual(seen, [false, false], 'the first after the rejoin is taken, the next repeat is not');
184
+ s.say('p1', { k: 'hub-hello', avatar: 1, again: true }); s.tick();
185
+ s.say('p1', { k: 'hub-visibility', visible: false, at: 5003 }); s.tick();
186
+ assert.deepEqual(seen, [false, false], 'an avatar change is no rejoin');
187
+ }
134
188
  console.log('test-visibility: ok');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "castle-web-cli",
3
- "version": "0.4.241",
3
+ "version": "0.4.243",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/castle-xyz/castle-experimental-web.git"