How broduoliviercontact-web/collab-hub-web-monitor works
Purpose and entry points
Collab-Hub Web Monitor is a Vite/vanilla-JS application that displays live music metadata from Max/MSP through Collab-Hub, with optional LiveKit direct audio. Public entry points are index.html → src/main.js and src/publicPage.js; the performer route is control-room.html → src/control-room/controlRoomPage.js. The Max publisher patch is max/CollabHub_Web_Text_Sender.maxpat.
Public metadata pipeline
The public runtime connects directly from the browser to the Collab-Hub Socket.IO /hub namespace. src/collabHub/socketClient.js owns connection/auth fallback and subscriptions; src/collabHub/observeGuard.js prevents duplicate observation per socket identity; src/collabHub/messageRouter.js normalizes delivered controls and separates known content headers from heartbeat/technical headers.
Routed metadata updates src/state/soundState.js, is restored/persisted locally through src/state/persist.js, then renders through src/ui/renderSoundInfo.js and src/ui/renderConnectionStatus.js. This is a browser-to-Collab-Hub boundary: Vercel does not proxy the real-time connection.
Freshness, stream state, and public UI
src/state/freshness.js tracks distinct server connectivity, Max heartbeat activity, and age of displayed content. src/state/streamStatus.js holds public audio-stream presence, level, peak, and listener-count data received from Collab-Hub. Public composition is split into additive runtimes under src/public/, notably src/public/publicContentRuntime.js, src/public/publicStreamRuntime.js, and src/public/publicListenerRuntime.js.
The public page can remain useful while disconnected because metadata persists only in browser localStorage; heartbeat state intentionally does not persist. Untrusted text and links are rendered safely without interpreted HTML.
Live audio: listener and performer paths
The public listener is dynamically enabled through src/livekit/livekitListener.js and UI modules in src/listener/. It obtains a short-lived listener token, joins LiveKit, subscribes to audio, and controls playback/volume via src/listener/listenerAudioElement.js.
The performer Control Room reuses a local Web Audio capture and processing engine: src/audio/audioEngine.js, src/audio/audioCapture.js, and src/audio/audioGraph.js. src/audio/livekitPublisher.js publishes the captured MediaStream to LiveKit. The Control Room coordinates capture, metering, publishing, and lifecycle in src/control-room/controlRoomRuntime.js and src/control-room/controlRoomController.js. It also publishes non-secret on-air, level, and listener-count presence back to Collab-Hub via src/control-room/streamPresencePublisher.js.
Serverless security boundary
Vercel API functions are the only server-side trust boundary. api/livekit/token.js issues role-scoped LiveKit tokens using server-only LiveKit credentials and performer authorization. Control Room login/session endpoints are api/control-room/login.js, api/control-room/session.js, and api/control-room/logout.js; signing and cookie logic reside in src/server/controlRoomSession.js and HTTP helpers in src/server/http.js.
Browser bundles must never receive LiveKit API secrets, performer password, or control-room session secret. The Control Room gate loads before the LiveKit runtime through src/control-room/controlRoomGatePage.js.
Diagnostics and operations
A gated, dynamically loaded diagnostics surface is implemented by src/diagnostic/debugGate.js and src/diagnostic/diagnosticPanel.js. It consumes runtime health, bounded event history, and sanitized exports from src/diagnostic/systemHealth.js, src/diagnostic/boundedEventLog.js, and src/diagnostic/diagnosticSanitizer.js. Diagnostic output redacts secrets and listener identities.
Deployment is static Vite output configured by vercel.json; GitHub Actions CI is defined in .github/workflows/ci.yml. External services are Collab-Hub (server.collab-hub.io), LiveKit Cloud, and Vercel serverless/static hosting.
Main entry points: publicPage.js Public page composition · messageRouter.js Metadata router · socketClient.js Collab-Hub socket client · token.js LiveKit token API
Components 24
Public browser
Persistent metadata and optional listener audio.
- Public page entry
src/main.js - Public page composition
src/publicPage.js - Collab-Hub socket client · Connects directly to the /hub namespace.
src/collabHub/socketClient.js - Observation guard · Prevents duplicate observation for a socket identity.
src/collabHub/observeGuard.js - Metadata router
src/collabHub/messageRouter.js - Sound state and persistence · Metadata is retained in localStorage for disconnected use.
src/state/soundState.js - Freshness state · Separates server, Max heartbeat, and content age.
src/state/freshness.js - Stream status
src/state/streamStatus.js - Public UI runtimes · Renders safe metadata, connection, stream, and listener UI.
src/public/publicContentRuntime.js - LiveKit listener · Obtains a listener token and subscribes to audio.
src/livekit/livekitListener.js - Gated diagnostics · Sanitizes health and bounded event exports.
src/diagnostic/debugGate.js
Control Room
Performer capture, publishing, and presence.
- Control Room entry
src/control-room/controlRoomPage.js - Control Room gate · Loads before the LiveKit runtime.
src/control-room/controlRoomGatePage.js - Control Room runtime · Coordinates capture, metering, publishing, and lifecycle.
src/control-room/controlRoomRuntime.js - Audio capture engine · Captures and processes the local performer stream.
src/audio/audioEngine.js - LiveKit publisher · Publishes the captured MediaStream.
src/audio/livekitPublisher.js - Stream presence publisher · Publishes non-secret on-air, level, and listener presence.
src/control-room/streamPresencePublisher.js
Vercel trust boundary
Server-only authorization and token issuance.
- LiveKit token API · Issues role-scoped tokens with server-only credentials.
api/livekit/token.js - Control Room session API · Login, session, and logout endpoints.
api/control-room/login.js - Session signing · Signs and validates Control Room cookies.
src/server/controlRoomSession.js
External systems
- Max metadata publisher
max/CollabHub_Web_Text_Sender.maxpat - Collab-Hub · Socket.IO metadata and presence service.
- LiveKit Cloud
- Vercel
vercel.json
Connections 30
- Public page entry → Public page composition: boots
- Public page composition → Collab-Hub socket client: starts
- Collab-Hub socket client → Observation guard: guards subscriptions
- Observation guard → Collab-Hub: observes /hub
- Collab-Hub → Collab-Hub socket client: delivers controls
- Collab-Hub socket client → Metadata router: routes messages
- Metadata router → Sound state and persistence: content updates
- Metadata router → Freshness state: heartbeat activity
- Metadata router → Stream status: stream presence
- Sound state and persistence → Public UI runtimes: renders metadata
- Freshness state → Public UI runtimes: renders status
- Stream status → Public UI runtimes: renders stream UI
- Public page composition → LiveKit listener: enables on demand
- LiveKit listener → LiveKit token API: requests listener token
- LiveKit token API → LiveKit Cloud: signs access
- LiveKit listener → LiveKit Cloud: subscribes audio
- Control Room entry → Control Room gate: loads first
- Control Room gate → Control Room session API: checks session
- Control Room session API → Session signing: signs cookies
- Control Room gate → Control Room runtime: authorizes
- Control Room runtime → Audio capture engine: captures audio
- Audio capture engine → LiveKit publisher: MediaStream
- LiveKit publisher → LiveKit token API: requests performer token
- LiveKit publisher → LiveKit Cloud: publishes audio
- Control Room runtime → Stream presence publisher: reports state
- Stream presence publisher → Collab-Hub: publishes presence
- Max metadata publisher → Collab-Hub: publishes metadata
- Public page composition → Gated diagnostics: loads when gated
- Vercel → Public page entry: hosts static app
- Vercel → LiveKit token API: runs function