@my-swu/simulator-client 0.1.0
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/LICENSE +21 -0
- package/README.md +355 -0
- package/dist/actionable.d.ts +61 -0
- package/dist/actionable.js +91 -0
- package/dist/client.d.ts +157 -0
- package/dist/client.js +92 -0
- package/dist/connection/handshake.d.ts +30 -0
- package/dist/connection/handshake.js +62 -0
- package/dist/connection/options.d.ts +36 -0
- package/dist/connection/options.js +1 -0
- package/dist/connection/url.d.ts +55 -0
- package/dist/connection/url.js +46 -0
- package/dist/connection/wait.d.ts +22 -0
- package/dist/connection/wait.js +10 -0
- package/dist/connection.d.ts +110 -0
- package/dist/connection.js +358 -0
- package/dist/generated/index.d.ts +121 -0
- package/dist/generated/index.js +1 -0
- package/dist/generated/public-types.d.ts +2 -0
- package/dist/generated/public-types.js +1 -0
- package/dist/generated/schemas.d.ts +27 -0
- package/dist/generated/schemas.js +21264 -0
- package/dist/generated/types/abandon-match-request.d.ts +1 -0
- package/dist/generated/types/abandon-match-request.js +2 -0
- package/dist/generated/types/abandon-match-response.d.ts +1 -0
- package/dist/generated/types/abandon-match-response.js +2 -0
- package/dist/generated/types/add-lobby-ai-player-request.d.ts +1 -0
- package/dist/generated/types/add-lobby-ai-player-request.js +2 -0
- package/dist/generated/types/ai-driver-error-report-list-response.d.ts +1 -0
- package/dist/generated/types/ai-driver-error-report-list-response.js +2 -0
- package/dist/generated/types/ai-driver-error-report-response.d.ts +1 -0
- package/dist/generated/types/ai-driver-error-report-response.js +2 -0
- package/dist/generated/types/api-error-response.d.ts +1 -0
- package/dist/generated/types/api-error-response.js +2 -0
- package/dist/generated/types/card-catalog-refresh-response.d.ts +1 -0
- package/dist/generated/types/card-catalog-refresh-response.js +2 -0
- package/dist/generated/types/cards-response.d.ts +1 -0
- package/dist/generated/types/cards-response.js +2 -0
- package/dist/generated/types/client-message.d.ts +1 -0
- package/dist/generated/types/client-message.js +2 -0
- package/dist/generated/types/close-tournament-room-request.d.ts +1 -0
- package/dist/generated/types/close-tournament-room-request.js +2 -0
- package/dist/generated/types/common.d.ts +5361 -0
- package/dist/generated/types/common.js +2 -0
- package/dist/generated/types/covered-cards-response.d.ts +47 -0
- package/dist/generated/types/covered-cards-response.js +2 -0
- package/dist/generated/types/create-limited-event-request.d.ts +1 -0
- package/dist/generated/types/create-limited-event-request.js +2 -0
- package/dist/generated/types/create-lobby-request.d.ts +1 -0
- package/dist/generated/types/create-lobby-request.js +2 -0
- package/dist/generated/types/create-match-request.d.ts +1 -0
- package/dist/generated/types/create-match-request.js +2 -0
- package/dist/generated/types/create-meta-window-request.d.ts +1 -0
- package/dist/generated/types/create-meta-window-request.js +2 -0
- package/dist/generated/types/create-tournament-room-request.d.ts +1 -0
- package/dist/generated/types/create-tournament-room-request.js +2 -0
- package/dist/generated/types/create-tournament-table-request.d.ts +1 -0
- package/dist/generated/types/create-tournament-table-request.js +2 -0
- package/dist/generated/types/error-payload.d.ts +1 -0
- package/dist/generated/types/error-payload.js +2 -0
- package/dist/generated/types/format-event-request.d.ts +1 -0
- package/dist/generated/types/format-event-request.js +2 -0
- package/dist/generated/types/format-event-response.d.ts +1 -0
- package/dist/generated/types/format-event-response.js +2 -0
- package/dist/generated/types/game-command.d.ts +1 -0
- package/dist/generated/types/game-command.js +2 -0
- package/dist/generated/types/game-event.d.ts +1 -0
- package/dist/generated/types/game-event.js +2 -0
- package/dist/generated/types/game-state.d.ts +1 -0
- package/dist/generated/types/game-state.js +2 -0
- package/dist/generated/types/get-match-response.d.ts +1 -0
- package/dist/generated/types/get-match-response.js +2 -0
- package/dist/generated/types/health-response.d.ts +1 -0
- package/dist/generated/types/health-response.js +2 -0
- package/dist/generated/types/join-limited-event-request.d.ts +1 -0
- package/dist/generated/types/join-limited-event-request.js +2 -0
- package/dist/generated/types/join-lobby-request.d.ts +1 -0
- package/dist/generated/types/join-lobby-request.js +2 -0
- package/dist/generated/types/join-match-request.d.ts +1 -0
- package/dist/generated/types/join-match-request.js +2 -0
- package/dist/generated/types/join-tournament-room-request.d.ts +1 -0
- package/dist/generated/types/join-tournament-room-request.js +2 -0
- package/dist/generated/types/join-tournament-table-request.d.ts +1 -0
- package/dist/generated/types/join-tournament-table-request.js +2 -0
- package/dist/generated/types/kick-lobby-player-request.d.ts +1 -0
- package/dist/generated/types/kick-lobby-player-request.js +2 -0
- package/dist/generated/types/kick-lobby-spectator-request.d.ts +1 -0
- package/dist/generated/types/kick-lobby-spectator-request.js +2 -0
- package/dist/generated/types/leave-lobby-request.d.ts +1 -0
- package/dist/generated/types/leave-lobby-request.js +2 -0
- package/dist/generated/types/leave-match-request.d.ts +1 -0
- package/dist/generated/types/leave-match-request.js +2 -0
- package/dist/generated/types/leave-match-response.d.ts +1 -0
- package/dist/generated/types/leave-match-response.js +2 -0
- package/dist/generated/types/leave-tournament-room-request.d.ts +1 -0
- package/dist/generated/types/leave-tournament-room-request.js +2 -0
- package/dist/generated/types/limited-event-access-response.d.ts +1 -0
- package/dist/generated/types/limited-event-access-response.js +2 -0
- package/dist/generated/types/limited-event-command-request.d.ts +1 -0
- package/dist/generated/types/limited-event-command-request.js +2 -0
- package/dist/generated/types/limited-event-preflight-response.d.ts +1 -0
- package/dist/generated/types/limited-event-preflight-response.js +2 -0
- package/dist/generated/types/limited-event-response.d.ts +1 -0
- package/dist/generated/types/limited-event-response.js +2 -0
- package/dist/generated/types/list-active-ai-matches-request.d.ts +1 -0
- package/dist/generated/types/list-active-ai-matches-request.js +2 -0
- package/dist/generated/types/list-active-ai-matches-response.d.ts +1 -0
- package/dist/generated/types/list-active-ai-matches-response.js +2 -0
- package/dist/generated/types/lobby-access-response.d.ts +1 -0
- package/dist/generated/types/lobby-access-response.js +2 -0
- package/dist/generated/types/lobby-chat-request.d.ts +1 -0
- package/dist/generated/types/lobby-chat-request.js +2 -0
- package/dist/generated/types/lobby-chat-response.d.ts +1 -0
- package/dist/generated/types/lobby-chat-response.js +2 -0
- package/dist/generated/types/lobby-list-response.d.ts +1 -0
- package/dist/generated/types/lobby-list-response.js +2 -0
- package/dist/generated/types/lobby-list-server-message.d.ts +1 -0
- package/dist/generated/types/lobby-list-server-message.js +2 -0
- package/dist/generated/types/lobby-matchmaking-decision-request.d.ts +1 -0
- package/dist/generated/types/lobby-matchmaking-decision-request.js +2 -0
- package/dist/generated/types/lobby-matchmaking-request.d.ts +1 -0
- package/dist/generated/types/lobby-matchmaking-request.js +2 -0
- package/dist/generated/types/lobby-response.d.ts +1 -0
- package/dist/generated/types/lobby-response.js +2 -0
- package/dist/generated/types/lobby-server-message.d.ts +1 -0
- package/dist/generated/types/lobby-server-message.js +2 -0
- package/dist/generated/types/lobby-sync-request.d.ts +1 -0
- package/dist/generated/types/lobby-sync-request.js +2 -0
- package/dist/generated/types/match-access-response.d.ts +1 -0
- package/dist/generated/types/match-access-response.js +2 -0
- package/dist/generated/types/match-chat-lookup-response.d.ts +1 -0
- package/dist/generated/types/match-chat-lookup-response.js +2 -0
- package/dist/generated/types/match-connection-role.d.ts +1 -0
- package/dist/generated/types/match-connection-role.js +2 -0
- package/dist/generated/types/match-history-deck-stats-request.d.ts +1 -0
- package/dist/generated/types/match-history-deck-stats-request.js +2 -0
- package/dist/generated/types/match-history-deck-stats-response.d.ts +1 -0
- package/dist/generated/types/match-history-deck-stats-response.js +2 -0
- package/dist/generated/types/match-history-entry.d.ts +1 -0
- package/dist/generated/types/match-history-entry.js +2 -0
- package/dist/generated/types/match-history-list-request.d.ts +1 -0
- package/dist/generated/types/match-history-list-request.js +2 -0
- package/dist/generated/types/match-history-list-response.d.ts +1 -0
- package/dist/generated/types/match-history-list-response.js +2 -0
- package/dist/generated/types/match-history-replay-request.d.ts +1 -0
- package/dist/generated/types/match-history-replay-request.js +2 -0
- package/dist/generated/types/match-history-replay-response.d.ts +1 -0
- package/dist/generated/types/match-history-replay-response.js +2 -0
- package/dist/generated/types/match-history-restore-request.d.ts +1 -0
- package/dist/generated/types/match-history-restore-request.js +2 -0
- package/dist/generated/types/match-save-payload.d.ts +1 -0
- package/dist/generated/types/match-save-payload.js +2 -0
- package/dist/generated/types/match-spectator-access-response.d.ts +1 -0
- package/dist/generated/types/match-spectator-access-response.js +2 -0
- package/dist/generated/types/meta-window.d.ts +1 -0
- package/dist/generated/types/meta-window.js +2 -0
- package/dist/generated/types/meta-windows-response.d.ts +1 -0
- package/dist/generated/types/meta-windows-response.js +2 -0
- package/dist/generated/types/prepare-lobby-limited-ai-decks-request.d.ts +1 -0
- package/dist/generated/types/prepare-lobby-limited-ai-decks-request.js +2 -0
- package/dist/generated/types/random-lobby-matchmaking-request.d.ts +173 -0
- package/dist/generated/types/random-lobby-matchmaking-request.js +2 -0
- package/dist/generated/types/ranked-admin-status.d.ts +1 -0
- package/dist/generated/types/ranked-admin-status.js +2 -0
- package/dist/generated/types/ranked-leaderboard-entry.d.ts +1 -0
- package/dist/generated/types/ranked-leaderboard-entry.js +2 -0
- package/dist/generated/types/ranked-leaderboard-query.d.ts +1 -0
- package/dist/generated/types/ranked-leaderboard-query.js +2 -0
- package/dist/generated/types/ranked-leaderboard-response.d.ts +1 -0
- package/dist/generated/types/ranked-leaderboard-response.js +2 -0
- package/dist/generated/types/ranked-matchmaking-request.d.ts +137 -0
- package/dist/generated/types/ranked-matchmaking-request.js +2 -0
- package/dist/generated/types/ranked-matchmaking-view.d.ts +1 -0
- package/dist/generated/types/ranked-matchmaking-view.js +2 -0
- package/dist/generated/types/ranked-profile-request.d.ts +1 -0
- package/dist/generated/types/ranked-profile-request.js +2 -0
- package/dist/generated/types/ranked-profile-response.d.ts +1 -0
- package/dist/generated/types/ranked-profile-response.js +2 -0
- package/dist/generated/types/ranked-queue.d.ts +1 -0
- package/dist/generated/types/ranked-queue.js +2 -0
- package/dist/generated/types/ready-tournament-table-request.d.ts +7 -0
- package/dist/generated/types/ready-tournament-table-request.js +2 -0
- package/dist/generated/types/rematch-match-request.d.ts +1 -0
- package/dist/generated/types/rematch-match-request.js +2 -0
- package/dist/generated/types/rematch-match-response.d.ts +1 -0
- package/dist/generated/types/rematch-match-response.js +2 -0
- package/dist/generated/types/resolve-card-ids-request.d.ts +1 -0
- package/dist/generated/types/resolve-card-ids-request.js +2 -0
- package/dist/generated/types/resolve-card-ids-response.d.ts +1 -0
- package/dist/generated/types/resolve-card-ids-response.js +2 -0
- package/dist/generated/types/restore-history-response.d.ts +1 -0
- package/dist/generated/types/restore-history-response.js +2 -0
- package/dist/generated/types/restore-match-save-request.d.ts +1 -0
- package/dist/generated/types/restore-match-save-request.js +2 -0
- package/dist/generated/types/restore-match-save-response.d.ts +1 -0
- package/dist/generated/types/restore-match-save-response.js +2 -0
- package/dist/generated/types/return-lobby-match-request.d.ts +1 -0
- package/dist/generated/types/return-lobby-match-request.js +2 -0
- package/dist/generated/types/return-tournament-match-request.d.ts +1 -0
- package/dist/generated/types/return-tournament-match-request.js +2 -0
- package/dist/generated/types/save-match-request.d.ts +1 -0
- package/dist/generated/types/save-match-request.js +2 -0
- package/dist/generated/types/server-message.d.ts +1 -0
- package/dist/generated/types/server-message.js +2 -0
- package/dist/generated/types/set-ai-paused-request.d.ts +1 -0
- package/dist/generated/types/set-ai-paused-request.js +2 -0
- package/dist/generated/types/set-ai-paused-response.d.ts +1 -0
- package/dist/generated/types/set-ai-paused-response.js +2 -0
- package/dist/generated/types/set-ranked-admission-request.d.ts +1 -0
- package/dist/generated/types/set-ranked-admission-request.js +2 -0
- package/dist/generated/types/set-simulator-maintenance-request.d.ts +1 -0
- package/dist/generated/types/set-simulator-maintenance-request.js +2 -0
- package/dist/generated/types/simulator-admin-status-response.d.ts +1 -0
- package/dist/generated/types/simulator-admin-status-response.js +2 -0
- package/dist/generated/types/simulator-availability-response.d.ts +1 -0
- package/dist/generated/types/simulator-availability-response.js +2 -0
- package/dist/generated/types/simulator-report-list-response.d.ts +1 -0
- package/dist/generated/types/simulator-report-list-response.js +2 -0
- package/dist/generated/types/simulator-report-response.d.ts +1 -0
- package/dist/generated/types/simulator-report-response.js +2 -0
- package/dist/generated/types/spectate-lobby-request.d.ts +1 -0
- package/dist/generated/types/spectate-lobby-request.js +2 -0
- package/dist/generated/types/spectate-match-request.d.ts +1 -0
- package/dist/generated/types/spectate-match-request.js +2 -0
- package/dist/generated/types/start-lobby-limited-match-request.d.ts +1 -0
- package/dist/generated/types/start-lobby-limited-match-request.js +2 -0
- package/dist/generated/types/start-lobby-request.d.ts +1 -0
- package/dist/generated/types/start-lobby-request.js +2 -0
- package/dist/generated/types/start-tournament-event-request.d.ts +1 -0
- package/dist/generated/types/start-tournament-event-request.js +2 -0
- package/dist/generated/types/stats-response.d.ts +5 -0
- package/dist/generated/types/stats-response.js +2 -0
- package/dist/generated/types/submit-lobby-limited-deck-request.d.ts +1 -0
- package/dist/generated/types/submit-lobby-limited-deck-request.js +2 -0
- package/dist/generated/types/submit-match-deck-request.d.ts +1 -0
- package/dist/generated/types/submit-match-deck-request.js +2 -0
- package/dist/generated/types/submit-match-deck-response.d.ts +1 -0
- package/dist/generated/types/submit-match-deck-response.js +2 -0
- package/dist/generated/types/submit-tournament-deck-request.d.ts +1 -0
- package/dist/generated/types/submit-tournament-deck-request.js +2 -0
- package/dist/generated/types/tournament-event-command-request.d.ts +1 -0
- package/dist/generated/types/tournament-event-command-request.js +2 -0
- package/dist/generated/types/tournament-room-access-response.d.ts +1 -0
- package/dist/generated/types/tournament-room-access-response.js +2 -0
- package/dist/generated/types/tournament-room-chat-request.d.ts +1 -0
- package/dist/generated/types/tournament-room-chat-request.js +2 -0
- package/dist/generated/types/tournament-room-chat-response.d.ts +1 -0
- package/dist/generated/types/tournament-room-chat-response.js +2 -0
- package/dist/generated/types/tournament-room-list-response.d.ts +1 -0
- package/dist/generated/types/tournament-room-list-response.js +2 -0
- package/dist/generated/types/tournament-room-response.d.ts +1 -0
- package/dist/generated/types/tournament-room-response.js +2 -0
- package/dist/generated/types/tournament-room-server-message.d.ts +1 -0
- package/dist/generated/types/tournament-room-server-message.js +2 -0
- package/dist/generated/types/tournament-room-sync-request.d.ts +1 -0
- package/dist/generated/types/tournament-room-sync-request.js +2 -0
- package/dist/generated/types/undo-match-request.d.ts +1 -0
- package/dist/generated/types/undo-match-request.js +2 -0
- package/dist/generated/types/undo-match-response.d.ts +1 -0
- package/dist/generated/types/undo-match-response.js +2 -0
- package/dist/generated/types/undo-respond-match-request.d.ts +1 -0
- package/dist/generated/types/undo-respond-match-request.js +2 -0
- package/dist/generated/types/update-lobby-ai-player-request.d.ts +1 -0
- package/dist/generated/types/update-lobby-ai-player-request.js +2 -0
- package/dist/generated/types/update-lobby-player-request.d.ts +1 -0
- package/dist/generated/types/update-lobby-player-request.js +2 -0
- package/dist/generated/types/update-lobby-settings-request.d.ts +1 -0
- package/dist/generated/types/update-lobby-settings-request.js +2 -0
- package/dist/generated/types/update-tournament-room-player-request.d.ts +1 -0
- package/dist/generated/types/update-tournament-room-player-request.js +2 -0
- package/dist/generated/types/update-tournament-room-settings-request.d.ts +1 -0
- package/dist/generated/types/update-tournament-room-settings-request.js +2 -0
- package/dist/generated/types/update-tournament-table-deck-request.d.ts +123 -0
- package/dist/generated/types/update-tournament-table-deck-request.js +2 -0
- package/dist/generated/types/welcome-payload.d.ts +1 -0
- package/dist/generated/types/welcome-payload.js +2 -0
- package/dist/generated/version.d.ts +16 -0
- package/dist/generated/version.js +16 -0
- package/dist/http/abort.d.ts +57 -0
- package/dist/http/abort.js +60 -0
- package/dist/http/json.d.ts +13 -0
- package/dist/http/json.js +24 -0
- package/dist/http/options.d.ts +40 -0
- package/dist/http/options.js +1 -0
- package/dist/http/request.d.ts +64 -0
- package/dist/http/request.js +182 -0
- package/dist/http/validated-json.d.ts +9 -0
- package/dist/http/validated-json.js +14 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +10 -0
- package/dist/internal/abort-error.d.ts +91 -0
- package/dist/internal/abort-error.js +62 -0
- package/dist/internal/authenticated-socket-session.d.ts +63 -0
- package/dist/internal/authenticated-socket-session.js +170 -0
- package/dist/internal/emitter.d.ts +18 -0
- package/dist/internal/emitter.js +34 -0
- package/dist/internal/errors.d.ts +233 -0
- package/dist/internal/errors.js +238 -0
- package/dist/internal/limits.d.ts +13 -0
- package/dist/internal/limits.js +13 -0
- package/dist/internal/reconnect-backoff.d.ts +33 -0
- package/dist/internal/reconnect-backoff.js +25 -0
- package/dist/internal/socket-frame.d.ts +43 -0
- package/dist/internal/socket-frame.js +47 -0
- package/dist/internal/transport.d.ts +78 -0
- package/dist/internal/transport.js +18 -0
- package/dist/internal/websocket-event.d.ts +15 -0
- package/dist/internal/websocket-event.js +31 -0
- package/dist/local/assets.d.ts +96 -0
- package/dist/local/assets.js +235 -0
- package/dist/local/client.d.ts +32 -0
- package/dist/local/client.js +211 -0
- package/dist/local/engine.d.ts +79 -0
- package/dist/local/engine.js +6 -0
- package/dist/local/index.d.ts +20 -0
- package/dist/local/index.js +17 -0
- package/dist/local/offline-engine.d.ts +46 -0
- package/dist/local/offline-engine.js +74 -0
- package/dist/local/protocol.d.ts +95 -0
- package/dist/local/protocol.js +10 -0
- package/dist/local/routing.d.ts +52 -0
- package/dist/local/routing.js +193 -0
- package/dist/local/server/ai-scheduler.d.ts +31 -0
- package/dist/local/server/ai-scheduler.js +93 -0
- package/dist/local/server/http-router.d.ts +35 -0
- package/dist/local/server/http-router.js +185 -0
- package/dist/local/server/index.d.ts +16 -0
- package/dist/local/server/index.js +140 -0
- package/dist/local/server/sockets.d.ts +25 -0
- package/dist/local/server/sockets.js +141 -0
- package/dist/local/wasm-engine.d.ts +61 -0
- package/dist/local/wasm-engine.js +63 -0
- package/dist/local/worker-boot.d.ts +17 -0
- package/dist/local/worker-boot.js +76 -0
- package/dist/local/worker.d.ts +6 -0
- package/dist/local/worker.js +9 -0
- package/dist/match-session/access.d.ts +6 -0
- package/dist/match-session/access.js +8 -0
- package/dist/match-session/controller.d.ts +63 -0
- package/dist/match-session/controller.js +513 -0
- package/dist/match-session/errors.d.ts +3 -0
- package/dist/match-session/errors.js +34 -0
- package/dist/match-session/methods.d.ts +433 -0
- package/dist/match-session/methods.js +1 -0
- package/dist/match-session/session-state.d.ts +235 -0
- package/dist/match-session/session-state.js +1 -0
- package/dist/match-session/types.d.ts +56 -0
- package/dist/match-session/types.js +1 -0
- package/dist/match-session.d.ts +3 -0
- package/dist/match-session.js +1 -0
- package/dist/messages.d.ts +195 -0
- package/dist/messages.js +240 -0
- package/dist/resources/admin.d.ts +63 -0
- package/dist/resources/admin.js +75 -0
- package/dist/resources/card-deck-json.d.ts +11 -0
- package/dist/resources/card-deck-json.js +164 -0
- package/dist/resources/card-resolution.d.ts +9 -0
- package/dist/resources/card-resolution.js +21 -0
- package/dist/resources/card-resource.d.ts +157 -0
- package/dist/resources/card-resource.js +28 -0
- package/dist/resources/card-types.d.ts +203 -0
- package/dist/resources/card-types.js +1 -0
- package/dist/resources/cards.d.ts +3 -0
- package/dist/resources/cards.js +1 -0
- package/dist/resources/limited-event-types.d.ts +252 -0
- package/dist/resources/limited-event-types.js +1 -0
- package/dist/resources/limited-events.d.ts +7 -0
- package/dist/resources/limited-events.js +49 -0
- package/dist/resources/lobbies.d.ts +53 -0
- package/dist/resources/lobbies.js +50 -0
- package/dist/resources/lobby-list-session.d.ts +13 -0
- package/dist/resources/lobby-list-session.js +198 -0
- package/dist/resources/lobby-session.d.ts +9 -0
- package/dist/resources/lobby-session.js +59 -0
- package/dist/resources/lobby-types.d.ts +357 -0
- package/dist/resources/lobby-types.js +1 -0
- package/dist/resources/match-history.d.ts +49 -0
- package/dist/resources/match-history.js +34 -0
- package/dist/resources/match-types.d.ts +448 -0
- package/dist/resources/match-types.js +1 -0
- package/dist/resources/matches.d.ts +16 -0
- package/dist/resources/matches.js +109 -0
- package/dist/resources/ranked.d.ts +24 -0
- package/dist/resources/ranked.js +47 -0
- package/dist/resources/session.d.ts +62 -0
- package/dist/resources/session.js +26 -0
- package/dist/resources/system.d.ts +51 -0
- package/dist/resources/system.js +9 -0
- package/dist/resources/tournament-room-session.d.ts +9 -0
- package/dist/resources/tournament-room-session.js +53 -0
- package/dist/resources/tournament-room-types.d.ts +44 -0
- package/dist/resources/tournament-room-types.js +1 -0
- package/dist/resources/tournament-rooms.d.ts +33 -0
- package/dist/resources/tournament-rooms.js +33 -0
- package/dist/session.d.ts +56 -0
- package/dist/session.js +1 -0
- package/dist/types.d.ts +73 -0
- package/dist/types.js +27 -0
- package/dist/validators/ajv.d.ts +51 -0
- package/dist/validators/ajv.js +121 -0
- package/dist/validators/discriminants.d.ts +36 -0
- package/dist/validators/discriminants.js +89 -0
- package/dist/validators/validator.d.ts +73 -0
- package/dist/validators/validator.js +26 -0
- package/dist/validators/warm-up.d.ts +25 -0
- package/dist/validators/warm-up.js +59 -0
- package/dist/validators.d.ts +173 -0
- package/dist/validators.js +85 -0
- package/package.json +88 -0
- package/schema/abandon-match-request.schema.json +15 -0
- package/schema/abandon-match-response.schema.json +15 -0
- package/schema/add-lobby-ai-player-request.schema.json +53 -0
- package/schema/api-error-response.schema.json +13 -0
- package/schema/card-catalog-refresh-response.schema.json +31 -0
- package/schema/cards-response.schema.json +17 -0
- package/schema/client-message.schema.json +203 -0
- package/schema/close-tournament-room-request.schema.json +18 -0
- package/schema/common.schema.json +14129 -0
- package/schema/create-limited-event-request.schema.json +60 -0
- package/schema/create-lobby-request.schema.json +67 -0
- package/schema/create-match-request.schema.json +124 -0
- package/schema/create-meta-window-request.schema.json +27 -0
- package/schema/create-tournament-room-request.schema.json +104 -0
- package/schema/create-tournament-table-request.schema.json +14 -0
- package/schema/error-payload.schema.json +34 -0
- package/schema/format-event-request.schema.json +20 -0
- package/schema/format-event-response.schema.json +15 -0
- package/schema/game-command.schema.json +775 -0
- package/schema/game-event.schema.json +2012 -0
- package/schema/game-state.schema.json +273 -0
- package/schema/get-match-response.schema.json +13 -0
- package/schema/health-response.schema.json +13 -0
- package/schema/join-limited-event-request.schema.json +6 -0
- package/schema/join-lobby-request.schema.json +40 -0
- package/schema/join-match-request.schema.json +79 -0
- package/schema/join-tournament-room-request.schema.json +39 -0
- package/schema/join-tournament-table-request.schema.json +14 -0
- package/schema/kick-lobby-player-request.schema.json +13 -0
- package/schema/kick-lobby-spectator-request.schema.json +14 -0
- package/schema/leave-lobby-request.schema.json +13 -0
- package/schema/leave-match-request.schema.json +15 -0
- package/schema/leave-match-response.schema.json +15 -0
- package/schema/leave-tournament-room-request.schema.json +14 -0
- package/schema/limited-event-access-response.schema.json +34 -0
- package/schema/limited-event-command-request.schema.json +20 -0
- package/schema/limited-event-preflight-response.schema.json +25 -0
- package/schema/limited-event-response.schema.json +15 -0
- package/schema/list-active-ai-matches-request.schema.json +23 -0
- package/schema/list-active-ai-matches-response.schema.json +17 -0
- package/schema/lobby-access-response.schema.json +31 -0
- package/schema/lobby-chat-request.schema.json +17 -0
- package/schema/lobby-chat-response.schema.json +17 -0
- package/schema/lobby-list-response.schema.json +16 -0
- package/schema/lobby-list-server-message.schema.json +49 -0
- package/schema/lobby-matchmaking-decision-request.schema.json +13 -0
- package/schema/lobby-matchmaking-request.schema.json +80 -0
- package/schema/lobby-response.schema.json +13 -0
- package/schema/lobby-server-message.schema.json +155 -0
- package/schema/lobby-sync-request.schema.json +13 -0
- package/schema/manifest.json +124 -0
- package/schema/match-access-response.schema.json +32 -0
- package/schema/match-chat-lookup-response.schema.json +34 -0
- package/schema/match-connection-role.schema.json +9 -0
- package/schema/match-history-deck-stats-request.schema.json +26 -0
- package/schema/match-history-deck-stats-response.schema.json +17 -0
- package/schema/match-history-entry.schema.json +78 -0
- package/schema/match-history-list-request.schema.json +48 -0
- package/schema/match-history-list-response.schema.json +25 -0
- package/schema/match-history-replay-request.schema.json +17 -0
- package/schema/match-history-replay-response.schema.json +14 -0
- package/schema/match-history-restore-request.schema.json +23 -0
- package/schema/match-save-payload.schema.json +71 -0
- package/schema/match-spectator-access-response.schema.json +22 -0
- package/schema/meta-window.schema.json +37 -0
- package/schema/meta-windows-response.schema.json +24 -0
- package/schema/prepare-lobby-limited-ai-decks-request.schema.json +14 -0
- package/schema/ranked-admin-status.schema.json +43 -0
- package/schema/ranked-leaderboard-entry.schema.json +61 -0
- package/schema/ranked-leaderboard-query.schema.json +34 -0
- package/schema/ranked-leaderboard-response.schema.json +23 -0
- package/schema/ranked-matchmaking-view.schema.json +15 -0
- package/schema/ranked-profile-request.schema.json +21 -0
- package/schema/ranked-profile-response.schema.json +59 -0
- package/schema/ranked-queue.schema.json +12 -0
- package/schema/rematch-match-request.schema.json +20 -0
- package/schema/rematch-match-response.schema.json +61 -0
- package/schema/resolve-card-ids-request.schema.json +17 -0
- package/schema/resolve-card-ids-response.schema.json +16 -0
- package/schema/restore-history-response.schema.json +15 -0
- package/schema/restore-match-save-request.schema.json +20 -0
- package/schema/restore-match-save-response.schema.json +29 -0
- package/schema/return-lobby-match-request.schema.json +13 -0
- package/schema/return-tournament-match-request.schema.json +14 -0
- package/schema/route-manifest.json +1014 -0
- package/schema/save-match-request.schema.json +15 -0
- package/schema/server-message.schema.json +192 -0
- package/schema/set-ai-paused-request.schema.json +19 -0
- package/schema/set-ai-paused-response.schema.json +18 -0
- package/schema/set-ranked-admission-request.schema.json +15 -0
- package/schema/set-simulator-maintenance-request.schema.json +20 -0
- package/schema/simulator-admin-status-response.schema.json +37 -0
- package/schema/simulator-availability-response.schema.json +27 -0
- package/schema/simulator-report-list-response.schema.json +23 -0
- package/schema/simulator-report-response.schema.json +77 -0
- package/schema/spectate-lobby-request.schema.json +32 -0
- package/schema/spectate-match-request.schema.json +32 -0
- package/schema/start-lobby-limited-match-request.schema.json +13 -0
- package/schema/start-lobby-request.schema.json +13 -0
- package/schema/start-tournament-event-request.schema.json +14 -0
- package/schema/submit-lobby-limited-deck-request.schema.json +33 -0
- package/schema/submit-match-deck-request.schema.json +45 -0
- package/schema/submit-match-deck-response.schema.json +14 -0
- package/schema/submit-tournament-deck-request.schema.json +34 -0
- package/schema/tournament-event-command-request.schema.json +18 -0
- package/schema/tournament-room-access-response.schema.json +32 -0
- package/schema/tournament-room-chat-request.schema.json +18 -0
- package/schema/tournament-room-chat-response.schema.json +18 -0
- package/schema/tournament-room-list-response.schema.json +17 -0
- package/schema/tournament-room-response.schema.json +14 -0
- package/schema/tournament-room-server-message.schema.json +127 -0
- package/schema/tournament-room-sync-request.schema.json +14 -0
- package/schema/undo-match-request.schema.json +14 -0
- package/schema/undo-match-response.schema.json +14 -0
- package/schema/undo-respond-match-request.schema.json +19 -0
- package/schema/update-lobby-ai-player-request.schema.json +65 -0
- package/schema/update-lobby-player-request.schema.json +81 -0
- package/schema/update-lobby-settings-request.schema.json +70 -0
- package/schema/update-tournament-room-player-request.schema.json +45 -0
- package/schema/update-tournament-room-settings-request.schema.json +33 -0
- package/schema/welcome-payload.schema.json +38 -0
|
@@ -0,0 +1,513 @@
|
|
|
1
|
+
import { MatchConnection } from '../connection.js';
|
|
2
|
+
import { TypedEmitter } from '../internal/emitter.js';
|
|
3
|
+
import { DEFAULT_ERROR_HISTORY_LIMIT, DEFAULT_MATCH_HISTORY_LIMIT } from '../internal/limits.js';
|
|
4
|
+
import { nonNegativeNumber, normalizeReconnectBackoff, reconnectDelayMs, } from '../internal/reconnect-backoff.js';
|
|
5
|
+
import { hasAccessSnapshot, matchReferenceFrom } from './access.js';
|
|
6
|
+
import { errorPayloadFromUnknown } from './errors.js';
|
|
7
|
+
const DEFAULT_EVENT_HISTORY_LIMIT = 50;
|
|
8
|
+
const DEFAULT_RECONNECT_INITIAL_DELAY_MS = 250;
|
|
9
|
+
const DEFAULT_RECONNECT_MAX_DELAY_MS = 5_000;
|
|
10
|
+
const DEFAULT_RECONNECT_MAX_RETRIES = 5;
|
|
11
|
+
const DEFAULT_RECONNECT_BACKOFF_FACTOR = 2;
|
|
12
|
+
/** SDK-owned live match session implementation. */
|
|
13
|
+
export class MatchSessionController {
|
|
14
|
+
/**
|
|
15
|
+
* Vue reactivity opt-out. The controller relies on `#private` class fields
|
|
16
|
+
* which are unreachable through a `Proxy`, so Vue must not wrap it. This
|
|
17
|
+
* is Vue's documented escape hatch (`ReactiveFlags.SKIP`) and is a no-op
|
|
18
|
+
* in non-Vue runtimes.
|
|
19
|
+
*/
|
|
20
|
+
__v_skip = true;
|
|
21
|
+
#defaultConnectOptions;
|
|
22
|
+
#emitter = new TypedEmitter();
|
|
23
|
+
#maxErrorHistory;
|
|
24
|
+
#maxEventHistory;
|
|
25
|
+
#matches;
|
|
26
|
+
#openConnection;
|
|
27
|
+
#autoReconnect;
|
|
28
|
+
#access;
|
|
29
|
+
#connection;
|
|
30
|
+
#connectionState = 'idle';
|
|
31
|
+
#aiStatus;
|
|
32
|
+
#detachConnection = [];
|
|
33
|
+
#errors = [];
|
|
34
|
+
#events = [];
|
|
35
|
+
#history = [];
|
|
36
|
+
#matchId;
|
|
37
|
+
#snapshot;
|
|
38
|
+
#seat;
|
|
39
|
+
#welcome;
|
|
40
|
+
#manualClose = false;
|
|
41
|
+
#reconnectGeneration = 0;
|
|
42
|
+
#reconnectState = { phase: 'idle' };
|
|
43
|
+
#reconnectTimer;
|
|
44
|
+
/** Creates one match session controller. */
|
|
45
|
+
constructor(options) {
|
|
46
|
+
this.#matches = options.matches;
|
|
47
|
+
this.#openConnection = options.openConnection;
|
|
48
|
+
this.#defaultConnectOptions = {
|
|
49
|
+
...(options.options?.handshakeTimeoutMs == null ? {} : { handshakeTimeoutMs: options.options.handshakeTimeoutMs }),
|
|
50
|
+
};
|
|
51
|
+
this.#autoReconnect = normalizeAutoReconnect(options.options?.autoReconnect);
|
|
52
|
+
this.#maxEventHistory = options.options?.maxEventHistory ?? DEFAULT_EVENT_HISTORY_LIMIT;
|
|
53
|
+
this.#maxErrorHistory = options.options?.maxErrorHistory ?? DEFAULT_ERROR_HISTORY_LIMIT;
|
|
54
|
+
if (options.access != null) {
|
|
55
|
+
this.#storeAccess(options.access);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
get connectionState() {
|
|
59
|
+
return this.#connectionState;
|
|
60
|
+
}
|
|
61
|
+
get aiStatus() {
|
|
62
|
+
return this.#aiStatus;
|
|
63
|
+
}
|
|
64
|
+
get errors() {
|
|
65
|
+
return [...this.#errors];
|
|
66
|
+
}
|
|
67
|
+
get events() {
|
|
68
|
+
return [...this.#events];
|
|
69
|
+
}
|
|
70
|
+
get history() {
|
|
71
|
+
return [...this.#history];
|
|
72
|
+
}
|
|
73
|
+
get errorMessages() {
|
|
74
|
+
return this.#errors.map(error => `${error.code} - ${error.message}`);
|
|
75
|
+
}
|
|
76
|
+
get matchId() {
|
|
77
|
+
return this.#matchId;
|
|
78
|
+
}
|
|
79
|
+
get reconnectState() {
|
|
80
|
+
return this.#reconnectState;
|
|
81
|
+
}
|
|
82
|
+
get snapshot() {
|
|
83
|
+
return this.#snapshot;
|
|
84
|
+
}
|
|
85
|
+
get seat() {
|
|
86
|
+
return this.#seat;
|
|
87
|
+
}
|
|
88
|
+
get state() {
|
|
89
|
+
return {
|
|
90
|
+
...(this.#aiStatus == null ? {} : { aiStatus: this.#aiStatus }),
|
|
91
|
+
connectionState: this.#connectionState,
|
|
92
|
+
errors: this.errors,
|
|
93
|
+
errorMessages: this.errorMessages,
|
|
94
|
+
events: this.events,
|
|
95
|
+
history: this.history,
|
|
96
|
+
...(this.#matchId == null ? {} : { matchId: this.#matchId }),
|
|
97
|
+
reconnectState: this.#reconnectState,
|
|
98
|
+
...(this.#snapshot == null ? {} : { snapshot: this.#snapshot }),
|
|
99
|
+
...(this.#seat == null ? {} : { seat: this.#seat }),
|
|
100
|
+
...(this.#welcome == null ? {} : { welcome: this.#welcome }),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
get welcome() {
|
|
104
|
+
return this.#welcome;
|
|
105
|
+
}
|
|
106
|
+
async connect(access, options = {}) {
|
|
107
|
+
this.#cancelAutoReconnect();
|
|
108
|
+
this.#manualClose = false;
|
|
109
|
+
const connectOptions = { ...this.#defaultConnectOptions, ...options };
|
|
110
|
+
if (access != null) {
|
|
111
|
+
this.#resetMatchState();
|
|
112
|
+
this.#storeAccess(access);
|
|
113
|
+
}
|
|
114
|
+
if (this.#access == null) {
|
|
115
|
+
const error = new Error('match session has no access');
|
|
116
|
+
this.#recordError(errorPayloadFromUnknown(error));
|
|
117
|
+
throw error;
|
|
118
|
+
}
|
|
119
|
+
// Keep an already-open socket alive through the replacement handshake.
|
|
120
|
+
// The server sees the new lease before this one drops, so a manual sync
|
|
121
|
+
// replacement remains one logical presence instead of disconnect/reconnect.
|
|
122
|
+
const previousConnection = this.#connection;
|
|
123
|
+
const previousDetachers = this.#detachConnection;
|
|
124
|
+
this.#setConnectionState('connecting');
|
|
125
|
+
try {
|
|
126
|
+
const connection = await this.#openConnection(this.#access, connectOptions);
|
|
127
|
+
if (previousConnection != null) {
|
|
128
|
+
for (const detach of previousDetachers) {
|
|
129
|
+
detach();
|
|
130
|
+
}
|
|
131
|
+
this.#detachConnection = [];
|
|
132
|
+
previousConnection.close();
|
|
133
|
+
}
|
|
134
|
+
this.#connection = connection;
|
|
135
|
+
this.#attachConnection(connection);
|
|
136
|
+
this.#setConnectionState(connection.connectionState);
|
|
137
|
+
this.#seedFromConnection(connection);
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
// A failed replacement leaves the old live connection usable.
|
|
142
|
+
this.#setConnectionState(previousConnection?.connectionState ?? 'closed');
|
|
143
|
+
this.#recordError(errorPayloadFromUnknown(error));
|
|
144
|
+
throw error;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
async createMatch(request, options = {}) {
|
|
148
|
+
this.#resetMatchState();
|
|
149
|
+
let access;
|
|
150
|
+
try {
|
|
151
|
+
access = await this.#matches.create(request);
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
this.#recordError(errorPayloadFromUnknown(error));
|
|
155
|
+
throw error;
|
|
156
|
+
}
|
|
157
|
+
this.#storeAccess(access);
|
|
158
|
+
await this.connect(undefined, options);
|
|
159
|
+
return access;
|
|
160
|
+
}
|
|
161
|
+
async joinMatch(match, request, options = {}) {
|
|
162
|
+
this.#resetMatchState();
|
|
163
|
+
let access;
|
|
164
|
+
try {
|
|
165
|
+
access = await this.#matches.join(matchReferenceFrom(match), request);
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
this.#recordError(errorPayloadFromUnknown(error));
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
this.#storeAccess(access);
|
|
172
|
+
await this.connect(undefined, options);
|
|
173
|
+
return access;
|
|
174
|
+
}
|
|
175
|
+
async spectateMatch(match, request, options = {}) {
|
|
176
|
+
this.#resetMatchState();
|
|
177
|
+
let access;
|
|
178
|
+
try {
|
|
179
|
+
access = await this.#matches.spectate(matchReferenceFrom(match), request);
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
this.#recordError(errorPayloadFromUnknown(error));
|
|
183
|
+
throw error;
|
|
184
|
+
}
|
|
185
|
+
this.#storeAccess(access);
|
|
186
|
+
await this.connect(undefined, options);
|
|
187
|
+
return access;
|
|
188
|
+
}
|
|
189
|
+
close() {
|
|
190
|
+
this.#manualClose = true;
|
|
191
|
+
this.#cancelAutoReconnect();
|
|
192
|
+
this.#closeActiveConnection();
|
|
193
|
+
this.#setConnectionState('closed');
|
|
194
|
+
}
|
|
195
|
+
reconnect(options = {}) {
|
|
196
|
+
return this.connect(undefined, options);
|
|
197
|
+
}
|
|
198
|
+
ready() {
|
|
199
|
+
this.#activeConnection().ready();
|
|
200
|
+
}
|
|
201
|
+
undo() {
|
|
202
|
+
this.#activeConnection().undo();
|
|
203
|
+
}
|
|
204
|
+
respondUndo(approve) {
|
|
205
|
+
this.#activeConnection().respondUndo(approve);
|
|
206
|
+
}
|
|
207
|
+
setAiPaused(paused) {
|
|
208
|
+
this.#activeConnection().setAiPaused(paused);
|
|
209
|
+
}
|
|
210
|
+
sync() {
|
|
211
|
+
this.#activeConnection().sync();
|
|
212
|
+
}
|
|
213
|
+
ping(nonce) {
|
|
214
|
+
this.#activeConnection().ping(nonce);
|
|
215
|
+
}
|
|
216
|
+
sendCommand(command) {
|
|
217
|
+
this.#activeConnection().sendCommand(command);
|
|
218
|
+
}
|
|
219
|
+
sendFormatEvent(command) {
|
|
220
|
+
this.#activeConnection().sendFormatEvent(command);
|
|
221
|
+
}
|
|
222
|
+
sendAiFormatEvent(command) {
|
|
223
|
+
this.#activeConnection().sendAiFormatEvent(command);
|
|
224
|
+
}
|
|
225
|
+
sendChat(message) {
|
|
226
|
+
this.#activeConnection().sendChat(message);
|
|
227
|
+
}
|
|
228
|
+
sendInteractionCue(cue) {
|
|
229
|
+
this.#activeConnection().sendInteractionCue(cue);
|
|
230
|
+
}
|
|
231
|
+
on(event, listener) {
|
|
232
|
+
return this.#emitter.on(event, listener);
|
|
233
|
+
}
|
|
234
|
+
waitForSnapshot(predicate, options = {}) {
|
|
235
|
+
return this.#activeConnection().waitForSnapshot(predicate, options.timeoutMs == null ? {} : { timeoutMs: options.timeoutMs });
|
|
236
|
+
}
|
|
237
|
+
#activeConnection() {
|
|
238
|
+
if (this.#connection == null) {
|
|
239
|
+
throw new Error('match session is not connected');
|
|
240
|
+
}
|
|
241
|
+
return this.#connection;
|
|
242
|
+
}
|
|
243
|
+
#attachConnection(connection) {
|
|
244
|
+
this.#detachConnection = [
|
|
245
|
+
connection.on('connectionState', state => {
|
|
246
|
+
this.#setConnectionState(state);
|
|
247
|
+
if (state === 'closed') {
|
|
248
|
+
this.#handleAbnormalClose(connection);
|
|
249
|
+
}
|
|
250
|
+
}),
|
|
251
|
+
connection.on('welcome', welcome => this.#setWelcome(welcome)),
|
|
252
|
+
connection.on('snapshot', snapshot => this.#setSnapshot(snapshot)),
|
|
253
|
+
connection.on('event', event => this.#recordEvent(event)),
|
|
254
|
+
connection.on('historySnapshot', snapshot => this.#setHistorySnapshot(snapshot)),
|
|
255
|
+
connection.on('historyEntry', entry => this.#recordHistoryEntry(entry)),
|
|
256
|
+
connection.on('interactionCue', cue => this.#emitInteractionCue(cue)),
|
|
257
|
+
connection.on('aiStatus', status => this.#setAiStatus(status)),
|
|
258
|
+
connection.on('error', error => this.#recordError(error)),
|
|
259
|
+
connection.on('message', message => this.#emitter.emit('message', message)),
|
|
260
|
+
connection.on('pong', pong => this.#emitter.emit('pong', pong)),
|
|
261
|
+
];
|
|
262
|
+
}
|
|
263
|
+
#detachActiveConnection() {
|
|
264
|
+
for (const detach of this.#detachConnection) {
|
|
265
|
+
detach();
|
|
266
|
+
}
|
|
267
|
+
this.#detachConnection = [];
|
|
268
|
+
}
|
|
269
|
+
#closeActiveConnection() {
|
|
270
|
+
const activeConnection = this.#connection;
|
|
271
|
+
this.#detachActiveConnection();
|
|
272
|
+
this.#connection = undefined;
|
|
273
|
+
activeConnection?.close();
|
|
274
|
+
}
|
|
275
|
+
#cancelAutoReconnect() {
|
|
276
|
+
this.#reconnectGeneration += 1;
|
|
277
|
+
if (this.#reconnectTimer != null) {
|
|
278
|
+
clearTimeout(this.#reconnectTimer);
|
|
279
|
+
this.#reconnectTimer = undefined;
|
|
280
|
+
}
|
|
281
|
+
this.#setReconnectState({ phase: 'idle' });
|
|
282
|
+
}
|
|
283
|
+
#emitChange() {
|
|
284
|
+
this.#emitter.emit('change', this.state);
|
|
285
|
+
}
|
|
286
|
+
#recordError(error) {
|
|
287
|
+
// Bounded like the event feed: a flapping socket records one error per
|
|
288
|
+
// failed reconnect, so an uncapped buffer would grow for the whole session.
|
|
289
|
+
const errors = [...this.#errors, error];
|
|
290
|
+
this.#errors = this.#maxErrorHistory <= 0 ? [] : errors.slice(-this.#maxErrorHistory);
|
|
291
|
+
this.#emitter.emit('error', error);
|
|
292
|
+
this.#emitChange();
|
|
293
|
+
}
|
|
294
|
+
#recordEvent(event) {
|
|
295
|
+
const events = [...this.#events, event];
|
|
296
|
+
this.#events = this.#maxEventHistory <= 0 ? [] : events.slice(-this.#maxEventHistory);
|
|
297
|
+
this.#emitter.emit('event', event);
|
|
298
|
+
this.#emitChange();
|
|
299
|
+
}
|
|
300
|
+
#setHistorySnapshot(snapshot) {
|
|
301
|
+
this.#history = [...snapshot.entries];
|
|
302
|
+
this.#emitter.emit('historySnapshot', snapshot);
|
|
303
|
+
this.#emitChange();
|
|
304
|
+
}
|
|
305
|
+
#recordHistoryEntry(entry) {
|
|
306
|
+
const withoutDuplicate = this.#history.filter(existing => existing.id !== entry.id);
|
|
307
|
+
this.#history = [...withoutDuplicate, entry].slice(-DEFAULT_MATCH_HISTORY_LIMIT);
|
|
308
|
+
this.#emitter.emit('historyEntry', entry);
|
|
309
|
+
this.#emitChange();
|
|
310
|
+
}
|
|
311
|
+
#emitInteractionCue(cue) {
|
|
312
|
+
this.#emitter.emit('interactionCue', cue);
|
|
313
|
+
}
|
|
314
|
+
#resetMatchState() {
|
|
315
|
+
this.close();
|
|
316
|
+
this.#access = undefined;
|
|
317
|
+
this.#aiStatus = undefined;
|
|
318
|
+
this.#errors = [];
|
|
319
|
+
this.#events = [];
|
|
320
|
+
this.#history = [];
|
|
321
|
+
this.#matchId = undefined;
|
|
322
|
+
this.#snapshot = undefined;
|
|
323
|
+
this.#seat = undefined;
|
|
324
|
+
this.#welcome = undefined;
|
|
325
|
+
this.#setConnectionState('idle');
|
|
326
|
+
this.#emitChange();
|
|
327
|
+
}
|
|
328
|
+
#handleAbnormalClose(connection) {
|
|
329
|
+
if (this.#connection !== connection) {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
this.#detachActiveConnection();
|
|
333
|
+
this.#connection = undefined;
|
|
334
|
+
if (this.#manualClose || !this.#autoReconnect.enabled || this.#access == null) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
this.#scheduleAutoReconnect(1, this.#reconnectGeneration);
|
|
338
|
+
}
|
|
339
|
+
#scheduleAutoReconnect(attempt, generation) {
|
|
340
|
+
if (attempt > this.#autoReconnect.maxRetries) {
|
|
341
|
+
this.#setReconnectState({
|
|
342
|
+
phase: 'exhausted',
|
|
343
|
+
attempts: this.#autoReconnect.maxRetries,
|
|
344
|
+
maxAttempts: this.#autoReconnect.maxRetries,
|
|
345
|
+
});
|
|
346
|
+
this.#recordError({
|
|
347
|
+
code: 'sdk_session_error',
|
|
348
|
+
message: 'automatic reconnect exhausted',
|
|
349
|
+
});
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
const delayMs = reconnectDelayMs(this.#autoReconnect, attempt);
|
|
353
|
+
this.#setReconnectState({
|
|
354
|
+
phase: 'waiting',
|
|
355
|
+
attempt,
|
|
356
|
+
maxAttempts: this.#autoReconnect.maxRetries,
|
|
357
|
+
delayMs,
|
|
358
|
+
});
|
|
359
|
+
this.#reconnectTimer = setTimeout(() => {
|
|
360
|
+
this.#reconnectTimer = undefined;
|
|
361
|
+
void this.#runAutoReconnectAttempt(attempt, generation);
|
|
362
|
+
}, delayMs);
|
|
363
|
+
}
|
|
364
|
+
async #runAutoReconnectAttempt(attempt, generation) {
|
|
365
|
+
if (generation !== this.#reconnectGeneration || this.#manualClose || this.#access == null) {
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
this.#setReconnectState({
|
|
369
|
+
phase: 'connecting',
|
|
370
|
+
attempt,
|
|
371
|
+
maxAttempts: this.#autoReconnect.maxRetries,
|
|
372
|
+
});
|
|
373
|
+
this.#setConnectionState('connecting');
|
|
374
|
+
try {
|
|
375
|
+
const connection = await this.#openConnection(this.#access, this.#defaultConnectOptions);
|
|
376
|
+
if (generation !== this.#reconnectGeneration || this.#manualClose) {
|
|
377
|
+
connection.close();
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
this.#connection = connection;
|
|
381
|
+
this.#attachConnection(connection);
|
|
382
|
+
this.#setConnectionState(connection.connectionState);
|
|
383
|
+
this.#seedFromConnection(connection);
|
|
384
|
+
this.#setReconnectState({ phase: 'idle' });
|
|
385
|
+
connection.sync();
|
|
386
|
+
}
|
|
387
|
+
catch (error) {
|
|
388
|
+
if (generation !== this.#reconnectGeneration || this.#manualClose) {
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
if (attempt >= this.#autoReconnect.maxRetries) {
|
|
392
|
+
this.#recordError(errorPayloadFromUnknown(error));
|
|
393
|
+
this.#recordError({
|
|
394
|
+
code: 'sdk_session_error',
|
|
395
|
+
message: 'automatic reconnect exhausted',
|
|
396
|
+
});
|
|
397
|
+
this.#setReconnectState({
|
|
398
|
+
phase: 'exhausted',
|
|
399
|
+
attempts: attempt,
|
|
400
|
+
maxAttempts: this.#autoReconnect.maxRetries,
|
|
401
|
+
});
|
|
402
|
+
this.#setConnectionState('closed');
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
this.#setConnectionState('closed');
|
|
406
|
+
this.#scheduleAutoReconnect(attempt + 1, generation);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
#seedFromConnection(connection) {
|
|
410
|
+
if (connection.aiStatus != null) {
|
|
411
|
+
this.#setAiStatus(connection.aiStatus);
|
|
412
|
+
}
|
|
413
|
+
if (connection.welcome != null) {
|
|
414
|
+
this.#setWelcome(connection.welcome);
|
|
415
|
+
}
|
|
416
|
+
if (connection.snapshot != null) {
|
|
417
|
+
this.#setSnapshot(connection.snapshot);
|
|
418
|
+
}
|
|
419
|
+
if (connection.historySnapshotReceived) {
|
|
420
|
+
// Empty recovery history is meaningful: consumers use this notification
|
|
421
|
+
// to baseline presence toasts before later live entries arrive.
|
|
422
|
+
this.#setHistorySnapshot({
|
|
423
|
+
snapshotRevision: connection.snapshotRevision,
|
|
424
|
+
entries: [...connection.history],
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
#setConnectionState(state) {
|
|
429
|
+
if (this.#connectionState === state) {
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
this.#connectionState = state;
|
|
433
|
+
this.#emitter.emit('connectionState', state);
|
|
434
|
+
this.#emitChange();
|
|
435
|
+
}
|
|
436
|
+
#setReconnectState(state) {
|
|
437
|
+
if (sameReconnectState(this.#reconnectState, state)) {
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
this.#reconnectState = state;
|
|
441
|
+
this.#emitter.emit('reconnectState', state);
|
|
442
|
+
this.#emitChange();
|
|
443
|
+
}
|
|
444
|
+
#setAiStatus(status) {
|
|
445
|
+
this.#aiStatus = status;
|
|
446
|
+
this.#emitter.emit('aiStatus', status);
|
|
447
|
+
this.#emitChange();
|
|
448
|
+
}
|
|
449
|
+
#setSnapshot(snapshot) {
|
|
450
|
+
this.#snapshot = snapshot;
|
|
451
|
+
this.#matchId = snapshot.matchId;
|
|
452
|
+
this.#emitter.emit('snapshot', snapshot);
|
|
453
|
+
this.#emitChange();
|
|
454
|
+
}
|
|
455
|
+
#setWelcome(welcome) {
|
|
456
|
+
this.#welcome = welcome;
|
|
457
|
+
this.#matchId = welcome.matchId;
|
|
458
|
+
this.#seat = welcome.seat ?? undefined;
|
|
459
|
+
this.#emitter.emit('welcome', welcome);
|
|
460
|
+
this.#emitChange();
|
|
461
|
+
}
|
|
462
|
+
#storeAccess(access) {
|
|
463
|
+
this.#access = 'spectatorToken' in access
|
|
464
|
+
? {
|
|
465
|
+
matchId: access.matchId,
|
|
466
|
+
spectatorToken: access.spectatorToken,
|
|
467
|
+
}
|
|
468
|
+
: {
|
|
469
|
+
matchId: access.matchId,
|
|
470
|
+
seatToken: access.seatToken,
|
|
471
|
+
};
|
|
472
|
+
this.#matchId = access.matchId;
|
|
473
|
+
if (hasAccessSnapshot(access)) {
|
|
474
|
+
this.#seat = 'seat' in access ? access.seat : undefined;
|
|
475
|
+
this.#snapshot = access.snapshot;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
function normalizeAutoReconnect(options) {
|
|
480
|
+
const policy = normalizeReconnectBackoff(options, {
|
|
481
|
+
enabled: false,
|
|
482
|
+
backoffFactor: DEFAULT_RECONNECT_BACKOFF_FACTOR,
|
|
483
|
+
initialDelayMs: DEFAULT_RECONNECT_INITIAL_DELAY_MS,
|
|
484
|
+
maxDelayMs: DEFAULT_RECONNECT_MAX_DELAY_MS,
|
|
485
|
+
});
|
|
486
|
+
const optionPolicy = options === true || options === false || options == null ? {} : options;
|
|
487
|
+
return {
|
|
488
|
+
...policy,
|
|
489
|
+
maxRetries: Math.max(0, Math.floor(nonNegativeNumber(optionPolicy.maxRetries, DEFAULT_RECONNECT_MAX_RETRIES))),
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
function sameReconnectState(left, right) {
|
|
493
|
+
if (left.phase !== right.phase) {
|
|
494
|
+
return false;
|
|
495
|
+
}
|
|
496
|
+
switch (left.phase) {
|
|
497
|
+
case 'idle':
|
|
498
|
+
return true;
|
|
499
|
+
case 'waiting':
|
|
500
|
+
return right.phase === 'waiting'
|
|
501
|
+
&& left.attempt === right.attempt
|
|
502
|
+
&& left.maxAttempts === right.maxAttempts
|
|
503
|
+
&& left.delayMs === right.delayMs;
|
|
504
|
+
case 'connecting':
|
|
505
|
+
return right.phase === 'connecting'
|
|
506
|
+
&& left.attempt === right.attempt
|
|
507
|
+
&& left.maxAttempts === right.maxAttempts;
|
|
508
|
+
case 'exhausted':
|
|
509
|
+
return right.phase === 'exhausted'
|
|
510
|
+
&& left.attempts === right.attempts
|
|
511
|
+
&& left.maxAttempts === right.maxAttempts;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { EngineHttpError, SimulatorSocketError, SdkValidationError, socketPayloadCodeForKind, } from '../internal/errors.js';
|
|
2
|
+
/** Converts arbitrary thrown values into renderable SDK error payloads. */
|
|
3
|
+
export function errorPayloadFromUnknown(error) {
|
|
4
|
+
if (error instanceof EngineHttpError) {
|
|
5
|
+
return {
|
|
6
|
+
code: error.code ?? 'sdk_http_error',
|
|
7
|
+
message: error.message,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
if (error instanceof SimulatorSocketError) {
|
|
11
|
+
// A rejection close frame names the engine error that refused the socket;
|
|
12
|
+
// keep it so clients map the failure exactly like the HTTP equivalent.
|
|
13
|
+
return {
|
|
14
|
+
code: error.serverCode ?? socketPayloadCodeForKind(error.kind),
|
|
15
|
+
message: error.message,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
if (error instanceof SdkValidationError) {
|
|
19
|
+
return {
|
|
20
|
+
code: 'sdk_validation_error',
|
|
21
|
+
message: error.message,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (error instanceof Error) {
|
|
25
|
+
return {
|
|
26
|
+
code: 'sdk_session_error',
|
|
27
|
+
message: error.message,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
code: 'sdk_session_error',
|
|
32
|
+
message: String(error),
|
|
33
|
+
};
|
|
34
|
+
}
|