From 41559c7712afe0b51c61b868710951303f14fb81 Mon Sep 17 00:00:00 2001 From: Moepchi Date: Wed, 29 Jul 2026 20:39:51 +0200 Subject: [PATCH] Allow enabling the mic (and picking an output device) before connecting The AudioContext/AudioPlayer were only created inside handleConnect, so clicking the mic button while disconnected silently did nothing - no permission prompt, no error. Lazily create them on first use instead (ensureAudioContext), and drop the mic button's connected-only disabled state, matching the real TS3 client where you can test your devices before joining a server. --- web/src/App.tsx | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index 41a9e5d..5806cd1 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -881,6 +881,18 @@ function App() { setSelfActive(false); }; + // Mic/output-device setup shouldn't require an active server connection (like + // the real TS3 client, where you can test your devices before connecting) - + // lazily create the audio context on first use instead of tying it to connect. + const ensureAudioContext = (): AudioContext => { + if (!audioContextRef.current) { + const audioContext = new AudioContext({ sampleRate: SAMPLE_RATE }); + audioContextRef.current = audioContext; + audioPlayerRef.current = new AudioPlayer(audioContext); + } + return audioContextRef.current; + }; + const handleConnect = (overrides?: { host?: string; nickname?: string; @@ -899,9 +911,7 @@ function App() { setConnectError(null); setConnectDialogOpen(false); - const audioContext = new AudioContext({ sampleRate: SAMPLE_RATE }); - audioContextRef.current = audioContext; - audioPlayerRef.current = new AudioPlayer(audioContext); + ensureAudioContext(); const socket = new WebSocket(GATEWAY_URL); socketRef.current = socket; @@ -1158,8 +1168,7 @@ function App() { const handleToggleMic = async () => { if (!micOn) { - const audioContext = audioContextRef.current; - if (!audioContext) return; + const audioContext = ensureAudioContext(); try { const mic = new MicCapture( audioContext, @@ -1412,7 +1421,6 @@ function App() {