diff --git a/packages/web/src/components/voice/VoiceUser.tsx b/packages/web/src/components/voice/VoiceUser.tsx index ed17f25a..27706756 100644 --- a/packages/web/src/components/voice/VoiceUser.tsx +++ b/packages/web/src/components/voice/VoiceUser.tsx @@ -20,84 +20,10 @@ export function VoiceUser({ participant, large }: VoiceUserProps) { const perUserVolume = participantVolumes.get(participant.userId) ?? 100; const isLocal = participant.isLocal; - const [ctxState, setCtxState] = useState('suspended'); - - // Monitor AudioContext state - useEffect(() => { - const ctx = getSharedAudioCtx(); - if (!ctx) return; - setCtxState(ctx.state); - const handler = () => setCtxState(ctx.state); - ctx.addEventListener('statechange', handler); - return () => ctx.removeEventListener('statechange', handler); - }, []); - // Web Audio for volume boost (> 100%) const gainNodeRef = useRef(null); const sourceNodeRef = useRef(null); - // Setup Web Audio graph - useEffect(() => { - if (isLocal || !participant.audioTrack) return; - - const ctx = getSharedAudioCtx(); - if (!ctx) return; - - if (!gainNodeRef.current) { - gainNodeRef.current = ctx.createGain(); - gainNodeRef.current.connect(ctx.destination); - } - - const gainNode = gainNodeRef.current!; - - if (sourceNodeRef.current) { - sourceNodeRef.current.disconnect(); - } - - const stream = new MediaStream([participant.audioTrack]); - sourceNodeRef.current = ctx.createMediaStreamSource(stream); - sourceNodeRef.current.connect(gainNode); - - return () => { - sourceNodeRef.current?.disconnect(); - }; - }, [participant.audioTrack, isLocal]); - - // Apply volume - STRICT DUAL PATH PREVENTION - useEffect(() => { - const audioEl = audioRef.current; - const ctx = getSharedAudioCtx(); - - if (isLocal || !audioEl || !ctx) return; - - const perUserScaled = perUserVolume / 100; - const globalScaled = outputVolume / 100; - const combined = perUserScaled * globalScaled; - - if (isDeafened) { - if (gainNodeRef.current) gainNodeRef.current.gain.setTargetAtTime(0, ctx.currentTime, 0.01); - audioEl.volume = 0; - audioEl.muted = true; - } else { - // Chrome/Safari Autoplay logic: - // If Context is Running: Use Web Audio (allows > 100% boost), Mute