Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix([issue-1023]): address review — resume suspended AudioContext, document dep-omission, test standalone→recording transition

Adam Eivyc16f8f34b82b
diff --git a/client/src/components/songs/PitchTuner.jsx b/client/src/components/songs/PitchTuner.jsx
index d1c035c784..4dd2a9c639 100644
--- a/client/src/components/songs/PitchTuner.jsx
+++ b/client/src/components/songs/PitchTuner.jsx
@@ -103,7 +103,11 @@ export default function PitchTuner({ stream = null, a4 = 440 }) {
teardownTracker();
}
return () => { if (stream) teardownTracker(); };
- // standaloneOn intentionally omitted: toggling it is handled in its own paths.
+ // standaloneOn intentionally omitted. `attach`/`teardownTracker` are
+ // referentially stable (their deps bottom out at the empty-dep
+ // teardownTracker and the constant a4), so the only live trigger here is
+ // `stream` changing — and every branch reads the current standaloneOn. The
+ // standalone start/stop paths own their own attach/teardown directly.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [stream, attach, teardownTracker]);
diff --git a/client/src/components/songs/PitchTuner.test.jsx b/client/src/components/songs/PitchTuner.test.jsx
index 8d35381117..be075e7179 100644
--- a/client/src/components/songs/PitchTuner.test.jsx
+++ b/client/src/components/songs/PitchTuner.test.jsx
@@ -71,6 +71,22 @@ describe('PitchTuner', () => {
expect(analyserClose).toHaveBeenCalled();
});
+ it('releases the standalone mic and switches when a recording stream arrives', async () => {
+ const ownTracks = [{ stop: vi.fn() }];
+ global.navigator.mediaDevices = { getUserMedia: vi.fn(() => Promise.resolve({ getTracks: () => ownTracks })) };
+
+ const { rerender } = render(<PitchTuner />); // standalone
+ fireEvent.click(screen.getByText('Tune'));
+ await waitFor(() => expect(createStreamAnalyser).toHaveBeenCalledTimes(1));
+
+ const recStream = fakeStream();
+ rerender(<PitchTuner stream={recStream} />); // a take starts recording
+ // The self-opened mic is released and the tuner re-attaches to the take's stream.
+ expect(ownTracks[0].stop).toHaveBeenCalled();
+ expect(createStreamAnalyser).toHaveBeenLastCalledWith(recStream);
+ expect(screen.queryByText('Tune')).toBeNull();
+ });
+
it('standalone mode opens its own mic on Tune and closes it on Stop', async () => {
const ownTracks = [{ stop: vi.fn() }];
const getUserMedia = vi.fn(() => Promise.resolve({ getTracks: () => ownTracks }));
diff --git a/client/src/lib/audioRecorder.js b/client/src/lib/audioRecorder.js
index 0225537c2c..f9520d7b07 100644
--- a/client/src/lib/audioRecorder.js
+++ b/client/src/lib/audioRecorder.js
@@ -94,6 +94,9 @@ export function arrayBufferToBase64(buffer) {
*/
export function createStreamAnalyser(stream, { fftSize = 2048 } = {}) {
const context = new (window.AudioContext || window.webkitAudioContext)();
+ // A context created outside a user gesture (e.g. in a render-driven effect)
+ // can start `suspended`; resume so frame reads aren't browser-dependent.
+ if (context.state === 'suspended') context.resume().catch(() => {});
const source = context.createMediaStreamSource(stream);
const analyser = context.createAnalyser();
analyser.fftSize = fftSize;