Repository navigation
refactor(stems): extract the buffer transport + #audio shims to src/transport.js - #35
Conversation
…ransport.js Move the top of the playback engine out of main.js into src/transport.js: the AudioContext-clock playhead (transportPlayhead/Raw), source start/stop (startSources/workletStartSources/stopSources), transportPlay/Pause/Seek/ setTransportRate/lightStop/handleNaturalEnd/dispatchAudioEvent, the shared onWorkletMessage handler, and installAudioShims + the nativeCore* helpers. main.js 1840 -> 1412 lines. It's a clean upper layer: it calls only within-cluster fns, shared state, and already-extracted modules (audio-ctx, streaming) by the same names, so the bodies moved VERBATIM. No cycle — streaming.js gets transportPlay/onWorkletMessage via the step-10 configureStreaming injection (runtime), not a static import, so transport -> streaming is one-way. Removed now-dead main.js imports (resumeCtx, repositionStream, streamOffsetBuffered). The ios-play-pause-shim.test.mjs + test_manifest.py shim assertions now read src/transport.js (the shims' new home), same retarget as the earlier screen.js -> main.js move. node 45/45, pytest 10/10. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughThis PR extracts buffer transport and ChangesBuffer transport extraction
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant Main as src/main.js
participant Transport as src/transport.js
participant AudioContext
participant Sources
Main->>Transport: transportPlay()/transportSeek()/transportPause()
Transport->>AudioContext: read currentTime / resume
Transport->>Sources: stopSources()/startSources(offset)
Sources-->>Transport: playback state
Transport-->>Main: play/pause/seek events
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Tools execution failed with the following error: Failed to run tools: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error) Comment |
There was a problem hiding this comment.
Pull request overview
Refactors the Stems playback engine by extracting the buffer transport and #audio shim layer out of src/main.js into a dedicated src/transport.js module, while retargeting existing tests and documenting the step in the changelog.
Changes:
- Added
src/transport.jscontaining transport playhead math, source lifecycle control, worklet message handling, and#audioplay/pause/currentTime shims. - Updated
src/main.jsto import transport/shim functions fromsrc/transport.jsand removed the inlined transport implementation. - Retargeted shim-related tests (Python + Node) and updated the changelog entry for step 11.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/test_manifest.py | Updates shim assertions to read src/transport.js instead of src/main.js. |
| tests/ios-play-pause-shim.test.mjs | Retargets the iOS play/pause shim regression test to src/transport.js. |
| src/transport.js | New module housing buffer transport orchestration and #audio delegation shims. |
| src/main.js | Removes extracted transport code and wires streaming hooks + transport imports. |
| CHANGELOG.md | Adds step 11 release note describing the extraction. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address Copilot on #35 — align the changelog with the PR (smoke pending); 'recommended before release' matches the not-yet-verified phrasing used for earlier steps. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/transport.js`:
- Around line 285-291: `handleNaturalEnd()` is still processing queued worklet
`ended` messages after an intentional pause/stop, which can incorrectly dispatch
`ended` and move the playhead to `duration`. Update `handleNaturalEnd()` in
`src/transport.js` to ignore stale natural-end events unless playback is still
active (for example by checking `transport.playing`/current active state before
updating `baseOffset`, stopping sources, or calling
`dispatchAudioEvent('ended')`). Keep the guard aligned with the stop/pause paths
used by `transportPause()` and `lightStop()`.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: e157dab4-c3c2-4885-a3d5-ba6e8b764c06
⛔ Files ignored due to path filters (1)
tests/__pycache__/test_manifest.cpython-314-pytest-9.0.3.pycis excluded by!**/*.pyc
📒 Files selected for processing (5)
CHANGELOG.mdsrc/main.jssrc/transport.jstests/ios-play-pause-shim.test.mjstests/test_manifest.py
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…eek guard (#36) * fix(stems): guard handleNaturalEnd on playback; test + document the seek guard Step 11.1 — the deferred streaming/transport hardening. 1. handleNaturalEnd() now returns unless transport.playing. In worklet mode a queued worklet 'ended' can arrive just after transportPause()/lightStop() flipped playing=false (stopSources posts 'stop' but can't unqueue an in-flight 'ended'), which would dispatch a spurious 'ended' and jump the playhead to duration. Pre-existing (CodeRabbit on #35); buffer mode was already safe since stopSources nulls src.onended before stop(). No genuine natural-end enters with playing===false (it's set false inside the handler). 2. Export appendRound + tests/streaming.test.mjs cases pinning the step-9.1 seek-token guard: posts only when the captured token matches ST.streamSeekToken, drops the block (no post, frontier unchanged) otherwise. 3. Document the synchronous t.done=true invariant in cancelStreamReaders that keeps reader-reopen seek-safe. This is why Copilot's immutable-per-generation track refactor isn't needed: the steal is unreachable given that invariant (readers reopen only after a network fetch, a macrotask after the cancelled read resolves with t.done already true) plus appendRound's per-track guard. node 47/47, pytest 10/10. Codex 0. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * test(stems): decouple appendRound guard test from STREAM_CHUNK_FRAMES Address Copilot on #36 — assert a block was posted and the frontier advanced by exactly the posted frame count, instead of hard-coding 8192. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
What
Step 11 — the last big cut. Moves the top of the playback engine out of
main.jsintosrc/transport.js:transportPlayhead/transportPlayheadRaw(off the AudioContext clock)startSources/workletStartSources/stopSourcestransportPlay/transportPause/transportSeek/setTransportRate/lightStop/handleNaturalEnd/dispatchAudioEventonWorkletMessageinstallAudioShims+ thenativeCore{Paused,Pause,Time}helpers (the#audioplay/pause/currentTime/duration delegation)main.js1840 → 1412 lines.Clean upper layer — no seam needed
Unlike streaming, this cluster calls only within-cluster fns, shared state, and already-extracted modules (
audio-ctx,streaming) by the same names — so the bodies moved verbatim. No cycle:streaming.jsgetstransportPlay/onWorkletMessagevia the step-10configureStreaminginjection (runtime), not a static import, sotransport → streamingis one-way. Removed the now-deadmain.jsimports (resumeCtx,repositionStream,streamOffsetBuffered).Tests
ios-play-pause-shim.test.mjs+test_manifest.py's shim assertions now readsrc/transport.js(the shims' new home) — the same retarget done for the earlierscreen.js → main.jsmove. Full suite green: node 45/45, pytest 10/10. Codex preflight: 0.CHANGELOG: step 11 entry added.
Still open (follow-up, not this PR)
Copilot's immutable-per-generation track hardening + token-guard unit tests are streaming.js concerns (the pump internals are private to
streaming.js) — tracked for a dedicated small PR, kept out of this clean move.Summary by CodeRabbit
New Features
#audiotransport shims for consistentcurrentTime,paused,duration,play, andpausebehavior.Bug Fixes
Tests