2026-08-07 10:44:03 +07:00
|
|
|
"use client";
|
|
|
|
|
|
2026-08-26 10:39:00 +07:00
|
|
|
import { Mic, PhoneOff, Radio, Volume2 } from "lucide-react";
|
2026-08-24 16:32:16 +07:00
|
|
|
import { useEffect, useState } from "react";
|
2026-08-15 20:03:55 +07:00
|
|
|
import { useAmbient } from "@/components/ambient/ambient-context";
|
2026-08-24 16:32:16 +07:00
|
|
|
import { Button, GlassPanel, toast } from "@/components/primitives";
|
2026-08-24 15:44:10 +07:00
|
|
|
import {
|
2026-08-24 16:32:16 +07:00
|
|
|
ErrorState,
|
2026-08-26 03:37:14 +07:00
|
|
|
PageTransition,
|
2026-08-24 16:32:16 +07:00
|
|
|
SectionHeader,
|
|
|
|
|
SkeletonPanel,
|
|
|
|
|
} from "@/components/shared";
|
|
|
|
|
import { GuildChannelPicker } from "@/components/shared/guild-picker";
|
2026-08-15 20:03:55 +07:00
|
|
|
import { VoiceStage } from "@/components/voice/voice-stage";
|
|
|
|
|
import {
|
|
|
|
|
useMicTransmit,
|
|
|
|
|
useSpeakers,
|
2026-08-07 10:44:03 +07:00
|
|
|
useVoiceConnect,
|
|
|
|
|
useVoiceDisconnect,
|
|
|
|
|
useVoiceListen,
|
2026-08-15 20:03:55 +07:00
|
|
|
useVoiceStatus,
|
2026-08-07 10:44:03 +07:00
|
|
|
} from "@/hooks";
|
2026-08-25 23:23:19 +07:00
|
|
|
import { useStaggerReveal } from "@/hooks/use-gsap-animation";
|
2026-08-15 17:53:48 +07:00
|
|
|
import type { Guild, VoiceStatus } from "@/lib/types";
|
2026-08-15 20:03:55 +07:00
|
|
|
import { useWebSocket } from "@/lib/ws/context";
|
2026-08-07 10:44:03 +07:00
|
|
|
|
2026-08-15 17:53:48 +07:00
|
|
|
export function VoiceView({
|
|
|
|
|
initialStatus,
|
|
|
|
|
initialGuilds,
|
|
|
|
|
}: {
|
|
|
|
|
initialStatus?: VoiceStatus;
|
|
|
|
|
initialGuilds?: Guild[];
|
|
|
|
|
}) {
|
2026-08-07 10:44:03 +07:00
|
|
|
const ws = useWebSocket();
|
2026-08-25 13:46:15 +07:00
|
|
|
const {
|
|
|
|
|
data: status,
|
|
|
|
|
isLoading,
|
|
|
|
|
error,
|
|
|
|
|
mutate,
|
|
|
|
|
} = useVoiceStatus(initialStatus);
|
2026-08-14 10:49:44 +07:00
|
|
|
const connect = useVoiceConnect();
|
|
|
|
|
const disconnect = useVoiceDisconnect();
|
2026-08-14 12:35:44 +07:00
|
|
|
const mic = useMicTransmit(ws);
|
2026-08-15 17:53:48 +07:00
|
|
|
const listen = useVoiceListen(ws);
|
|
|
|
|
const { speakers, subscribe } = useSpeakers(initialStatus?.activeSpeakers);
|
|
|
|
|
const ambient = useAmbient();
|
|
|
|
|
|
|
|
|
|
const [guildId, setGuildId] = useState<string | null>(
|
|
|
|
|
initialStatus?.activeGuildId ?? initialGuilds?.[0]?.id ?? null,
|
|
|
|
|
);
|
|
|
|
|
const [channelId, setChannelId] = useState<string | null>(
|
|
|
|
|
initialStatus?.activeChannelId ?? null,
|
|
|
|
|
);
|
2026-08-22 12:53:18 +07:00
|
|
|
const [micVol, setMicVol] = useState(100);
|
|
|
|
|
const [listenVol, setListenVol] = useState(75);
|
2026-08-07 10:44:03 +07:00
|
|
|
|
2026-08-26 03:37:14 +07:00
|
|
|
const containerRef = useStaggerReveal<HTMLDivElement>(".voice-tile", {
|
|
|
|
|
stagger: 0.04,
|
|
|
|
|
y: 8,
|
2026-08-25 23:23:19 +07:00
|
|
|
dependencies: [status],
|
|
|
|
|
});
|
|
|
|
|
|
2026-08-07 10:44:03 +07:00
|
|
|
useEffect(() => {
|
|
|
|
|
const unsub = subscribe(ws);
|
2026-08-14 10:49:44 +07:00
|
|
|
return unsub;
|
|
|
|
|
}, [subscribe, ws]);
|
2026-08-07 10:44:03 +07:00
|
|
|
|
2026-08-15 17:53:48 +07:00
|
|
|
useEffect(() => {
|
2026-08-26 03:37:14 +07:00
|
|
|
if (status?.connected) ambient.set("signal", 0.45, "voice active");
|
|
|
|
|
else ambient.set("vermilion", 0.25, "voice disconnected");
|
2026-08-15 17:53:48 +07:00
|
|
|
}, [status?.connected, ambient]);
|
2026-08-14 11:28:08 +07:00
|
|
|
|
2026-08-25 13:46:15 +07:00
|
|
|
if (error && !status)
|
|
|
|
|
return <ErrorState error={error} onRetry={() => void mutate()} />;
|
2026-08-18 09:21:12 +07:00
|
|
|
if (!status && isLoading)
|
|
|
|
|
return (
|
2026-08-26 03:37:14 +07:00
|
|
|
<div className="space-y-4">
|
|
|
|
|
<SkeletonPanel rows={3} />
|
|
|
|
|
<SkeletonPanel rows={5} />
|
2026-08-24 16:32:16 +07:00
|
|
|
</div>
|
2026-08-18 09:21:12 +07:00
|
|
|
);
|
2026-08-15 17:53:48 +07:00
|
|
|
|
|
|
|
|
const connected = status?.connected ?? false;
|
|
|
|
|
|
|
|
|
|
const onConnect = async () => {
|
|
|
|
|
if (!guildId || !channelId) {
|
2026-08-26 03:37:14 +07:00
|
|
|
toast({ title: "Select target channel", tone: "vermilion" });
|
2026-08-15 17:53:48 +07:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
await connect.mutateAsync({ guildId, channelId });
|
2026-08-26 03:37:14 +07:00
|
|
|
toast({ title: "Connected to voice channel", tone: "signal" });
|
2026-08-15 17:53:48 +07:00
|
|
|
} catch (e) {
|
2026-08-15 20:03:55 +07:00
|
|
|
toast({
|
2026-08-26 03:37:14 +07:00
|
|
|
title: "Connection failed",
|
2026-08-15 20:03:55 +07:00
|
|
|
description: String(e),
|
|
|
|
|
tone: "vermilion",
|
|
|
|
|
});
|
2026-08-14 12:35:44 +07:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-08-26 03:37:14 +07:00
|
|
|
const onDisconnect = async () => {
|
2026-08-15 17:53:48 +07:00
|
|
|
try {
|
2026-08-26 03:37:14 +07:00
|
|
|
await disconnect.mutateAsync();
|
|
|
|
|
toast({ title: "Disconnected from voice", tone: "neutral" });
|
2026-08-15 17:53:48 +07:00
|
|
|
} catch (e) {
|
2026-08-26 03:37:14 +07:00
|
|
|
toast({
|
|
|
|
|
title: "Disconnect failed",
|
|
|
|
|
description: String(e),
|
|
|
|
|
tone: "vermilion",
|
|
|
|
|
});
|
2026-08-15 17:53:48 +07:00
|
|
|
}
|
2026-08-14 11:28:08 +07:00
|
|
|
};
|
2026-08-07 10:44:03 +07:00
|
|
|
|
|
|
|
|
return (
|
2026-08-26 03:37:14 +07:00
|
|
|
<PageTransition>
|
|
|
|
|
<div ref={containerRef} className="space-y-4">
|
|
|
|
|
{/* Precision Sub-Header Bar */}
|
|
|
|
|
<div className="voice-tile flex flex-wrap items-center justify-between gap-3 border-b border-white/[0.06] pb-3">
|
|
|
|
|
<div className="flex items-center gap-2.5">
|
2026-08-25 23:23:19 +07:00
|
|
|
<span
|
2026-08-26 03:37:14 +07:00
|
|
|
className={`h-2 w-2 rounded-full ${
|
2026-08-24 16:32:16 +07:00
|
|
|
connected
|
2026-08-26 03:37:14 +07:00
|
|
|
? "bg-[#10b981] shadow-[0_0_8px_#10b981]"
|
|
|
|
|
: "bg-[#8a8f98]"
|
|
|
|
|
}`}
|
2026-08-24 16:32:16 +07:00
|
|
|
/>
|
2026-08-26 03:37:14 +07:00
|
|
|
<h1 className="font-mono text-xs font-semibold tracking-wide text-[#f7f8f8] uppercase">
|
|
|
|
|
Voice Spectrum & Stage Controls
|
|
|
|
|
</h1>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center gap-2 font-mono text-[11px]">
|
|
|
|
|
<span className="text-[#8a8f98]">STAGE:</span>
|
|
|
|
|
<span
|
|
|
|
|
className={`rounded px-1.5 py-0.5 font-medium border ${
|
|
|
|
|
connected
|
|
|
|
|
? "border-[#10b981]/30 bg-[#10b981]/10 text-[#10b981]"
|
|
|
|
|
: "border-white/[0.06] bg-white/[0.02] text-[#8a8f98]"
|
|
|
|
|
}`}
|
|
|
|
|
>
|
|
|
|
|
{connected ? "LIVE_BRIDGE" : "OFFLINE"}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-08-24 16:32:16 +07:00
|
|
|
|
2026-08-26 03:37:14 +07:00
|
|
|
{/* Channel Router Stage */}
|
|
|
|
|
<div className="voice-tile">
|
|
|
|
|
<GlassPanel className="p-4">
|
|
|
|
|
<div className="flex flex-wrap items-center justify-between gap-3">
|
|
|
|
|
<div className="flex-1 min-w-[240px]">
|
|
|
|
|
<GuildChannelPicker
|
|
|
|
|
guildId={guildId}
|
|
|
|
|
channelId={channelId}
|
|
|
|
|
guildsInitial={initialGuilds}
|
|
|
|
|
onChange={(g, c) => {
|
|
|
|
|
setGuildId(g);
|
|
|
|
|
setChannelId(c);
|
|
|
|
|
}}
|
|
|
|
|
mode="voice"
|
|
|
|
|
/>
|
2026-08-24 16:32:16 +07:00
|
|
|
</div>
|
2026-08-26 03:37:14 +07:00
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
{connected ? (
|
|
|
|
|
<Button
|
|
|
|
|
variant="danger"
|
|
|
|
|
size="md"
|
|
|
|
|
onClick={onDisconnect}
|
|
|
|
|
className="gap-1.5"
|
|
|
|
|
>
|
|
|
|
|
<PhoneOff className="size-3.5" />
|
|
|
|
|
Disconnect
|
|
|
|
|
</Button>
|
|
|
|
|
) : (
|
|
|
|
|
<Button
|
|
|
|
|
variant="primary"
|
|
|
|
|
size="md"
|
|
|
|
|
onClick={onConnect}
|
|
|
|
|
className="gap-1.5"
|
|
|
|
|
>
|
|
|
|
|
<Radio className="size-3.5" />
|
|
|
|
|
Connect Bridge
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
2026-08-24 16:32:16 +07:00
|
|
|
</div>
|
2026-08-26 03:37:14 +07:00
|
|
|
</div>
|
|
|
|
|
</GlassPanel>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Voice Stage Grid */}
|
|
|
|
|
<div className="grid gap-3 lg:grid-cols-3">
|
|
|
|
|
<GlassPanel className="voice-tile lg:col-span-2">
|
|
|
|
|
<SectionHeader
|
|
|
|
|
eyebrow="Participants"
|
|
|
|
|
title="Active Stage Members"
|
|
|
|
|
/>
|
|
|
|
|
<div className="mt-4 min-h-[160px]">
|
|
|
|
|
<VoiceStage speakers={speakers} />
|
|
|
|
|
</div>
|
|
|
|
|
</GlassPanel>
|
|
|
|
|
|
|
|
|
|
<GlassPanel className="voice-tile flex flex-col justify-between">
|
|
|
|
|
<div>
|
2026-08-26 10:39:00 +07:00
|
|
|
<SectionHeader eyebrow="Telemetry" title="Input / Output Mix" />
|
2026-08-26 03:37:14 +07:00
|
|
|
<div className="mt-4 space-y-4">
|
|
|
|
|
<div>
|
|
|
|
|
<div className="flex justify-between text-xs font-medium text-[#d0d6e0]">
|
|
|
|
|
<span className="flex items-center gap-1.5">
|
|
|
|
|
<Mic className="size-3.5 text-[#7170ff]" />
|
|
|
|
|
Mic Sensitivity
|
|
|
|
|
</span>
|
|
|
|
|
<span className="font-mono text-[11px] text-[#8a8f98]">
|
|
|
|
|
{micVol}%
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
<input
|
|
|
|
|
type="range"
|
|
|
|
|
min={0}
|
|
|
|
|
max={150}
|
|
|
|
|
value={micVol}
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
const v = Number(e.target.value);
|
|
|
|
|
setMicVol(v);
|
|
|
|
|
mic.setVolume(v / 100);
|
|
|
|
|
}}
|
|
|
|
|
className="mt-2 h-1.5 w-full appearance-none rounded-full bg-white/[0.08] accent-[#7170ff]"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<div className="flex justify-between text-xs font-medium text-[#d0d6e0]">
|
|
|
|
|
<span className="flex items-center gap-1.5">
|
|
|
|
|
<Volume2 className="size-3.5 text-[#10b981]" />
|
|
|
|
|
Monitor Output
|
|
|
|
|
</span>
|
|
|
|
|
<span className="font-mono text-[11px] text-[#8a8f98]">
|
|
|
|
|
{listenVol}%
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
<input
|
|
|
|
|
type="range"
|
|
|
|
|
min={0}
|
|
|
|
|
max={150}
|
|
|
|
|
value={listenVol}
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
const v = Number(e.target.value);
|
|
|
|
|
setListenVol(v);
|
|
|
|
|
listen.setVolume(v / 100);
|
|
|
|
|
}}
|
|
|
|
|
className="mt-2 h-1.5 w-full appearance-none rounded-full bg-white/[0.08] accent-[#10b981]"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="mt-6 border-t border-white/[0.06] pt-3">
|
|
|
|
|
<div className="font-mono text-[10px] text-[#8a8f98]">
|
|
|
|
|
CODEC: OPUS 48KHZ · LOW_LATENCY
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</GlassPanel>
|
|
|
|
|
</div>
|
2026-08-24 16:32:16 +07:00
|
|
|
</div>
|
2026-08-26 03:37:14 +07:00
|
|
|
</PageTransition>
|
2026-08-07 10:44:03 +07:00
|
|
|
);
|
|
|
|
|
}
|