10. Codespaces Support and Remote Audio Streaming¶
Running the extension in GitHub Codespaces: remote/container environment detection, the devcontainer's headless audio stack, streamed audio playback and stale port-file recovery.
Purpose¶
This module group enables running the extension in GitHub Codespaces where no local audio hardware is available. It provides:
- Environment detection for remote/container sessions
- A headless audio stack inside the devcontainer
- HTTP audio streaming to a VS Code webview player
- Port persistence and stale-port recovery for reconnect reliability
Components¶
src/config/environment.ts¶
detectEnvironment() reads environment variables and returns typed runtime context:
isCodespaceisRemoteContainercodespaceNamesonicPiHomeaudioStreamPort
The audio stream port is validated to a safe integer (1..65535) with fallback to 8080.
src/ui/AudioStreamWebview.ts¶
Creates the Sonic Pi — Audio Stream webview panel used by the command sonicpi.openAudioStream.
Key details:
- Uses secure Content Security Policy (CSP)
- Uses nonce-based script execution
- Sanitizes stream port before URL construction
- Streams from
http://localhost:<port>
Connection fallback behavior¶
ConnectionManager now attempts persisted port-info first. If ping fails:
- Clear persisted
port-info - Retry via daemon spawn (if available)
- Fallback to config/default ports
This avoids repeated failures caused by stale port files.
Devcontainer Runtime¶
.devcontainer/ provides the full runtime:
Dockerfile: builds Sonic Pi server and dependenciespulse-default.pa: headless PulseAudio null sinkstart-audio.sh: starts PulseAudio, JACK dummy backend, and ffmpeg streamdevcontainer.json: forwards audio stream port and sets remote env vars
Security and runtime defaults:
- ffmpeg HTTP listener bound to
127.0.0.1 - Sonic Pi runtime dir permissions set to
775
User Flow¶
- User opens repository in Codespaces
- Devcontainer starts audio subsystem
- Extension auto-connects to Sonic Pi
- On first connect in Codespaces, extension offers to open the audio stream
- User listens via webview or forwarded port
Operational Notes¶
- Network latency is expected for streamed audio
- MIDI is not available in Codespaces
- Initial container build is heavier than local-only development