fix(voice): separate Mic and Listen state (were both bound to listen)
- MicControl now uses useMicTransmit + local micActive/micVolume (was wrongly wired to listen.active/listen.toggle) - ListenControl keeps useVoiceListen + handleListenVolume (tsc clean, next build green)
This commit is contained in:
@@ -16,6 +16,7 @@ import { MicControl } from "@/components/voice/mic-control";
|
|||||||
import { ListenControl } from "@/components/voice/listen-control";
|
import { ListenControl } from "@/components/voice/listen-control";
|
||||||
import {
|
import {
|
||||||
useGuilds,
|
useGuilds,
|
||||||
|
useMicTransmit,
|
||||||
useSpeakers,
|
useSpeakers,
|
||||||
useVoiceChannels,
|
useVoiceChannels,
|
||||||
useVoiceConnect,
|
useVoiceConnect,
|
||||||
@@ -41,6 +42,9 @@ export default function VoiceView({ initialStatus }: { initialStatus?: VoiceStat
|
|||||||
const connect = useVoiceConnect();
|
const connect = useVoiceConnect();
|
||||||
const disconnect = useVoiceDisconnect();
|
const disconnect = useVoiceDisconnect();
|
||||||
const listen = useVoiceListen(ws);
|
const listen = useVoiceListen(ws);
|
||||||
|
const mic = useMicTransmit(ws);
|
||||||
|
const [micActive, setMicActive] = useState(false);
|
||||||
|
const [micVolume, setMicVolume] = useState(75);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const unsub = subscribe(ws);
|
const unsub = subscribe(ws);
|
||||||
@@ -50,6 +54,33 @@ export default function VoiceView({ initialStatus }: { initialStatus?: VoiceStat
|
|||||||
const active = speakers.filter((s) => s.speaking);
|
const active = speakers.filter((s) => s.speaking);
|
||||||
const connected = status?.connected ?? false;
|
const connected = status?.connected ?? false;
|
||||||
|
|
||||||
|
const handleMicToggle = async (on: boolean) => {
|
||||||
|
if (on) {
|
||||||
|
try {
|
||||||
|
await mic.mutateAsync(true);
|
||||||
|
setMicActive(true);
|
||||||
|
} catch {
|
||||||
|
setMicActive(false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setMicActive(false);
|
||||||
|
try {
|
||||||
|
await mic.mutateAsync(false);
|
||||||
|
} catch {
|
||||||
|
// Stop already tore down — ignore remote error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMicVolume = (v: number) => {
|
||||||
|
setMicVolume(v);
|
||||||
|
mic.setVolume(v);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleListenVolume = (v: number) => {
|
||||||
|
listen.setVolume(v);
|
||||||
|
};
|
||||||
|
|
||||||
const handleGuildChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
|
const handleGuildChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
|
||||||
const g = e.target.value;
|
const g = e.target.value;
|
||||||
setSelectedGuild(g);
|
setSelectedGuild(g);
|
||||||
@@ -165,8 +196,8 @@ export default function VoiceView({ initialStatus }: { initialStatus?: VoiceStat
|
|||||||
<StaggerGroup className="grid gap-3 sm:grid-cols-[1fr_auto] sm:items-end">
|
<StaggerGroup className="grid gap-3 sm:grid-cols-[1fr_auto] sm:items-end">
|
||||||
<StaggerItem>
|
<StaggerItem>
|
||||||
<MicControl
|
<MicControl
|
||||||
micOn={listen.active}
|
micOn={micActive}
|
||||||
onToggle={(on) => listen.toggle(on)}
|
onToggle={handleMicToggle}
|
||||||
levels={listen.levels}
|
levels={listen.levels}
|
||||||
/>
|
/>
|
||||||
</StaggerItem>
|
</StaggerItem>
|
||||||
@@ -175,7 +206,7 @@ export default function VoiceView({ initialStatus }: { initialStatus?: VoiceStat
|
|||||||
listening={listen.active}
|
listening={listen.active}
|
||||||
onToggle={(on) => listen.toggle(on)}
|
onToggle={(on) => listen.toggle(on)}
|
||||||
volume={75}
|
volume={75}
|
||||||
onVolume={listen.setVolume}
|
onVolume={handleListenVolume}
|
||||||
/>
|
/>
|
||||||
</StaggerItem>
|
</StaggerItem>
|
||||||
</StaggerGroup>
|
</StaggerGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user