castle-web-cli 0.4.162 → 0.4.163

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 (65) hide show
  1. package/dist/devSessionChild.js +23 -0
  2. package/dist/devSessionServer.js +49 -4
  3. package/dist/init.js +1 -1
  4. package/dist/platformDoc.js +2 -1
  5. package/dist/shell/assets/index-BJO7LVCM.js +422 -0
  6. package/dist/shell/index.html +1 -1
  7. package/kits/base/castle.json +1 -1
  8. package/kits/base/package-lock.json +1 -1
  9. package/kits/base/sdk/README.md +12 -1
  10. package/kits/base/sdk/multiplayer.d.ts +2 -0
  11. package/kits/base/sdk/multiplayer.js +59 -16
  12. package/kits/base/sdk/multiplayerProtocol.d.ts +3 -0
  13. package/kits/base/sdk/multiplayerProtocol.js +13 -0
  14. package/kits/base/sdk/server/platformHandle.d.ts +3 -0
  15. package/kits/base/sdk/server/wrapper.d.ts +3 -0
  16. package/kits/base/sdk/server/wrapper.js +42 -0
  17. package/kits/blank/.castle/agent/children.json +1 -0
  18. package/kits/blank/.castle/agent/messages.json +9 -0
  19. package/kits/blank/.castle/agent/pending-sends.json +1 -0
  20. package/kits/blank/.castle/agent/tasks/index.md +2 -0
  21. package/kits/blank/.castle/docs/platform.md +36 -0
  22. package/kits/blank/node_modules/.vite/deps/_metadata.json +8 -0
  23. package/kits/blank/node_modules/.vite/deps/package.json +3 -0
  24. package/package.json +1 -1
  25. package/dist/shell/assets/index--_Rr2xwM.js +0 -441
  26. package/kits/base/node_modules/.package-lock.json +0 -28
  27. package/kits/base/node_modules/castle-web-fonts/README.md +0 -114
  28. package/kits/base/node_modules/castle-web-fonts/dist/catalog.d.ts +0 -18
  29. package/kits/base/node_modules/castle-web-fonts/dist/catalog.js +0 -142
  30. package/kits/base/node_modules/castle-web-fonts/dist/face.d.ts +0 -1
  31. package/kits/base/node_modules/castle-web-fonts/dist/face.js +0 -52
  32. package/kits/base/node_modules/castle-web-fonts/dist/faces/Bore.d.ts +0 -3
  33. package/kits/base/node_modules/castle-web-fonts/dist/faces/Bore.js +0 -10
  34. package/kits/base/node_modules/castle-web-fonts/dist/faces/CourierPrime.d.ts +0 -3
  35. package/kits/base/node_modules/castle-web-fonts/dist/faces/CourierPrime.js +0 -10
  36. package/kits/base/node_modules/castle-web-fonts/dist/faces/DMSans.d.ts +0 -3
  37. package/kits/base/node_modules/castle-web-fonts/dist/faces/DMSans.js +0 -10
  38. package/kits/base/node_modules/castle-web-fonts/dist/faces/Glacier.d.ts +0 -3
  39. package/kits/base/node_modules/castle-web-fonts/dist/faces/Glacier.js +0 -10
  40. package/kits/base/node_modules/castle-web-fonts/dist/faces/HelicoCentrica.d.ts +0 -3
  41. package/kits/base/node_modules/castle-web-fonts/dist/faces/HelicoCentrica.js +0 -10
  42. package/kits/base/node_modules/castle-web-fonts/dist/faces/Piazzolla.d.ts +0 -3
  43. package/kits/base/node_modules/castle-web-fonts/dist/faces/Piazzolla.js +0 -10
  44. package/kits/base/node_modules/castle-web-fonts/dist/faces/Synco.d.ts +0 -3
  45. package/kits/base/node_modules/castle-web-fonts/dist/faces/Synco.js +0 -10
  46. package/kits/base/node_modules/castle-web-fonts/dist/faces/Tektur.d.ts +0 -3
  47. package/kits/base/node_modules/castle-web-fonts/dist/faces/Tektur.js +0 -10
  48. package/kits/base/node_modules/castle-web-fonts/dist/faces/YatraOne.d.ts +0 -3
  49. package/kits/base/node_modules/castle-web-fonts/dist/faces/YatraOne.js +0 -10
  50. package/kits/base/node_modules/castle-web-fonts/dist/index.d.ts +0 -16
  51. package/kits/base/node_modules/castle-web-fonts/dist/index.js +0 -15
  52. package/kits/base/node_modules/castle-web-fonts/licenses/CC-BY-ND-4.0.txt +0 -393
  53. package/kits/base/node_modules/castle-web-fonts/licenses/FONTS.md +0 -64
  54. package/kits/base/node_modules/castle-web-fonts/licenses/OFL-1.1.txt +0 -95
  55. package/kits/base/node_modules/castle-web-fonts/package.json +0 -47
  56. package/kits/base/node_modules/castle-web-fonts/woff2/Bore.woff2 +0 -0
  57. package/kits/base/node_modules/castle-web-fonts/woff2/CourierPrime.woff2 +0 -0
  58. package/kits/base/node_modules/castle-web-fonts/woff2/DMSans.woff2 +0 -0
  59. package/kits/base/node_modules/castle-web-fonts/woff2/Glacier.woff2 +0 -0
  60. package/kits/base/node_modules/castle-web-fonts/woff2/HelicoCentrica.woff2 +0 -0
  61. package/kits/base/node_modules/castle-web-fonts/woff2/Piazzolla.woff2 +0 -0
  62. package/kits/base/node_modules/castle-web-fonts/woff2/SOURCE.txt +0 -2
  63. package/kits/base/node_modules/castle-web-fonts/woff2/Synco.woff2 +0 -0
  64. package/kits/base/node_modules/castle-web-fonts/woff2/Tektur.woff2 +0 -0
  65. package/kits/base/node_modules/castle-web-fonts/woff2/YatraOne.woff2 +0 -0
