194 lines
13 KiB
Markdown
194 lines
13 KiB
Markdown
# Adaptive Music architecture — 0.5.0 local release candidate
|
|
|
|
Independent project by **CheddahBoxMB**, system-independent, targeting Foundry
|
|
**v14.371** and MA **2.10.6**. Standard distribution is **one Foundry module ZIP**
|
|
with a stable Git-hosted manifest and immutable version-specific download URL.
|
|
No mandatory Foundry modules, containers, VMs/LXCs, sandbox runtime, core patches,
|
|
OS-service installer, subscription or telemetry. Planned Gitea URLs are configured
|
|
but the host/repository has not been contacted or confirmed to exist.
|
|
|
|
## Decision after reevaluation
|
|
|
|
The 0.4.0 companion is **not a mandatory architecture**. Native playback and all
|
|
scene/world/combat/boss/manual rules remain entirely module-local. The preferred
|
|
MA experiment is a trusted GM-browser host using the official Sendspin browser
|
|
SDK, Web Audio and WebRTC audio tracks. Its feasibility is conditional on secure
|
|
private MA reachability, an authorized existing receiver identity, GM availability,
|
|
participant capabilities and a working ICE path. It cannot yet be represented as
|
|
reliable module-only remote MA audio for arbitrary networks.
|
|
|
|
The validated companion remains under `gateway/` and local branch
|
|
`experimental/companion-0.4.0`; provider/catalog/restoration code is preserved.
|
|
Shared Web Crypto transport/provider implementations now serve both GM and optional
|
|
companion, with compatibility exports at the original gateway paths. All original
|
|
regressions remain. If the browser gates cannot be met, propose one manually run,
|
|
restricted process **co-located on the existing Foundry host**. No new machine,
|
|
container or automatic service is proposed or deployed. Placement/routing and any
|
|
manual service registration require explicit approval after concrete review.
|
|
|
|
```mermaid
|
|
flowchart LR
|
|
F[Foundry scene and combat policy] --> C[Existing serialized controller]
|
|
C --> N[Owned native playlist provider]
|
|
C --> M[Shared guarded MA provider in trusted GM browser]
|
|
M -->|private authenticated API WebSocket| A[Private MA 2.10.6]
|
|
A -->|authenticated Sendspin to pinned existing identity| S[Official SDK in GM browser]
|
|
S --> W[Web Audio MediaStream]
|
|
W -->|DTLS SRTP media tracks| P[Authorized player browsers]
|
|
G[Foundry module socket] <-->|bounded encrypted SDP only| S
|
|
G <-->|bounded encrypted SDP only| P
|
|
```
|
|
|
|
No raw audio or MA token uses the ordinary module socket. No MA HTTP/WS/Sendspin
|
|
proxy is exposed to players. No microphone is requested and no RTC control data
|
|
channel is accepted. A GM's credentials are **not hidden from that GM/browser user**;
|
|
all code executing in that browser origin must be trusted. Other player browsers
|
|
never receive the MA credential, SDK identity, private queue snapshots or endpoint.
|
|
|
|
## What is measured
|
|
|
|
`evidence/browser-audio.json`: actual Chromium **143.0.7499.4**, two independent
|
|
listener browser contexts, original 440 Hz synthetic PCM encoded in Sendspin binary
|
|
frames and decoded by the pinned official SDK, Web Audio -> WebRTC -> HTMLAudio /
|
|
listener analyser. Both listeners had signal after **1,757 ms**, FFT peak **445.3125
|
|
Hz** (bin resolution around the 440 Hz source), RMS about **0.054**, aggregate GM RTP
|
|
payload **42.3 kbps** over **4.766 seconds**. Four encrypted signaling messages,
|
|
maximum **2,078 bytes**; no audio on the signaling channel. Localhost, no TURN, no
|
|
MA/Noise handshake, no real Foundry socket, no hardware audibility claim, no WAN,
|
|
interlistener skew or long-run drift measurement. These are synthetic path results,
|
|
not MA playlist playback or synchronization verification.
|
|
|
|
Live dedicated target/queue reads still verify the existing DEV identity and an
|
|
empty idle queue. `module-only-prerequisites.json`: the configured MA origin is
|
|
HTTP, the HTTPS-host access policy rejects it as mixed content, and no authorized
|
|
DEV private SDK identity is available locally. **Zero new Sendspin connections,
|
|
identities or playback mutations.** Earlier read-only catalogs and bounded idle
|
|
controls remain separate evidence; synthetic ingestion previously failed.
|
|
|
|
## Browser access and GM-local authentication
|
|
|
|
`GMAudioHost` uses a private, memory-only profile supplied by the GM, with canonical
|
|
MA origin, dedicated target ID/name/provider, approved provider filter, catalog key/
|
|
namespace and existing SDK identity/pairing storage. Nothing is saved into Foundry
|
|
settings, flags, browser localStorage, module socket or a release. Catalog IDs remain
|
|
HMAC-derived and stable when the operator retains the same private key/namespace.
|
|
|
|
The official public `/ws` control API avoids dependence on cross-origin HTTP `/api`
|
|
preflight, which is not configured for that route in the inspected MA pin. The same
|
|
fixed client command allowlist, response bounds, timeout, redirect policy, target
|
|
checks and registered-media rules are preserved through the WebSocket adapter.
|
|
Its initial auth command carries the GM's token in a private connection, never a
|
|
URL; unsolicited events are discarded. The Sendspin `/sendspin` connection uses
|
|
the official frontend's first-message auth pattern, then the official SDK's Noise
|
|
transport. The SDK's fixed roles include controller/metadata; it runs only in the
|
|
trusted GM host, never as a supposedly restricted player listener.
|
|
|
|
A source-derived privacy gate matters: pinned MA `websocket_client.py` logs raw
|
|
received frames at VERBOSE, including auth. The GM profile requires an explicit
|
|
operator `webSocketAuthLogSafe` acknowledgment after ensuring such payload logging
|
|
is disabled. This has **not** been verified live or changed by the agent. No live
|
|
WebSocket token test was attempted. The module logs no credential and does not
|
|
modify MA logging/core. An adapter cannot redact the remote server's own logs.
|
|
|
|
HTTPS Foundry -> plain HTTP/ws private MA is not a generally portable browser path,
|
|
even with encrypted Sendspin payloads. CSP, browser local-network access rules,
|
|
Origin policy, TLS trust and private routing still apply. Current policy refuses
|
|
that deployment rather than disabling browser protections. Local-network exceptions
|
|
in particular browsers are not a cross-browser guarantee. A private trusted HTTPS/
|
|
WSS MA endpoint reachable by the GM, or the approved co-located restricted worker,
|
|
is required. Players do not need MA network access.
|
|
|
|
SDK identity is derived from an X25519 private key. A player name or ID alone cannot
|
|
reconstruct it. The code checks the supplied identity matches **Adaptive Music DEV**
|
|
before any receiver connection; no random replacement, discovery-and-select, pairing
|
|
or internal virtual-player provisioning occurs. Operator-controlled handover from
|
|
the original web player is needed. Read-only identity/topology checks may inspect
|
|
the known unavailable target during handover; every mutation still requires full
|
|
availability, exact name/provider, own active queue and standalone topology.
|
|
|
|
## WebRTC signaling, authorization and transport
|
|
|
|
Foundry's supported `game.socket`/module channel is a relay, not an authenticated
|
|
claim of sender identity. We do **not** trust a payload `userId`/`isGM` or assume
|
|
that broadcast destinations enforce confidentiality. The GM explicitly issues a
|
|
unique short-lived 256-bit per-listener invitation, delivered over an authenticated
|
|
private channel outside the module broadcast. Possession authorizes only that peer;
|
|
it does not prove a Foundry login cryptographically, and a recipient can forward
|
|
its own capability/audio. No automatically broadcast bootstrap exists.
|
|
|
|
`SignalCodec` authenticates/encrypts SDP (including ICE addresses/DTLS fingerprints)
|
|
with AES-GCM, session/peer/direction/sequence binding, nonce, expiry, size/type limits
|
|
and replay checks rechecked after asynchronous decryption. A listener can affect
|
|
only its own peer; another peer has another key. `PeerAudio` permits one recvonly
|
|
listener offer and audio-only answer, rejects video/data/outbound listener audio,
|
|
bounds peers, drops unknown frames, permits at most two explicit ICE restarts, and
|
|
revokes on expiry, disconnect or authorization reconciliation. Continuous media is
|
|
browser-managed DTLS-SRTP, never JSON PCM over Foundry sockets.
|
|
|
|
Default ICE servers are **empty**: no silent external STUN/TURN or telemetry.
|
|
Operator-provided STUN/TURN configuration is explicit. TURN credentials must be
|
|
short-lived; relay-only mode requires TURN and avoids direct peer candidates.
|
|
Authorized peers can inspect their own ICE/network details and credentials. Direct
|
|
P2P may disclose GM/peer network addresses to the authorized peer; encryption hides
|
|
SDP from other world clients, not its intended recipient. No secrets are protected
|
|
from the browser's own user. Existing public-interface references:
|
|
[Foundry Game/socket](https://foundryvtt.com/api/v14/classes/foundry.Game.html),
|
|
[WebRTC connectivity](https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API/Connectivity),
|
|
[mixed content](https://developer.mozilla.org/en-US/docs/Web/Security/Defenses/Mixed_content).
|
|
|
|
Symmetric NAT, CGNAT, UDP filtering and restrictive corporate networks can need TURN;
|
|
STUN alone cannot guarantee connectivity. A relay must already exist or be separately
|
|
approved, not installed as another container/VM by this module. One GM peer connection
|
|
per listener means approximately linear GM upload/encoding cost. The 42.3 kbps local
|
|
measurement is two listeners and short synthetic content, not a capacity promise.
|
|
Browser jitter buffers, suspend/background policy and output devices introduce
|
|
independent playout delay: Sendspin's upstream timestamps do not create synchronized
|
|
WebRTC outputs automatically. Measure WAN jitter/skew and 30-minute drift before any
|
|
sync guarantee. Crossfade and concurrent ambient layers remain unimplemented.
|
|
|
|
## Authority, lifecycle and restoration
|
|
|
|
Policy remains manual (including silence) > explicit eligible boss > started active
|
|
combat for the scene > scene ambient > world default > silence. Bosses use module
|
|
flags/priority, no actor HP/schema. Scene/world assignments, explicit native fallback,
|
|
legacy flag migration, snapshots, interrupted paused offsets and duplicate ordered
|
|
occurrences are preserved. Ambient is currently the single interrupted base queue;
|
|
AmbientSound and effects remain untouched. Optional companion control retains its
|
|
expiring fenced lease; native document ownership stays explicitly opted in.
|
|
|
|
GM-local control shares the same serialized, generation-checked provider and target
|
|
checks. A Web Lock excludes duplicate GM tabs on the same origin; startup requires
|
|
one active GM and a known empty idle target. This is **not a distributed server fence**
|
|
and cannot prevent a malicious/stale independent GM client with its own MA token.
|
|
The module refuses automatic split-brain handover and invalidates authority on
|
|
Foundry disconnect. Permanent strict multi-writer fencing needs the approved worker.
|
|
No browser-only design can manufacture an MA server-side compare-and-swap lease.
|
|
|
|
GM loss stops WebRTC forwarding and automated writes; it cannot guarantee immediate
|
|
restoration after a crashed/offline browser, and already delivered audio cannot be
|
|
revoked from a recipient. SDK-adopted sockets do not auto-reconnect. Explicit reconnect
|
|
requires target reconciliation, same identity, secure access, new peer invitations
|
|
and role checks. Native fallback cannot silently bypass an uncertain active MA target.
|
|
|
|
The preserved MA snapshots are signed, scoped to campaign/session/fence/generation,
|
|
expire after five minutes and carry ordered occurrences, index, whole-second offset,
|
|
pause/state and repeat. Capture repeats pagination; restore stages ordered items,
|
|
checks them and seeks. Shuffled/dynamic/autoplay/overlay/ended/nonstandard speed
|
|
states are unsupported. Remote ambiguity latches closed rather than retrying blindly.
|
|
Restart/crash durability, shuffled restoration and true cross-client fencing remain
|
|
acceptance gates. The bounded live harness still captures/restores original state;
|
|
closing an experimental GM tab is not claimed to restore MA automatically.
|
|
|
|
## Optional minimal co-located fallback
|
|
|
|
If secure private browser reachability, network traversal or GM uptime is unacceptable,
|
|
review a single non-root worker on the **existing Foundry host**, using existing host
|
|
runtime/network capacity and protected state. It would terminate only the dedicated
|
|
MA receiver, hold credentials server-side, enforce controller/listener authorization
|
|
and expose restricted campaign audio/control through the existing TLS origin. It
|
|
must never forward arbitrary MA API/WS/Sendspin messages. Existing `gateway/` code is
|
|
a validated starting point, but actual Sendspin termination, durability and production
|
|
security remain work. No system service is installed automatically, no host is
|
|
provisioned and no Foundry/MA core is changed. Any real route/placement/deployment
|
|
must be proposed concretely and approved first; nothing is deployed here.
|