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: close hosted guest microphone on normal release (#8092)

[._.]/ Adam Eivya1e9a73e359c
diff --git a/client/src/pages/FableLoomHostedJoin.jsx b/client/src/pages/FableLoomHostedJoin.jsx
index 905ad93984..6af6458dfc 100644
--- a/client/src/pages/FableLoomHostedJoin.jsx
+++ b/client/src/pages/FableLoomHostedJoin.jsx
@@ -140,7 +140,13 @@ export default function FableLoomHostedJoin() {
const recorder = new MediaRecorder(stream);
const chunks = [];
- mediaRecorderRef.current = { recorder, stream };
+ let tracksStopped = false;
+ const stopTracks = () => {
+ if (tracksStopped) return;
+ tracksStopped = true;
+ stream.getTracks().forEach((track) => track.stop());
+ };
+ mediaRecorderRef.current = { recorder, stream, stopTracks };
recorder.ondataavailable = (event) => {
if (event.data && event.data.size > 0) {
@@ -155,7 +161,7 @@ export default function FableLoomHostedJoin() {
socket.emit('hosted:mic:stop', new Uint8Array(buf));
}
});
- stream.getTracks().forEach((track) => track.stop());
+ stopTracks();
};
recorder.start(100);
@@ -175,9 +181,10 @@ export default function FableLoomHostedJoin() {
pressedRef.current = false;
++startGenRef.current;
if (mediaRecorderRef.current) {
- const { recorder } = mediaRecorderRef.current;
+ const { recorder, stopTracks } = mediaRecorderRef.current;
mediaRecorderRef.current = null;
if (recorder.state !== 'inactive') recorder.stop();
+ stopTracks();
setIsRecording(false);
}
};
@@ -190,7 +197,7 @@ export default function FableLoomHostedJoin() {
if (active) {
active.recorder.onstop = null;
if (active.recorder.state !== 'inactive') active.recorder.stop();
- active.stream.getTracks().forEach((track) => track.stop());
+ active.stopTracks();
}
}, []);
diff --git a/client/src/pages/FableLoomHostedJoin.test.jsx b/client/src/pages/FableLoomHostedJoin.test.jsx
index f26e985311..3a30943132 100644
--- a/client/src/pages/FableLoomHostedJoin.test.jsx
+++ b/client/src/pages/FableLoomHostedJoin.test.jsx
@@ -124,6 +124,40 @@ describe('FableLoomHostedJoin', () => {
vi.unstubAllGlobals();
});
+ it('closes the mic on release while preserving the recorder final chunk', async () => {
+ window.location.hash = '#session=sess-123&token=tok-abc';
+ const track = { stop: vi.fn() };
+ Object.defineProperty(navigator, 'mediaDevices', {
+ configurable: true,
+ value: { getUserMedia: vi.fn().mockResolvedValue({ getTracks: () => [track] }) },
+ });
+ let recorder;
+ vi.stubGlobal('MediaRecorder', class {
+ constructor() { this.state = 'inactive'; this.mimeType = 'audio/webm'; recorder = this; }
+ start() { this.state = 'recording'; }
+ stop() {
+ this.state = 'inactive';
+ queueMicrotask(() => {
+ this.ondataavailable?.({ data: new Blob(['last']) });
+ this.onstop?.();
+ });
+ }
+ });
+
+ render(<FableLoomHostedJoin />);
+ const button = screen.getByRole('button', { name: /hold talk/i });
+ fireEvent.pointerDown(button);
+ await waitFor(() => expect(recorder?.state).toBe('recording'));
+ fireEvent.pointerUp(button);
+
+ expect(track.stop).toHaveBeenCalledOnce();
+ await waitFor(() => expect(mockSocket.emit).toHaveBeenCalledWith('hosted:mic:stop', expect.any(Uint8Array)));
+ const bytes = mockSocket.emit.mock.calls.find(([event]) => event === 'hosted:mic:stop')[1];
+ expect(new TextDecoder().decode(bytes)).toBe('last');
+ expect(track.stop).toHaveBeenCalledOnce();
+ vi.unstubAllGlobals();
+ });
+
it('keeps audio chunks separate across two press and release cycles', async () => {
window.location.hash = '#session=sess-123&token=tok-abc';
const tracks = [{ stop: vi.fn() }, { stop: vi.fn() }];