@@ -60,6 +60,17 @@ function createPlatformHandle(init, platformEvents) {
60
60
  broadcast(text) {
61
61
  send({ protocolVersion: PROTOCOL_VERSION, t: 'broadcast', d: text });
62
62
  },
63
+ sendBinary(connId, bytes) {
64
+ send({
65
+ protocolVersion: PROTOCOL_VERSION,
66
+ t: 'sendBinary',
67
+ playerId: connId,
68
+ b: binaryBase64(bytes),
69
+ });
70
+ },
71
+ broadcastBinary(bytes) {
72
+ send({ protocolVersion: PROTOCOL_VERSION, t: 'broadcastBinary', b: binaryBase64(bytes) });
73
+ },
63
74
  disconnect(connId, code) {
64
75
  send({ protocolVersion: PROTOCOL_VERSION, t: 'kick', playerId: connId, reason: String(code) });
65
76
  },
@@ -90,6 +101,12 @@ async function dispatch(platformEvents, frame) {
90
101
  case 'clientMessage':
91
102
  await platformEvents.emit('message', frame.playerId, JSON.stringify(frame.d));
92
103
  return;
104
+ case 'clientBinary':
105
+ if (typeof frame.playerId !== 'string' || typeof frame.b !== 'string') {
106
+ throw new Error('platform channel sent an invalid binary message');
107
+ }
108
+ await platformEvents.emit('binaryMessage', frame.playerId, new Uint8Array(Buffer.from(frame.b, 'base64')));
109
+ return;
93
110
  case 'replaced':
94
111
  await platformEvents.emit('replaced');
95
112
  return;
@@ -111,6 +128,12 @@ function send(frame) {
111
128
  throw new Error('platform channel is not open');
112
129
  socket.send(JSON.stringify(frame));
113
130
  }
131
+ function binaryBase64(bytes) {
132
+ const buffer = bytes instanceof ArrayBuffer
133
+ ? Buffer.from(bytes)
134
+ : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
135
+ return buffer.toString('base64');
136
+ }
114
137
  function asRecord(value) {
115
138
  if (typeof value !== 'object' || value === null || Array.isArray(value)) {
116
139
  throw new Error('platform channel sent an invalid frame');
@@ -10,6 +10,9 @@ import { readCastleJson, resolveServerConfig } from './castleJson.js';
10
10
  import { bundleServerModule } from './serverBundle.js';
11
11
  const PROTOCOL_VERSION = 1;
12
12
  const MAX_CLIENT_FRAME_BYTES = 16 * 1024;
13
+ // Mirrors the host-agent's server-to-client broadcast cap.
14
+ const MAX_SERVER_FRAME_BYTES = 64 * 1024;
15
+ const BINARY_MESSAGE_TAG = 0x01;
13
16
  const NONCE_TTL_MS = 60_000;
14
17
  const CHILD_READY_TIMEOUT_MS = 15_000;
15
18
  const CHILD_STOP_GRACE_MS = 2_000;
@@ -38,7 +41,11 @@ class DevSessionServerImpl {
38
41
  noServer: true,
39
42
  maxPayload: MAX_CLIENT_FRAME_BYTES,
40
43
  });
41
- platformWss = new WebSocketServer({ noServer: true, maxPayload: 80 * 1024 });
44
+ // Leaves room for base64 and JSON envelope expansion around a legal server frame.
45
+ platformWss = new WebSocketServer({
46
+ noServer: true,
47
+ maxPayload: MAX_SERVER_FRAME_BYTES * 2 + 1024,
48
+ });
42
49
  nonces = new Map();
43
50
  reconnects = new Map();
44
51
  players = new Map();
@@ -229,7 +236,19 @@ class DevSessionServerImpl {
229
236
  }
230
237
  handleClientMessage(playerId, socket, data, isBinary) {
231
238
  if (isBinary) {
232
- socket.close(1003, 'binary frames are not supported');
239
+ const buffer = Buffer.isBuffer(data)
240
+ ? data
241
+ : Buffer.concat(Array.isArray(data) ? data : [Buffer.from(data)]);
242
+ if (buffer.length === 0 || buffer[0] !== BINARY_MESSAGE_TAG) {
243
+ socket.close(1003, 'unsupported binary frame');
244
+ return;
245
+ }
246
+ this.sendPlatform({
247
+ protocolVersion: PROTOCOL_VERSION,
248
+ t: 'clientBinary',
249
+ playerId,
250
+ b: buffer.subarray(1).toString('base64'),
251
+ });
233
252
  return;
234
253
  }
235
254
  let frame;
@@ -313,6 +332,13 @@ class DevSessionServerImpl {
313
332
  if (socket && payload.ok)
314
333
  this.sendClient(socket, { t: 'm', d: payload.value });
315
334
  }
335
+ else if (frame.t === 'sendBinary' &&
336
+ typeof frame.playerId === 'string' &&
337
+ typeof frame.b === 'string') {
338
+ const socket = this.players.get(frame.playerId)?.socket;
339
+ if (socket)
340
+ this.sendClientBinary(socket, Buffer.from(frame.b, 'base64'));
341
+ }
316
342
  else if (frame.t === 'broadcast') {
317
343
  const payload = parseAuthorPayload(frame.d);
318
344
  if (payload.ok)
@@ -321,6 +347,13 @@ class DevSessionServerImpl {
321
347
  this.sendClient(player.socket, { t: 'm', d: payload.value });
322
348
  }
323
349
  }
350
+ else if (frame.t === 'broadcastBinary' && typeof frame.b === 'string') {
351
+ const payload = Buffer.from(frame.b, 'base64');
352
+ for (const player of this.players.values()) {
353
+ if (player.socket)
354
+ this.sendClientBinary(player.socket, payload);
355
+ }
356
+ }
324
357
  else if (frame.t === 'kick' && typeof frame.playerId === 'string') {
325
358
  this.kick(frame.playerId, typeof frame.reason === 'string' ? frame.reason : undefined);
326
359
  }
@@ -420,12 +453,24 @@ class DevSessionServerImpl {
420
453
  if (socket.readyState !== WebSocket.OPEN)
421
454
  return;
422
455
  const text = JSON.stringify(frame);
423
- if (Buffer.byteLength(text) > MAX_CLIENT_FRAME_BYTES) {
424
- this.log('error', 'dropped a server message larger than 16KB');
456
+ if (Buffer.byteLength(text) > MAX_SERVER_FRAME_BYTES) {
457
+ this.log('error', 'dropped a server message larger than 64KB');
425
458
  return;
426
459
  }
427
460
  socket.send(text);
428
461
  }
462
+ sendClientBinary(socket, payload) {
463
+ if (socket.readyState !== WebSocket.OPEN)
464
+ return;
465
+ const frame = Buffer.allocUnsafe(payload.byteLength + 1);
466
+ frame[0] = BINARY_MESSAGE_TAG;
467
+ payload.copy(frame, 1);
468
+ if (frame.byteLength > MAX_SERVER_FRAME_BYTES) {
469
+ this.log('error', 'dropped a server message larger than 64KB');
470
+ return;
471
+ }
472
+ socket.send(frame, { binary: true });
473
+ }
429
474
  broadcastRoster() {
430
475
  const players = this.connectedPlayers();
431
476
  for (const player of this.players.values()) {
package/dist/init.js CHANGED
@@ -55,7 +55,7 @@ if (!(await mountEditorRoute())) startGame(initCard());
55
55
  // Registry version of castle-web-sdk to inject when scaffolding from a
56
56
  // globally-installed castle-web (not from inside the workspace). Bumped
57
57
  // alongside cli/sdk version bumps.
58
- const PUBLISHED_SDK_VERSION = '0.4.24';
58
+ const PUBLISHED_SDK_VERSION = '0.4.25';
59
59
  // Range, not a pin: `castle-web-fonts` is its own package precisely so a tenth
60
60
  // face can ship without a cli release, and a caret range means an existing
61
61
  // deck's next install picks it up. Nothing here has to move when it does.
@@ -217,7 +217,8 @@ const COMMON_SECTIONS = `## Imports are read-only
217
217
  \`named\` puts everyone passing the same \`key\` in one session, which is how you build room codes and invite links. \`public\` drops a player into a shared session for the deck; \`party\` uses the Castle party they are already in.
218
218
  - **Always handle \`conn.isSolo\`.** When a player cannot join — signed out, blocked, private deck, or no capacity free — the SDK returns a working single-player connection instead of throwing. Keep the deck playable on its own rather than gating the whole game behind other people showing up.
219
219
  - **What the server may and may not do.** Roughly 128MB of memory, no filesystem that survives, and **no network access at all**: no \`fetch\`, no database, no third-party API. Keep state in memory and send it to clients. A session ends once its last player leaves and nothing persists between sessions, so use \`sharedDeckStorage\` for anything that must outlive one.
220
- - **Limits worth designing around.** Messages from a client are capped at 16KB and about 30 per second; server broadcasts at 64KB. Sending 20–30 updates per second means sending deltas rather than whole-world snapshots, and every player's phone pays for whatever you broadcast.
220
+ - **Limits worth designing around.** Client→server messages are capped at 16 KB and about 30 per second; server→client messages are capped at 64 KB. These limits apply to both JSON and binary frames, and a binary frame includes a one-byte protocol tag. Sending 20–30 updates per second means sending deltas rather than whole-world snapshots, and every player's phone pays for whatever you broadcast.
221
+ - **Binary messages are opt-in per payload.** Pass any typed array, \`DataView\`, or \`ArrayBuffer\` to client \`send\`, server \`send\`, or server \`broadcast\` to send its raw bytes. \`onMessage\` always receives those bytes as a \`Uint8Array\`, while every other payload continues to use JSON. Reconstruct another view type such as \`Float32Array\` on receipt; multi-byte values use the sender platform's byte order.
221
222
  - **Test multiplayer locally with no setup.** \`castle-web serve\` runs your server file alongside the deck; open the play URL in two tabs and they share a session. Editing anything under \`server/\` restarts it and clients reconnect, so you exercise your reconnect path constantly. Server \`console.log\` goes to the serve's logs, not the browser console.
222
223
  - **Publishing does not disturb games in progress.** \`save-deck\` bundles and publishes \`server/\`, but sessions already running keep the code they started with (they get \`onReplaced\`, so you can prompt players), and the next new session picks up the new version.
223
224
  `;