map: ScriptProcessorNode audio fallback so listening works over plain HTTP - #14
Merged
Conversation
…ontexts The map's "listen" feature opened an AudioWorklet to play a port's PCM. AudioWorklet is a secure-context-only API, so on plain HTTP served from a non-localhost host (e.g. http://packetdotnet:8090) `ctx.audioWorklet` is undefined and `ensureAudioCtx` threw `TypeError: Cannot read properties of undefined (reading 'addModule')` — audio never started. Branch the playback node in ensureAudioCtx: keep the AudioWorklet on secure contexts (HTTPS / localhost), and fall back to a ScriptProcessorNode when `ctx.audioWorklet` is absent. ScriptProcessorNode is deprecated and runs on the main thread, but it isn't secure-context-gated and is fine for monitoring one port. It uses the same queue/drain logic as the worklet (with a ~2 s backlog cap). The WebSocket onmessage now routes samples through a mode-agnostic `listenState.feed` so both paths share the receive code. No functional change on HTTPS/localhost (still uses the worklet). Unrelated to the 503s on /api/peer/chatbot/state — those are just the peer proxy reporting no `chatbot` container is resolvable on the Docker network; the map already hides that panel. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On the live map, clicking a port's ♪ to listen threw:
ensureAudioCtxcallsctx.audioWorklet.addModule(...), butAudioWorkletis a secure-context-only API. When the UI is served over plain HTTP from a non-localhost host (e.g.http://packetdotnet:8090),ctx.audioWorkletisundefined, so playback never started. (Thews://audio stream itself isn't secure-context-gated — only the worklet playback was.)Fix
Branch the playback node in
ensureAudioCtx:AudioWorkletas before.ScriptProcessorNode. Deprecated and main-thread, but not secure-context-gated and fine for monitoring one port. Same queue/drain logic as the worklet, with a ~2 s backlog cap.ws.onmessagenow routes samples through a mode-agnosticlistenState.feed, so both paths share the receive/decode code. No behaviour change on HTTPS/localhost.Not in scope (separate, environmental)
The
503on/api/peer/chatbot/stateis unrelated: the peer proxy can't resolve achatbotcontainer on the Docker network (lookup chatbot ... no such host), so it returns a clean 503 and the map hides that panel. Nothing to fix in code — run a container namedchatbot(port 8090) on the same network if you want the panel.Testing
make testgreen;go buildof the embed OK; map.html JS passesnode --check./mapover HTTP and confirmed it carries the fallback (createScriptProcessor, thectx.audioWorkletguard, and thefeed()routing).chromechannel needs root). The fix targets the exact, confirmed cause with the canonical ScriptProcessorNode generator pattern — worth a 10-second manual confirm: reload the map overhttp://…and click ♪.Merging publishes a fresh
ghcr.io/packethacking/net-sim:mainimage with the fix.