castle-web-cli 0.4.233 → 0.4.234
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/dist/api.d.ts +11 -0
- package/dist/api.js +43 -0
- package/dist/bundle.d.ts +64 -0
- package/dist/bundle.js +558 -2
- package/dist/castle-host/host.d.ts +17 -2
- package/dist/castle-host/host.js +793 -36
- package/dist/castleJson.d.ts +20 -1
- package/dist/castleJson.js +44 -2
- package/dist/check.js +9 -2
- package/dist/chunkLoader.d.ts +3 -0
- package/dist/chunkLoader.js +111 -0
- package/dist/devParty.d.ts +26 -0
- package/dist/devParty.js +231 -0
- package/dist/devSaveStorage.js +4 -0
- package/dist/devSessionStorage.js +3 -1
- package/dist/devSocial.d.ts +24 -0
- package/dist/devSocial.js +70 -0
- package/dist/ide.d.ts +2 -0
- package/dist/ide.js +119 -15
- package/dist/index.js +8 -2
- package/dist/init.js +1 -1
- package/dist/save-deck.d.ts +20 -1
- package/dist/save-deck.js +141 -5
- package/dist/serve.js +29 -11
- package/dist/shell/assets/{index-BjOxR-lW.js → index-DulbYIJm.js} +97 -97
- package/dist/shell/index.html +1 -1
- package/dist/vitePlugins.d.ts +2 -1
- package/dist/vitePlugins.js +13 -0
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +260 -3
- package/kits/base/sdk/castle.d.ts +7 -3
- package/kits/base/sdk/castle.js +2 -0
- package/kits/base/sdk/commands.d.ts +162 -1
- package/kits/base/sdk/commands.js +3 -0
- package/kits/base/sdk/display.d.ts +3 -0
- package/kits/base/sdk/display.js +9 -3
- package/kits/base/sdk/hub.d.ts +33 -6
- package/kits/base/sdk/hub.js +50 -4
- package/kits/base/sdk/multiplayer.d.ts +7 -1
- package/kits/base/sdk/multiplayer.js +140 -40
- package/kits/base/sdk/multiplayerProtocol.d.ts +2 -0
- package/kits/base/sdk/party.d.ts +23 -0
- package/kits/base/sdk/party.js +91 -0
- package/kits/base/sdk/reconnectBudget.d.ts +23 -0
- package/kits/base/sdk/reconnectBudget.js +96 -0
- package/kits/base/sdk/save.d.ts +38 -1
- package/kits/base/sdk/save.js +79 -6
- package/kits/base/sdk/server/hub.d.ts +31 -1
- package/kits/base/sdk/server/hub.js +50 -3
- package/kits/base/sdk/server/platformHandle.d.ts +13 -1
- package/kits/base/sdk/server/storage.d.ts +4 -0
- package/kits/base/sdk/server/storage.js +19 -3
- package/kits/base/sdk/server/wrapper.d.ts +7 -1
- package/kits/base/sdk/server/wrapper.js +10 -1
- package/kits/base/sdk/social.d.ts +9 -0
- package/kits/base/sdk/social.js +5 -0
- package/kits/hub-game/CLAUDE.md +123 -3
- package/kits/hub-game/README.md +63 -0
- package/kits/hub-game/castle.json +5 -5
- package/kits/hub-game/code/client/act.js +312 -0
- package/kits/hub-game/code/client/actionLayout.js +147 -0
- package/kits/hub-game/code/client/actionOverflow.js +556 -0
- package/kits/hub-game/code/client/arrivalCamera.js +50 -0
- package/kits/hub-game/code/client/askSlot.js +117 -0
- package/kits/hub-game/code/client/avatar.js +4 -2
- package/kits/hub-game/code/client/avatarShare.js +2 -0
- package/kits/hub-game/code/client/backVisibility.js +13 -0
- package/kits/hub-game/code/client/ballot.js +15 -10
- package/kits/hub-game/code/client/build.js +16 -0
- package/kits/hub-game/code/client/chat.js +41 -5
- package/kits/hub-game/code/client/chatModeration.js +5 -0
- package/kits/hub-game/code/client/chrome.js +1148 -258
- package/kits/hub-game/code/client/crowdNames.js +241 -0
- package/kits/hub-game/code/client/decor.js +10 -4
- package/kits/hub-game/code/client/defaultEnvironment.js +194 -0
- package/kits/hub-game/code/client/doorErrors.js +39 -0
- package/kits/hub-game/code/client/fall.js +18 -0
- package/kits/hub-game/code/client/farAvatars.js +233 -0
- package/kits/hub-game/code/client/firstJoin.js +9 -2
- package/kits/hub-game/code/client/fpsTelemetry.js +50 -0
- package/kits/hub-game/code/client/frameBatch.js +5 -0
- package/kits/hub-game/code/client/grab.js +31 -11
- package/kits/hub-game/code/client/hookLayer.js +87 -8
- package/kits/hub-game/code/client/hudCopy.js +51 -0
- package/kits/hub-game/code/client/hudRate.js +20 -0
- package/kits/hub-game/code/client/idle.js +14 -2
- package/kits/hub-game/code/client/invites.js +231 -0
- package/kits/hub-game/code/client/joinError.js +9 -0
- package/kits/hub-game/code/client/labelsNear.js +31 -2
- package/kits/hub-game/code/client/landscapeLayout.js +17 -0
- package/kits/hub-game/code/client/layoutCache.js +264 -0
- package/kits/hub-game/code/client/loadTelemetry.js +20 -0
- package/kits/hub-game/code/client/loadingCover.js +148 -0
- package/kits/hub-game/code/client/loadingEntry.js +8 -0
- package/kits/hub-game/code/client/menuRows.js +43 -0
- package/kits/hub-game/code/client/modelReady.js +7 -0
- package/kits/hub-game/code/client/padCueArrival.js +23 -0
- package/kits/hub-game/code/client/padCues.js +112 -0
- package/kits/hub-game/code/client/padOccupancy.js +88 -0
- package/kits/hub-game/code/client/padReadability.js +26 -0
- package/kits/hub-game/code/client/padRings.js +69 -0
- package/kits/hub-game/code/client/pushVisit.js +14 -0
- package/kits/hub-game/code/client/quality.js +205 -0
- package/kits/hub-game/code/client/qualityEntry.js +55 -0
- package/kits/hub-game/code/client/safeLayout.js +338 -0
- package/kits/hub-game/code/client/safeStyle.js +42 -0
- package/kits/hub-game/code/client/say.js +12 -3
- package/kits/hub-game/code/client/shot.js +64 -10
- package/kits/hub-game/code/client/shotFit.js +56 -0
- package/kits/hub-game/code/client/signIn.js +28 -0
- package/kits/hub-game/code/client/state.js +53 -0
- package/kits/hub-game/code/client/talk.js +209 -45
- package/kits/hub-game/code/client/tiers.js +68 -66
- package/kits/hub-game/code/client/together.js +7 -2
- package/kits/hub-game/code/client/weakestLookBake.js +92 -0
- package/kits/hub-game/code/client/weakestTier.js +295 -0
- package/kits/hub-game/code/client/worldLabels.js +241 -0
- package/kits/hub-game/code/client/yours.js +10 -9
- package/kits/hub-game/code/npcDisplayText.js +55 -0
- package/kits/hub-game/code/server/act.js +124 -0
- package/kits/hub-game/code/server/actions.js +6 -1
- package/kits/hub-game/code/server/actors.js +2 -1
- package/kits/hub-game/code/server/analytics.js +83 -0
- package/kits/hub-game/code/server/anonymousEntry.js +49 -0
- package/kits/hub-game/code/server/arrivalPose.js +36 -0
- package/kits/hub-game/code/server/companion.js +28 -3
- package/kits/hub-game/code/server/doorAnalytics.js +52 -0
- package/kits/hub-game/code/server/earned.js +22 -5
- package/kits/hub-game/code/server/frameBatch.js +183 -0
- package/kits/hub-game/code/server/friendsAmong.js +49 -9
- package/kits/hub-game/code/server/history.js +2 -0
- package/kits/hub-game/code/server/hub.js +1306 -95
- package/kits/hub-game/code/server/idle.js +30 -1
- package/kits/hub-game/code/server/index.js +26 -4
- package/kits/hub-game/code/server/invites.js +19 -0
- package/kits/hub-game/code/server/labels.js +9 -1
- package/kits/hub-game/code/server/loadAbandon.js +106 -0
- package/kits/hub-game/code/server/manifest.js +211 -3
- package/kits/hub-game/code/server/menu.js +31 -3
- package/kits/hub-game/code/server/npcs.js +226 -64
- package/kits/hub-game/code/server/observe.js +408 -0
- package/kits/hub-game/code/server/padOccupancy.js +85 -0
- package/kits/hub-game/code/server/players.js +9 -1
- package/kits/hub-game/code/server/resumePose.js +152 -0
- package/kits/hub-game/code/server/say.js +1 -1
- package/kits/hub-game/code/server/standing.js +4 -5
- package/kits/hub-game/code/server/storageLimit.js +187 -0
- package/kits/hub-game/code/server/vis.js +67 -5
- package/kits/hub-game/code/shared/act.js +35 -0
- package/kits/hub-game/code/shared/danceIdle.js +28 -0
- package/kits/hub-game/code/shared/loadStages.js +12 -0
- package/kits/hub-game/code/shared/quality.js +74 -0
- package/kits/hub-game/code/shared/say.js +2 -0
- package/kits/hub-game/code/shared/shot.js +35 -1
- package/kits/hub-game/code/systems/hub.js +970 -169
- package/kits/hub-game/docs/analytics.md +279 -0
- package/kits/hub-game/docs/contract.md +1257 -42
- package/kits/hub-game/docs/home-pieces.md +9 -2
- package/kits/hub-game/docs/observed-progress.md +252 -0
- package/kits/hub-game/main.jsx +2 -0
- package/kits/hub-game/package-lock.json +10 -3
- package/kits/hub-game/package.json +6 -3
- package/kits/hub-game/play/player.js +142 -0
- package/kits/hub-game/play/registry.js +47 -0
- package/kits/hub-game/play.jsx +37 -0
- package/kits/hub-game/scripts/check.mjs +39 -5
- package/kits/hub-game/scripts/companion-follower-wire.json +1 -1
- package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +11 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless.json +5 -5
- package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +3 -0
- package/kits/hub-game/scripts/fixtures/fake-dom.mjs +19 -3
- package/kits/hub-game/scripts/fixtures/interest-legacy.json +3 -3
- package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -1
- package/kits/hub-game/scripts/pose-storage-fixture.mjs +46 -0
- package/kits/hub-game/scripts/test-act-client.mjs +186 -0
- package/kits/hub-game/scripts/test-act.mjs +171 -0
- package/kits/hub-game/scripts/test-action-layout.mjs +80 -0
- package/kits/hub-game/scripts/test-action-observers.mjs +46 -0
- package/kits/hub-game/scripts/test-actions-client.mjs +367 -2
- package/kits/hub-game/scripts/test-actors.mjs +20 -7
- package/kits/hub-game/scripts/test-analytics.mjs +76 -0
- package/kits/hub-game/scripts/test-anonymous-entry.mjs +28 -0
- package/kits/hub-game/scripts/test-arrival-pose-server.mjs +196 -0
- package/kits/hub-game/scripts/test-arrival-pose.mjs +24 -0
- package/kits/hub-game/scripts/test-ask-slot.mjs +85 -0
- package/kits/hub-game/scripts/test-avatar-wire.mjs +49 -10
- package/kits/hub-game/scripts/test-avatar.mjs +44 -0
- package/kits/hub-game/scripts/test-back-visibility.mjs +82 -0
- package/kits/hub-game/scripts/test-ballot.mjs +11 -4
- package/kits/hub-game/scripts/test-ban-join.mjs +121 -13
- package/kits/hub-game/scripts/test-build.mjs +20 -2
- package/kits/hub-game/scripts/test-chat.mjs +206 -5
- package/kits/hub-game/scripts/test-companion-chat.mjs +20 -2
- package/kits/hub-game/scripts/test-control-layout-dom.mjs +120 -0
- package/kits/hub-game/scripts/test-crowd-names.mjs +205 -0
- package/kits/hub-game/scripts/test-decor-client.mjs +45 -4
- package/kits/hub-game/scripts/test-decor.mjs +7 -0
- package/kits/hub-game/scripts/test-default-environment-root.mjs +95 -0
- package/kits/hub-game/scripts/test-default-environment.mjs +267 -0
- package/kits/hub-game/scripts/test-door-analytics.mjs +58 -0
- package/kits/hub-game/scripts/test-door-jump.mjs +100 -0
- package/kits/hub-game/scripts/test-earned.mjs +33 -3
- package/kits/hub-game/scripts/test-far-avatars.mjs +340 -0
- package/kits/hub-game/scripts/test-fps-telemetry.mjs +112 -0
- package/kits/hub-game/scripts/test-frame-batch.mjs +252 -0
- package/kits/hub-game/scripts/test-fresh-friends.mjs +118 -0
- package/kits/hub-game/scripts/test-grab-orbit.mjs +47 -4
- package/kits/hub-game/scripts/test-high-only.mjs +170 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +321 -2
- package/kits/hub-game/scripts/test-hub-trip.mjs +879 -11
- package/kits/hub-game/scripts/test-hud-clear.mjs +162 -59
- package/kits/hub-game/scripts/test-hud-defects-dom.mjs +100 -0
- package/kits/hub-game/scripts/test-hud-rate.mjs +224 -0
- package/kits/hub-game/scripts/test-hud-safe-visibility-dom.mjs +83 -0
- package/kits/hub-game/scripts/test-idle.mjs +66 -0
- package/kits/hub-game/scripts/test-interest-cells.mjs +20 -0
- package/kits/hub-game/scripts/test-interest.mjs +15 -0
- package/kits/hub-game/scripts/test-invites-client.mjs +430 -0
- package/kits/hub-game/scripts/test-invites.mjs +109 -0
- package/kits/hub-game/scripts/test-labels.mjs +71 -3
- package/kits/hub-game/scripts/test-landscape-layout.mjs +194 -0
- package/kits/hub-game/scripts/test-list-scroll-dom.mjs +49 -0
- package/kits/hub-game/scripts/test-load-abandon.mjs +246 -0
- package/kits/hub-game/scripts/test-loading-cover.mjs +162 -0
- package/kits/hub-game/scripts/test-manifest.mjs +265 -0
- package/kits/hub-game/scripts/test-menu-client.mjs +105 -0
- package/kits/hub-game/scripts/test-menu.mjs +23 -0
- package/kits/hub-game/scripts/test-npcs.mjs +819 -10
- package/kits/hub-game/scripts/test-observed.mjs +745 -0
- package/kits/hub-game/scripts/test-pad-cues.mjs +304 -0
- package/kits/hub-game/scripts/test-pad-occupancy.mjs +177 -0
- package/kits/hub-game/scripts/test-picker.mjs +234 -7
- package/kits/hub-game/scripts/test-placement-cache.mjs +690 -0
- package/kits/hub-game/scripts/test-progress-reset.mjs +559 -0
- package/kits/hub-game/scripts/test-push-visit.mjs +26 -0
- package/kits/hub-game/scripts/test-quality.mjs +385 -0
- package/kits/hub-game/scripts/test-rehello.mjs +699 -5
- package/kits/hub-game/scripts/test-resume-action-order.mjs +598 -0
- package/kits/hub-game/scripts/test-resume-held.mjs +239 -0
- package/kits/hub-game/scripts/test-resume-pose.mjs +142 -0
- package/kits/hub-game/scripts/test-safe-events-dom.mjs +116 -0
- package/kits/hub-game/scripts/test-safe-layout.mjs +330 -0
- package/kits/hub-game/scripts/test-say.mjs +1 -1
- package/kits/hub-game/scripts/test-shot.mjs +145 -0
- package/kits/hub-game/scripts/test-signin-client.mjs +45 -0
- package/kits/hub-game/scripts/test-soundscape.mjs +22 -17
- package/kits/hub-game/scripts/test-standing.mjs +35 -2
- package/kits/hub-game/scripts/test-storage-limit.mjs +333 -0
- package/kits/hub-game/scripts/test-stuck.mjs +5 -4
- package/kits/hub-game/scripts/test-talk-overlay-dom.mjs +130 -0
- package/kits/hub-game/scripts/test-tiers-render.mjs +86 -13
- package/kits/hub-game/scripts/test-tiers.mjs +7 -8
- package/kits/hub-game/scripts/test-vis.mjs +433 -6
- package/kits/hub-game/scripts/test-weakest-tier.mjs +924 -0
- package/kits/hub-game/scripts/test-world-labels.mjs +367 -0
- package/kits/hub-game/scripts/test-yours-chrome.mjs +50 -6
- package/kits/hub-game/scripts/test-yours.mjs +39 -8
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/joinFailure.js +27 -0
- package/kits/multiplayer-3d/code/client/resumeGate.js +139 -0
- package/kits/multiplayer-3d/code/systems/multiplayer.js +369 -30
- package/kits/multiplayer-3d/package-lock.json +8 -1
- package/kits/multiplayer-3d/package.json +2 -1
- package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +436 -0
- package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +624 -0
- package/kits/physics-2d/CLAUDE.md +10 -1
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/frozenActors.js +233 -0
- package/kits/physics-2d/engine/scene.js +87 -5
- package/kits/physics-2d/eslint.config.js +1 -1
- package/kits/physics-2d/play/behaviors/AnalogStick.js +198 -0
- package/kits/physics-2d/play/behaviors/Camera.js +40 -0
- package/kits/physics-2d/play/behaviors/Collider.js +122 -0
- package/kits/physics-2d/play/behaviors/Draggable.js +115 -0
- package/kits/physics-2d/play/behaviors/Goal.js +46 -0
- package/kits/physics-2d/play/behaviors/Joints.js +126 -0
- package/kits/physics-2d/play/behaviors/Layout.js +71 -0
- package/kits/physics-2d/play/behaviors/RigidBody.js +57 -0
- package/kits/physics-2d/play/behaviors/Slingshot.js +142 -0
- package/kits/physics-2d/play/behaviors/SoundPlayer.js +263 -0
- package/kits/physics-2d/play/behaviors/Sprite.js +406 -0
- package/kits/physics-2d/play/behaviors/Style.js +209 -0
- package/kits/physics-2d/play/behaviors/Text.js +85 -0
- package/kits/physics-2d/play/behaviors/Video.js +93 -0
- package/kits/physics-3d/CLAUDE.md +25 -1651
- package/kits/physics-3d/behaviors/Body.jsx +3 -0
- package/kits/physics-3d/behaviors/Model.jsx +3 -0
- package/kits/physics-3d/behaviors/Player.jsx +35 -18
- package/kits/physics-3d/behaviors/Shape.jsx +3 -0
- package/kits/physics-3d/behaviors/Solid.jsx +3 -0
- package/kits/physics-3d/behaviors/Transform.jsx +3 -0
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/docs/engine-camera.md +542 -0
- package/kits/physics-3d/docs/engine-frame-cap.md +136 -0
- package/kits/physics-3d/docs/engine-load.md +149 -0
- package/kits/physics-3d/docs/engine-look.md +114 -0
- package/kits/physics-3d/docs/engine-shadows.md +372 -0
- package/kits/physics-3d/docs/engine-skip-work.md +187 -0
- package/kits/physics-3d/docs/engine-sky.md +198 -0
- package/kits/physics-3d/docs/engine-static-actors.md +226 -0
- package/kits/physics-3d/docs/engine-view.md +37 -0
- package/kits/physics-3d/docs/pxmodel-format.md +1 -1
- package/kits/physics-3d/engine3d/PlayOnly3D.jsx +5 -1
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +19 -333
- package/kits/physics-3d/engine3d/actornode.js +1 -0
- package/kits/physics-3d/engine3d/branches.js +3 -13
- package/kits/physics-3d/engine3d/cage.js +2 -7
- package/kits/physics-3d/engine3d/cageops.js +2 -17
- package/kits/physics-3d/engine3d/dataBehaviors.js +12 -0
- package/kits/physics-3d/engine3d/framecap.js +4 -1
- package/kits/physics-3d/engine3d/frozenphysics.js +140 -0
- package/kits/physics-3d/engine3d/frozenstatics.js +273 -0
- package/kits/physics-3d/engine3d/gait.js +8 -0
- package/kits/physics-3d/engine3d/initialModelFiles.js +18 -0
- package/kits/physics-3d/engine3d/look.js +7 -0
- package/kits/physics-3d/engine3d/modelFiles.js +3 -17
- package/kits/physics-3d/engine3d/modelMath.js +49 -0
- package/kits/physics-3d/engine3d/modelready.js +16 -0
- package/kits/physics-3d/engine3d/motion.js +3 -3
- package/kits/physics-3d/engine3d/nearshadows.js +77 -10
- package/kits/physics-3d/engine3d/orbitinput.js +59 -25
- package/kits/physics-3d/engine3d/partgeometry.js +1 -16
- package/kits/physics-3d/engine3d/paths.js +1 -9
- package/kits/physics-3d/engine3d/playTimings.js +50 -0
- package/kits/physics-3d/engine3d/playerRun.js +372 -0
- package/kits/physics-3d/engine3d/pxmodel.js +3 -3
- package/kits/physics-3d/engine3d/rapier.js +27 -0
- package/kits/physics-3d/engine3d/scatter.js +1 -11
- package/kits/physics-3d/engine3d/shadowfade.js +23 -15
- package/kits/physics-3d/engine3d/sky.js +1 -1
- package/kits/physics-3d/engine3d/squarefirst.js +177 -0
- package/kits/physics-3d/engine3d/stillshadows.js +399 -0
- package/kits/physics-3d/engine3d/sweep.js +1 -25
- package/kits/physics-3d/engine3d/world3d.js +468 -18
- package/kits/physics-3d/eslint.config.js +2 -1
- package/kits/physics-3d/main.jsx +6 -3
- package/kits/physics-3d/package-lock.json +7 -0
- package/kits/physics-3d/package.json +5 -1
- package/kits/physics-3d/play/behaviors/Body.js +31 -0
- package/kits/physics-3d/play/behaviors/Door.js +37 -0
- package/kits/physics-3d/play/behaviors/Lookable.js +16 -0
- package/kits/physics-3d/play/behaviors/Model.js +23 -0
- package/kits/physics-3d/play/behaviors/Pickup.js +46 -0
- package/kits/physics-3d/play/behaviors/Player.js +1204 -0
- package/kits/physics-3d/play/behaviors/Shape.js +47 -0
- package/kits/physics-3d/play/behaviors/Solid.js +16 -0
- package/kits/physics-3d/play/behaviors/Transform.js +29 -0
- package/kits/physics-3d/pnpm-lock.yaml +8 -0
- package/kits/physics-3d/scripts/bench-shadow-fade.mjs +37 -0
- package/kits/physics-3d/scripts/build-rapier-gz.mjs +56 -0
- package/kits/physics-3d/scripts/frozen-statics-fixture.mjs +141 -0
- package/kits/physics-3d/scripts/test-camera-follow.mjs +5 -1
- package/kits/physics-3d/scripts/test-camera-orbit.mjs +52 -4
- package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +1 -1
- package/kits/physics-3d/scripts/test-empty-gait-hints.mjs +89 -0
- package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +6 -3
- package/kits/physics-3d/scripts/test-frame-cap.mjs +1 -1
- package/kits/physics-3d/scripts/test-frozen-nested.mjs +49 -0
- package/kits/physics-3d/scripts/test-frozen-statics-legacy-physics2d.mjs +123 -0
- package/kits/physics-3d/scripts/test-frozen-statics.mjs +434 -0
- package/kits/physics-3d/scripts/test-look-bake.mjs +1 -1
- package/kits/physics-3d/scripts/test-near-shadows.mjs +2 -2
- package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +88 -7
- package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +40 -3
- package/kits/physics-3d/scripts/test-orbit-shot.mjs +75 -1
- package/kits/physics-3d/scripts/test-rapier-gz.mjs +106 -0
- package/kits/physics-3d/scripts/test-sky.mjs +1 -1
- package/kits/physics-3d/scripts/test-square-first.mjs +921 -0
- package/kits/physics-3d/scripts/test-static-actors.mjs +3 -1
- package/kits/physics-3d/scripts/test-static-physics.mjs +4 -1
- package/kits/physics-3d/scripts/test-static-scenery.mjs +5 -2
- package/kits/physics-3d/scripts/test-steady-hover.mjs +5 -2
- package/kits/physics-3d/scripts/test-still-shadows.mjs +477 -0
- package/kits/physics-3d/systems/physics3d.js +37 -4
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/connection.js +33 -10
- package/kits/real-time/code/client/gameHooks.js +2 -0
- package/kits/real-time/code/client/joinOverlay.js +9 -4
- package/kits/real-time/code/server/session.js +6 -4
- package/kits/real-time/package-lock.json +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
// Run with: node kits/multiplayer-3d/scripts/test-join-watchdog.mjs
|
|
2
|
+
// Real system and cover helpers, with controlled page time and async grants.
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import { register } from 'node:module';
|
|
5
|
+
const kits = new URL('../../', import.meta.url).href;
|
|
6
|
+
const sdk = new URL('../../../sdk/src/', import.meta.url).href;
|
|
7
|
+
const typescript = new URL('../../../node_modules/typescript/lib/typescript.js', import.meta.url).href;
|
|
8
|
+
const stubs = {
|
|
9
|
+
'../client/avatars.js': `
|
|
10
|
+
export const makeAvatars = () => ({ actors: new Map(), leaving: new Map(), retired: new Set() });
|
|
11
|
+
export const clearAvatars = (a) => a.actors.clear();
|
|
12
|
+
export const showPlayer = (a, scene, id) => {
|
|
13
|
+
if (!a.actors.has(id)) { globalThis.__spawns++; a.actors.set(id, 'avatar-' + id); }
|
|
14
|
+
return { id: 'avatar-' + id, components: { Transform: {} } };
|
|
15
|
+
};
|
|
16
|
+
export const showSelf = () => {}; export const animate = () => {};
|
|
17
|
+
export const dropMissing = () => {}; export const enter = () => {}; export const retire = () => {};`,
|
|
18
|
+
'../client/steer.js': 'export const makeState = () => ({}); export const LIVE_RADIUS = 3;',
|
|
19
|
+
'@imports/castle.real-time/code/client/connection.js': 'export const connectSession = (o) => globalThis.__join(o);',
|
|
20
|
+
'@imports/castle.real-time/code/client/soloBadge.js': 'export const showSoloBadge = () => {}; export const updateSoloBadge = () => {};',
|
|
21
|
+
'@imports/castle.real-time/code/client/joinOverlay.js': 'export const showJoinOverlay = (v, t) => { globalThis.__cover = v ? t : null; };',
|
|
22
|
+
'@imports/castle.real-time/code/client/gameHooks.js': 'export const game = { arrive: () => { globalThis.__arrivals++; return true; } };',
|
|
23
|
+
};
|
|
24
|
+
register(`data:text/javascript,${encodeURIComponent(`
|
|
25
|
+
import { readFile } from 'node:fs/promises';
|
|
26
|
+
import ts from ${JSON.stringify(typescript)};
|
|
27
|
+
const sdk = ${JSON.stringify(sdk)};
|
|
28
|
+
const stubs = ${JSON.stringify(stubs)};
|
|
29
|
+
const kits = ${JSON.stringify(kits)};
|
|
30
|
+
export async function resolve(s, c, next) {
|
|
31
|
+
if (s === 'castle-web-sdk') { return next(sdk + 'multiplayer.ts', c); }
|
|
32
|
+
if (c.parentURL?.startsWith(sdk) && s.startsWith('.')) {
|
|
33
|
+
return next(new URL(s + '.ts', c.parentURL).href, c);
|
|
34
|
+
}
|
|
35
|
+
if (c.parentURL?.endsWith('/systems/multiplayer.js') && stubs[s]) {
|
|
36
|
+
return { url: 'data:text/javascript,' + encodeURIComponent(stubs[s]), shortCircuit: true };
|
|
37
|
+
}
|
|
38
|
+
if (s.startsWith('@imports/castle.real-time/')) {
|
|
39
|
+
return next(kits + 'real-time/' + s.slice('@imports/castle.real-time/'.length), c);
|
|
40
|
+
}
|
|
41
|
+
return next(s, c);
|
|
42
|
+
}
|
|
43
|
+
export async function load(u, c, next) {
|
|
44
|
+
if (u.startsWith(sdk) && u.endsWith('.ts')) {
|
|
45
|
+
const source = ts.transpileModule(await readFile(new URL(u), 'utf8'), {
|
|
46
|
+
compilerOptions: { module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ES2022 },
|
|
47
|
+
}).outputText;
|
|
48
|
+
return { format: 'module', source, shortCircuit: true };
|
|
49
|
+
}
|
|
50
|
+
if (u.endsWith('/systems/multiplayer.js')) {
|
|
51
|
+
const source = (await readFile(new URL(u), 'utf8')).replace(/import.meta.glob\\([^)]*\\)/g,
|
|
52
|
+
(glob) => glob.includes('/castle.json') ? '({ config: { hub: { title: "Town" } } })' : '({})');
|
|
53
|
+
return { format: 'module', source, shortCircuit: true };
|
|
54
|
+
}
|
|
55
|
+
return next(u, c);
|
|
56
|
+
}
|
|
57
|
+
`)}`);
|
|
58
|
+
let now = 1000;
|
|
59
|
+
Object.defineProperty(globalThis, 'performance', { value: { now: () => now }, configurable: true });
|
|
60
|
+
const warnings = [];
|
|
61
|
+
const log = console.log;
|
|
62
|
+
console.warn = (stage, detail) => warnings.push({ stage, ...detail });
|
|
63
|
+
console.log = (...args) => { if (!String(args[0]).startsWith('[multiplayer]')) { log(...args); } };
|
|
64
|
+
// Minimal DOM, keeping real element parentage, styles and listener removal.
|
|
65
|
+
class Element {
|
|
66
|
+
constructor(tag) {
|
|
67
|
+
this.tag = tag; this.children = []; this.attributes = {}; this.style = {};
|
|
68
|
+
this.listeners = new Map(); this.textContent = '';
|
|
69
|
+
}
|
|
70
|
+
setAttribute(k, v) { this.attributes[k] = v; }
|
|
71
|
+
removeAttribute(k) { delete this.attributes[k]; }
|
|
72
|
+
append(...nodes) {
|
|
73
|
+
for (const n of nodes) { n.remove(); n.parentElement = this; this.children.push(n); }
|
|
74
|
+
}
|
|
75
|
+
remove() {
|
|
76
|
+
if (this.parentElement) {
|
|
77
|
+
this.parentElement.children = this.parentElement.children.filter((n) => n !== this);
|
|
78
|
+
this.parentElement = null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
addEventListener(t, f) { this.listeners.set(t, f); }
|
|
82
|
+
removeEventListener(t, f) { if (this.listeners.get(t) === f) { this.listeners.delete(t); } }
|
|
83
|
+
focus() { this.focused = true; }
|
|
84
|
+
click() { this.listeners.get('click')?.(); }
|
|
85
|
+
}
|
|
86
|
+
const document = globalThis.document = Object.assign(new Element('document'), {
|
|
87
|
+
hidden: false, body: new Element('body'), head: new Element('head'),
|
|
88
|
+
documentElement: new Element('html'), createElement: (tag) => new Element(tag),
|
|
89
|
+
});
|
|
90
|
+
const { installSystem } = await import('../code/systems/multiplayer.js');
|
|
91
|
+
const { joinPlaceName, showJoinFailure } = await import('../code/client/joinFailure.js');
|
|
92
|
+
const { makeLoadingCover } = await import('../../hub-game/code/client/loadingCover.js');
|
|
93
|
+
let attempts, nets, current;
|
|
94
|
+
function net() {
|
|
95
|
+
const n = {
|
|
96
|
+
isClosed: false, closes: 0, inbox: [], state: 'connected', solo: false,
|
|
97
|
+
close() { this.closes++; this.isClosed = true; },
|
|
98
|
+
closed() { return this.isClosed; }, closeError: () => 'SOCKET_CLOSED',
|
|
99
|
+
status() { return { state: this.state, solo: this.solo, others: this.solo ? 0 : 1 }; },
|
|
100
|
+
selfId: () => 'self', drain() { return this.inbox.splice(0); },
|
|
101
|
+
others: () => new Map([['peer', 'Peer']]), roster: () => new Map(), userId: () => null,
|
|
102
|
+
send() {}, sendMove: () => false,
|
|
103
|
+
};
|
|
104
|
+
nets.push(n); return n;
|
|
105
|
+
}
|
|
106
|
+
function setup(mode = 'public', join = null) {
|
|
107
|
+
current?.system.dispose(current.scene);
|
|
108
|
+
now = 1000; document.hidden = false;
|
|
109
|
+
document.listeners.clear(); document.body.children = []; document.head.children = [];
|
|
110
|
+
warnings.length = 0; globalThis.__spawns = 0; globalThis.__arrivals = 0;
|
|
111
|
+
attempts = []; nets = [];
|
|
112
|
+
globalThis.__join = join ?? ((options) => new Promise((resolve, reject) => attempts.push({ options, resolve, reject })));
|
|
113
|
+
const system = installSystem({ registerSystem() {} });
|
|
114
|
+
system.target = typeof mode === 'string' ? { mode } : mode;
|
|
115
|
+
const local = { id: 'local', components: { Transform: { x: 0, y: 0, z: 0 } } };
|
|
116
|
+
const body = { setTranslation(p) { Object.assign(local.components.Transform, p); }, setLinvel() {} };
|
|
117
|
+
const scene = { actorWith: () => local, actors: new Map(), getActor: () => null,
|
|
118
|
+
physics3d: { bodyOf: (actor) => actor === local ? body : null },
|
|
119
|
+
data: {}, systems: [], touch() {}, despawnActor() {}, hud: {}, multiplayer: system };
|
|
120
|
+
current = { system, scene }; frame();
|
|
121
|
+
assert.equal(attempts.length, 1); return current;
|
|
122
|
+
}
|
|
123
|
+
function frame(ms = 0) { now += ms; current.system.afterBehaviors(current.scene, ms / 1000); }
|
|
124
|
+
function step(ms) {
|
|
125
|
+
const until = now + ms;
|
|
126
|
+
while (now < until) { frame(Math.min(100, until - now)); }
|
|
127
|
+
}
|
|
128
|
+
async function flush() { await Promise.resolve(); await Promise.resolve(); }
|
|
129
|
+
async function connect(at = attempts.length - 1) {
|
|
130
|
+
const n = net(); attempts[at].resolve(n); await flush(); return n;
|
|
131
|
+
}
|
|
132
|
+
async function error(code = 'TEST_ERROR') {
|
|
133
|
+
attempts.at(-1).reject(Object.assign(new Error(code), { code, extensions: { closeCode: 4401 } })); await flush();
|
|
134
|
+
}
|
|
135
|
+
function visibility(hidden) { document.hidden = hidden; document.listeners.get('visibilitychange')?.(); }
|
|
136
|
+
function placed(n) {
|
|
137
|
+
n.inbox.push({ k: 'w', t: now, localMs: now, ps: [['self', 0, 0, 0, 0], ['peer', 1, 0, 1, 0]], os: [], own: [] });
|
|
138
|
+
frame(); assert.equal(current.system.joined, true);
|
|
139
|
+
}
|
|
140
|
+
const stages = (name) => warnings.filter((e) => e.stage === `[multiplayer] join ${name}`);
|
|
141
|
+
const panel = () => document.body.children.find((n) => 'data-multiplayer-join-failure' in n.attributes);
|
|
142
|
+
const results = [];
|
|
143
|
+
async function check(name, run) {
|
|
144
|
+
await run();
|
|
145
|
+
const seen = new Set();
|
|
146
|
+
for (const e of warnings.filter((r) => r.stage.startsWith('[multiplayer] join '))) {
|
|
147
|
+
const key = `${e.attempt}:${e.stage}`;
|
|
148
|
+
assert(!seen.has(key), `one line per stage per attempt: ${key}`); seen.add(key);
|
|
149
|
+
}
|
|
150
|
+
results.push(`PASS ${name}`);
|
|
151
|
+
}
|
|
152
|
+
await check('20s watchdog aborts pending acquisition and assigned sockets once, then backs off', async () => {
|
|
153
|
+
for (const assigned of [false, true]) {
|
|
154
|
+
const { system } = setup(); const first = assigned ? await connect() : null;
|
|
155
|
+
assert.equal(stages('attempt start')[0].attempt, 1);
|
|
156
|
+
assert.equal(stages('attempt start')[0].mode, 'public');
|
|
157
|
+
step(20000); assert.equal(stages('watchdog abort').length, 0);
|
|
158
|
+
frame(100);
|
|
159
|
+
assert.equal(stages('watchdog abort').length, 1); assert.equal(system.joinFailures, 1);
|
|
160
|
+
assert.equal(first?.closes ?? 0, assigned ? 1 : 0); assert.equal(system.net, null);
|
|
161
|
+
step(900); assert.equal(attempts.length, 1, 'normal backoff');
|
|
162
|
+
frame(100); frame(); assert.equal(attempts.length, 2, 'exactly one replacement');
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
await check('solo play never spends the watchdog, rejoins on return or counts a failure', async () => {
|
|
166
|
+
const { system } = setup();
|
|
167
|
+
await error(); step(1000); await error(); step(2000);
|
|
168
|
+
const solo = await connect(); solo.solo = true;
|
|
169
|
+
const failures = system.joinFailures;
|
|
170
|
+
for (let i = 0; i < 3; i++) {
|
|
171
|
+
step(25000);
|
|
172
|
+
visibility(true); now += 180000; visibility(false); frame(1500);
|
|
173
|
+
assert.equal(system.net, solo);
|
|
174
|
+
assert.equal(attempts.length, 3);
|
|
175
|
+
assert.equal(solo.closes, 0);
|
|
176
|
+
assert.equal(system.joinFailures, failures);
|
|
177
|
+
assert.equal(panel(), undefined);
|
|
178
|
+
}
|
|
179
|
+
assert.equal(stages('watchdog abort').length, 0);
|
|
180
|
+
assert.equal(stages('visible rejoin').length, 0);
|
|
181
|
+
solo.isClosed = true; frame();
|
|
182
|
+
assert.equal(system.joinFailures, failures, 'an ended solo net is not a failed server join');
|
|
183
|
+
assert.equal(stages('failure').length, 2, 'only the two earlier real failures count');
|
|
184
|
+
assert.equal(panel(), undefined);
|
|
185
|
+
});
|
|
186
|
+
await check('placement at 15s, 19s or on the timeout frame always wins', async () => {
|
|
187
|
+
for (const at of [15000, 19000, 20100]) {
|
|
188
|
+
const { system } = setup(); const n = await connect(); step(at - 100); now += 100; placed(n); step(25000);
|
|
189
|
+
assert.equal(n.closes, 0); assert.equal(attempts.length, 1); assert.equal(stages('placed').length, 1);
|
|
190
|
+
assert.equal(stages('placed')[0].ms, at); assert.equal(system.joinFailures, 0);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
await check('queued WORLD placement at 15.1s survives stalls and visible returns on any assigned net', async () => {
|
|
194
|
+
for (const state of ['connected', 'reconnecting']) {
|
|
195
|
+
for (const visible of [false, true]) {
|
|
196
|
+
const { system } = setup(); const n = await connect(); n.state = state;
|
|
197
|
+
step(14000);
|
|
198
|
+
if (visible) { visibility(true); }
|
|
199
|
+
now += 1100;
|
|
200
|
+
n.inbox.push({ k: 'w', t: now, localMs: now, ps: [['self', 1, 0, 1, 0]], os: [], own: [] });
|
|
201
|
+
if (visible) { visibility(false); }
|
|
202
|
+
assert.equal(n.closes, 0, 'visibility alone cannot discard an assigned net');
|
|
203
|
+
frame();
|
|
204
|
+
assert.equal(system.joined, true);
|
|
205
|
+
assert.equal(system.net, n);
|
|
206
|
+
assert.equal(n.closes, 0);
|
|
207
|
+
assert.equal(attempts.length, 1);
|
|
208
|
+
assert.equal(system.joinFailures, 0);
|
|
209
|
+
assert.equal(stages('placed')[0].ms, 15100);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
await check('connected unplaced nets survive returns without WORLD and retain their visible watchdog budget', async () => {
|
|
214
|
+
const { system } = setup(); const n = await connect();
|
|
215
|
+
step(19000); frame(1100);
|
|
216
|
+
visibility(true); now += 120000; visibility(false); frame();
|
|
217
|
+
assert.equal(system.net, n); assert.equal(attempts.length, 1);
|
|
218
|
+
assert.equal(system.joinAttempt.visibleMs, 19000, 'parked time is excluded');
|
|
219
|
+
step(1000); assert.equal(n.closes, 0);
|
|
220
|
+
frame(100); assert.equal(n.closes, 1);
|
|
221
|
+
assert.equal(stages('watchdog abort').length, 1);
|
|
222
|
+
});
|
|
223
|
+
await check('late abandoned result closes and cannot assign, dispatch hooks or duplicate avatars', async () => {
|
|
224
|
+
const { system } = setup(); step(21100); const replacement = await connect(1); placed(replacement);
|
|
225
|
+
const abandoned = await connect(0);
|
|
226
|
+
assert.equal(abandoned.closes, 1); assert.equal(system.net, replacement);
|
|
227
|
+
assert.equal(nets.filter((n) => !n.isClosed).length, 1);
|
|
228
|
+
assert.equal(attempts[0].options.onArrival({ k: 'hello' }), false); attempts[0].options.onConnected();
|
|
229
|
+
assert.equal(globalThis.__arrivals, 0); assert.equal(system.resume.armed, false); frame();
|
|
230
|
+
assert.equal(system.avatars.actors.size, 1); assert.equal(globalThis.__spawns, 1);
|
|
231
|
+
});
|
|
232
|
+
await check('visible returns refresh pending joins immediately and disconnected nets after draining', async () => {
|
|
233
|
+
for (const assigned of [false, true]) {
|
|
234
|
+
const { system } = setup(); const old = assigned ? await connect() : null;
|
|
235
|
+
if (old) { old.state = 'reconnecting'; }
|
|
236
|
+
step(500); visibility(true); now += 60000; visibility(false);
|
|
237
|
+
assert.equal(attempts.length, assigned ? 1 : 2, 'assigned nets wait for a drain');
|
|
238
|
+
frame();
|
|
239
|
+
assert.equal(attempts.length, 2);
|
|
240
|
+
assert.equal(old?.closes ?? 0, assigned ? 1 : 0); assert.equal(stages('visible rejoin').length, 1);
|
|
241
|
+
frame(); visibility(false); assert.equal(attempts.length, 2); assert.equal(system.joinFailures, 1);
|
|
242
|
+
}
|
|
243
|
+
const { system } = setup(); step(500); visibility(false); assert.equal(attempts.length, 1);
|
|
244
|
+
await error(); assert(system.joinRetryAt > now); visibility(false); assert.equal(system.joinRetryAt, 0);
|
|
245
|
+
frame(); assert.equal(attempts.length, 2);
|
|
246
|
+
});
|
|
247
|
+
await check('hidden time spends no watchdog budget; attempts started hidden refresh on return', async () => {
|
|
248
|
+
const { system } = setup(); step(19000); visibility(true); step(180000);
|
|
249
|
+
assert.equal(stages('watchdog abort').length, 0); assert.equal(system.joinAttempt.visibleMs, 19000);
|
|
250
|
+
visibility(false); step(19000);
|
|
251
|
+
assert.equal(stages('watchdog abort').length, 0); assert.equal(system.joinAttempt.visibleMs, 19000);
|
|
252
|
+
setup(); await error(); visibility(true); step(1100); assert.equal(attempts.length, 2);
|
|
253
|
+
visibility(false); assert.equal(attempts.length, 3);
|
|
254
|
+
});
|
|
255
|
+
await check('frame gaps without visibilitychange refresh pending and disconnected joins', async () => {
|
|
256
|
+
for (const assigned of [false, true]) {
|
|
257
|
+
const { system } = setup(); if (assigned) { (await connect()).state = 'reconnecting'; } frame(1100);
|
|
258
|
+
assert.equal(attempts.length, 2); assert.equal(stages('visible rejoin').length, 1);
|
|
259
|
+
assert.equal(stages('watchdog abort').length, 0); assert.equal(system.joinFailures, 1);
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
await check('three mixed failures stop retries; body panel and Retry recover exactly once', async () => {
|
|
263
|
+
const { system, scene } = setup();
|
|
264
|
+
const hubCover = makeLoadingCover({ enabled: true, title: 'Town', document });
|
|
265
|
+
hubCover.sync(scene);
|
|
266
|
+
await error('CONNECT_REFUSED');
|
|
267
|
+
assert.equal(stages('failure')[0].code, 'CONNECT_REFUSED'); assert.equal(stages('failure')[0].closeCode, 4401);
|
|
268
|
+
step(1000); const second = await connect(); assert.equal(system.joinFailures, 1);
|
|
269
|
+
second.isClosed = true; frame(); assert.equal(system.joinFailures, 2);
|
|
270
|
+
step(2000); step(20100);
|
|
271
|
+
assert.equal(system.joinFailures, 3); assert.equal(system.joinFailed, true); assert.equal(stages('gave up').length, 1);
|
|
272
|
+
const failure = panel(); assert(failure); assert.equal(failure.children[0].textContent, "Couldn't join the Town");
|
|
273
|
+
const z = Number(failure.style.cssText.match(/z-index:(\d+)/)[1]);
|
|
274
|
+
assert(z > 2147482000 && z < 2147483000, 'between hub cover and engine errors');
|
|
275
|
+
assert.equal(system.joiningOverlayWanted(), false);
|
|
276
|
+
step(120000); visibility(true); now += 60000; visibility(false); frame(); assert.equal(attempts.length, 3);
|
|
277
|
+
const retry = failure.children[1]; retry.click(); retry.click(); frame();
|
|
278
|
+
assert.equal(attempts.length, 4); assert.equal(stages('retry tapped').length, 1);
|
|
279
|
+
assert.equal(system.joinFailures, 0); assert.equal(panel(), undefined); placed(await connect());
|
|
280
|
+
hubCover.dispose();
|
|
281
|
+
});
|
|
282
|
+
await check('placement resets failures; session switches and disposal clean up panel and pending joins', async () => {
|
|
283
|
+
const { system, scene } = setup(); await error(); step(1000); placed(await connect());
|
|
284
|
+
assert.equal(system.joinFailures, 0);
|
|
285
|
+
system.switchSession(scene, { mode: 'named', key: 'other' }); frame();
|
|
286
|
+
for (let i = 0; i < 3; i++) { await error(); if (i < 2) { step(1000 * 2 ** i); } }
|
|
287
|
+
assert(panel()); system.switchSession(scene, { mode: 'public' }); assert.equal(panel(), undefined);
|
|
288
|
+
frame(); const pending = attempts.at(-1); system.dispose(scene);
|
|
289
|
+
const late = net(); pending.resolve(late); await flush(); assert.equal(late.closes, 1); assert.equal(system.net, null);
|
|
290
|
+
});
|
|
291
|
+
await check('permanent ban and invite refusals keep their existing final failure UI', async () => {
|
|
292
|
+
for (const code of ['CAULDRON_HUB_BANNED', 'CAULDRON_HUB_INVITE_EXPIRED']) {
|
|
293
|
+
const { system } = setup(); await error(code); step(30000);
|
|
294
|
+
visibility(true); now += 30000; visibility(false); frame(1100);
|
|
295
|
+
assert.equal(system.joinError, code); assert.equal(system.joinFailed, true);
|
|
296
|
+
assert.equal(attempts.length, 1); assert.equal(panel(), undefined);
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
await check('hub joins keep existing final failures and never re-request spent handoffs', async () => {
|
|
300
|
+
for (const outcome of ['pending', 'error', 'close']) {
|
|
301
|
+
const { system } = setup('hub');
|
|
302
|
+
if (outcome === 'error') { await error(); }
|
|
303
|
+
if (outcome === 'close') { const n = await connect(); n.isClosed = true; frame(); assert.equal(system.joinState(), 'lost'); }
|
|
304
|
+
step(30000); visibility(true); now += 120000; visibility(false); frame(1100);
|
|
305
|
+
assert.equal(attempts.length, 1); assert.equal(stages('watchdog abort').length, 0);
|
|
306
|
+
assert.equal(stages('visible rejoin').length, 0); assert.equal(stages('gave up').length, 0);
|
|
307
|
+
assert.equal(panel(), undefined); assert.equal(system.joinFailed, outcome !== 'pending');
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
await check('after placement, visibility and stalls belong to the resume gate', async () => {
|
|
311
|
+
const { system } = setup(); const n = await connect(); placed(n);
|
|
312
|
+
visibility(true); now += 120000; visibility(false); frame(); assert.equal(system.resume.armed, true);
|
|
313
|
+
frame(1100); attempts[0].options.onConnected(); attempts[0].options.onConnected(); step(21000);
|
|
314
|
+
assert.equal(attempts.length, 1); assert.equal(n.closes, 0); assert.equal(stages('connected').length, 1);
|
|
315
|
+
});
|
|
316
|
+
await check('Town cover keeps joining text beyond 10s and releases only after placement and draw', async () => {
|
|
317
|
+
const { system, scene } = setup(); const cover = makeLoadingCover({ enabled: true, title: 'Town', document });
|
|
318
|
+
const surface = document.body.children.find((n) => 'data-hub-loading-cover' in n.attributes);
|
|
319
|
+
const renderer = { info: { render: { frame: 0 } }, getContext: () => ({ isContextLost: () => false }) };
|
|
320
|
+
scene.three = { renderer, composer: { render() { renderer.info.render.frame++; } } }; cover.sync(scene);
|
|
321
|
+
const n = await connect(); step(11000); assert.equal(system.joiningOverlayWanted(), false, '10s cap retained');
|
|
322
|
+
cover.sync(scene); scene.three.composer.render(); assert.equal(surface.parentElement, document.body);
|
|
323
|
+
assert.equal(surface.children[0].textContent, 'Joining the Town…');
|
|
324
|
+
assert.equal(surface.attributes['aria-label'], 'Joining the Town…');
|
|
325
|
+
placed(n); cover.sync(scene); scene.three.composer.render();
|
|
326
|
+
assert.equal(surface.parentElement, document.body, 'camera settling frame stays covered');
|
|
327
|
+
frame(100); scene.three.composer.render(); assert.equal(surface.parentElement, null); cover.dispose();
|
|
328
|
+
assert.equal(joinPlaceName(undefined), ''); const remove = showJoinFailure('', () => {});
|
|
329
|
+
assert.equal(panel().children[0].textContent, "Couldn't join"); remove();
|
|
330
|
+
});
|
|
331
|
+
// Use the actual SDK source (transpiled by the loader without a build) and
|
|
332
|
+
// real wrapper. Only the host bridge and socket are fake: the SDK's global
|
|
333
|
+
// acquisition cancellation, AbortController and connection lifecycle are real.
|
|
334
|
+
await check('destination cancellation cannot fall back publicly and cancel its replacement (real SDK)', async () => {
|
|
335
|
+
const { connectSession } = await import('../../real-time/code/client/connection.js');
|
|
336
|
+
const previousWindow = globalThis.window, previousSocket = globalThis.WebSocket;
|
|
337
|
+
const envelopes = [], destinations = [], sockets = [];
|
|
338
|
+
const reply = (envelope, data) => mockWindow.__castleSdkHost.receive({
|
|
339
|
+
castleSdk: 1, requestId: envelope.requestId, ok: true, data,
|
|
340
|
+
});
|
|
341
|
+
const mockWindow = {
|
|
342
|
+
CastleEmbed: { host: 'web' }, location: { href: 'https://deck.test/play' },
|
|
343
|
+
addEventListener() {},
|
|
344
|
+
parent: { postMessage(envelope) {
|
|
345
|
+
envelopes.push(envelope);
|
|
346
|
+
if (envelope.cancel) { return; }
|
|
347
|
+
if (envelope.command === 'multiplayer.joinDestination') { destinations.push(envelope); return; }
|
|
348
|
+
if (envelope.command === 'multiplayer.getSession') {
|
|
349
|
+
queueMicrotask(() => reply(envelope, { status: 'solo', soloReason: 'no_server_bundle', sessionId: 'fallback' }));
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
assert.equal(envelope.command, 'voice.getState');
|
|
353
|
+
queueMicrotask(() => reply(envelope, { state: 'unavailable' }));
|
|
354
|
+
} },
|
|
355
|
+
};
|
|
356
|
+
class Socket {
|
|
357
|
+
static CONNECTING = 0; static OPEN = 1; static CLOSING = 2; static CLOSED = 3;
|
|
358
|
+
readyState = Socket.CONNECTING;
|
|
359
|
+
constructor(url) {
|
|
360
|
+
this.url = url; sockets.push(this);
|
|
361
|
+
queueMicrotask(() => {
|
|
362
|
+
if (this.readyState !== Socket.CONNECTING) { return; }
|
|
363
|
+
this.readyState = Socket.OPEN;
|
|
364
|
+
this.onmessage?.({ data: JSON.stringify({ t: 'hello', playerId: 'self',
|
|
365
|
+
reconnectToken: 'reconnect', sessionId: 'world', mode: 'public' }) });
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
send() {}
|
|
369
|
+
close(code = 1000) {
|
|
370
|
+
this.readyState = Socket.CLOSED;
|
|
371
|
+
queueMicrotask(() => this.onclose?.({ code }));
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
// Let the SDK's promise chains and queued socket hello finish, without
|
|
375
|
+
// advancing page time or waiting for a real handshake/reconnect timer.
|
|
376
|
+
const settle = () => new Promise((resolve) => setImmediate(resolve));
|
|
377
|
+
globalThis.window = mockWindow; globalThis.WebSocket = Socket;
|
|
378
|
+
try {
|
|
379
|
+
const target = { destination: { routeId: 'town', slot: 'main' }, fallback: { mode: 'public' } };
|
|
380
|
+
const join = (options) => { attempts.push({ options }); return connectSession(options); };
|
|
381
|
+
const { system } = setup(target, join);
|
|
382
|
+
assert.equal(destinations.length, 1);
|
|
383
|
+
frame(1100); // the parked acquisition is abandoned and a fresh one starts
|
|
384
|
+
await settle();
|
|
385
|
+
assert.equal(destinations.length, 2);
|
|
386
|
+
assert.equal(envelopes.filter((e) => e.cancel).length, 1, 'SDK cancels only the old acquisition');
|
|
387
|
+
assert.equal(envelopes.filter((e) => e.command === 'multiplayer.getSession').length, 0,
|
|
388
|
+
'an abandoned destination must never start a public fallback');
|
|
389
|
+
reply(destinations[0], { status: 'unavailable' }); // even a late reply is inert
|
|
390
|
+
reply(destinations[1], { status: 'ok', url: 'ws://test/world', nonce: 'world',
|
|
391
|
+
sessionId: 'world', audience: 'public' });
|
|
392
|
+
await settle();
|
|
393
|
+
assert.equal(attempts.length, 2);
|
|
394
|
+
assert.equal(system.joinFailures, 1, 'only the original abandonment counts');
|
|
395
|
+
assert.equal(system.net?.status().state, 'connected');
|
|
396
|
+
assert.equal(system.net?.status().solo, false);
|
|
397
|
+
assert.equal(sockets.filter((socket) => socket.readyState === Socket.OPEN).length, 1);
|
|
398
|
+
sockets[0].onmessage({ data: JSON.stringify({ t: 'm', d: {
|
|
399
|
+
k: 'w', t: now, ps: [['self', 0, 0, 0, 0]], os: [], own: [],
|
|
400
|
+
} }) });
|
|
401
|
+
await settle(); frame();
|
|
402
|
+
assert.equal(system.joined, true);
|
|
403
|
+
assert.equal(system.joinFailures, 0);
|
|
404
|
+
|
|
405
|
+
// A watchdog leaves a retry backoff before the SDK is called again. If the
|
|
406
|
+
// old host reply lands in that window, only the caller's generation check
|
|
407
|
+
// can prevent fallback: the SDK has not cancelled that acquisition yet.
|
|
408
|
+
const count = destinations.length;
|
|
409
|
+
const later = setup(target, join).system;
|
|
410
|
+
step(20100);
|
|
411
|
+
assert.equal(attempts.length, 1);
|
|
412
|
+
assert.equal(later.joinFailures, 1);
|
|
413
|
+
reply(destinations[count], { status: 'unavailable' });
|
|
414
|
+
await settle();
|
|
415
|
+
assert.equal(envelopes.filter((e) => e.command === 'multiplayer.getSession').length, 0,
|
|
416
|
+
'a stale unavailable result during backoff must not fall back either');
|
|
417
|
+
assert.equal(later.net, null);
|
|
418
|
+
step(1000);
|
|
419
|
+
assert.equal(attempts.length, 2);
|
|
420
|
+
reply(destinations[count + 1], { status: 'unavailable' });
|
|
421
|
+
await settle();
|
|
422
|
+
assert.equal(envelopes.filter((e) => e.command === 'multiplayer.getSession').length, 1,
|
|
423
|
+
'the current attempt still uses its public fallback when genuinely unavailable');
|
|
424
|
+
assert.equal(later.net?.status().solo, true);
|
|
425
|
+
step(60000); visibility(true); now += 120000; visibility(false); frame(1100);
|
|
426
|
+
assert.equal(attempts.length, 2, 'the real SDK solo fallback stays exempt from recovery');
|
|
427
|
+
assert.equal(panel(), undefined);
|
|
428
|
+
} finally {
|
|
429
|
+
current.system.dispose(current.scene);
|
|
430
|
+
await settle();
|
|
431
|
+
globalThis.window = previousWindow; globalThis.WebSocket = previousSocket;
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
current.system.dispose(current.scene);
|
|
435
|
+
console.log(results.join('\n'));
|
|
436
|
+
console.log(`test-join-watchdog: ${results.length} scenarios passed`);
|