Files
scrying-pool/module.js
T
uberwald 5ba7717ecd Fix Story 1.3: StateStore spec compliance and minor cleanup
Critical Fix:
- StateStore now uses global Hooks.callAll directly (per spec)
- Removed hooks parameter from StateStore constructor
- Updated module.js to pass only adapter.settings
- Updated tests to stub globalThis.Hooks

Minor Cleanup:
- Fixed misleading warning in SocketHandler.registerPendingOp
- Added clarifying comment for setMatrix _revision behavior

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-05-22 11:38:45 +02:00

84 lines
3.0 KiB
JavaScript

// @ts-nocheck — Module entry point with FoundryVTT globals, no exports needed
/**
* module.js — Entry point and wiring diagram for Video View Manager (Scrying Pool).
*
* This file is the wiring diagram ONLY. It imports all modules, constructs them
* with injected dependencies, and holds NO business logic.
*
* Initialisation order:
* Hooks.once('init') → register world settings → construct FoundryAdapter
* → StateStore → SocketHandler (queue+drain)
* Hooks.once('ready') → hydrate StateStore → probe WebRTC
* → Story 1.4: VisibilityManager → SocketHandler.setReady()
* → NotificationBus → RoleRenderer → RosterStrip
* → DirectorsBoard (lazy, GM only)
*/
import { FoundryAdapter } from './src/foundry/FoundryAdapter.js';
import { StateStore } from './src/core/StateStore.js';
import { SocketHandler } from './src/core/SocketHandler.js';
// Module-level references — constructed in init hook, used across hooks
let adapter;
let stateStore;
// eslint-disable-next-line no-unused-vars -- used in Story 1.4 (socketHandler.setReady)
let socketHandler;
Hooks.once("init", () => {
console.log("[ScryingPool] init — module loading");
// OQ-1 resolved (Story 1.2 spike): probe result is 'css-fallback' — see FoundryAdapter.js
game.settings.register("scrying-pool", "webrtcMode", {
scope: "world",
config: false,
type: String,
default: "css-fallback",
choices: {
"track-disable": "Track Disable (bandwidth-saving)",
"css-fallback": "CSS Fallback (cosmetic hiding)",
"unsupported": "Unsupported (AV not available)",
},
});
// Construct adapter first — needed for settings registration
adapter = new FoundryAdapter(game);
// Story 1.3: register remaining world settings via adapter
adapter.settings.register("visibilityMatrix", {
scope: "world",
config: false,
type: Object,
default: { _version: 1, matrix: {} },
});
adapter.settings.register("showGMSelfFeed", {
scope: "world",
config: true,
type: Boolean,
default: true,
});
// Construct data layer — constructors are side-effect-free
stateStore = new StateStore(adapter.settings);
socketHandler = new SocketHandler(adapter.socket, adapter.hooks);
});
Hooks.once("ready", () => {
console.log("[ScryingPool] ready — module active");
// Hydrate StateStore from persisted world setting (AC-6, AC-7)
stateStore.init();
// Probe WebRTC capability and set adapter.webrtc (AC-8)
const outcome = FoundryAdapter.probeCapability(game.webrtc);
adapter.webrtc = outcome === 'track-disable'
? FoundryAdapter.buildWebRTCSurface(game.webrtc)
: null;
adapter.settings.set(FoundryAdapter.SETTING_WEBRTC_MODE, outcome).catch(err => {
console.error('[ScryingPool] Failed to set webrtcMode setting:', err);
});
// Story 1.4: construct VisibilityManager and call socketHandler.setReady(visibilityManager)
});