fix select voice will triger agent call

This commit is contained in:
Xin Wang 2025-12-09 23:08:59 +08:00
parent 026cde6d47
commit 974cf0994f
2 changed files with 6 additions and 8 deletions

View File

@ -17,11 +17,12 @@ import { useToast } from "@/components/toast/ToasterProvider";
export interface PhoneSimulatorProps {
onConnect: () => void;
onDisconnect: () => void;
phoneMode?: "normal" | "capture";
onCapture?: (image: File) => void;
}
export function PhoneSimulator({ onConnect, phoneMode = "normal", onCapture }: PhoneSimulatorProps) {
export function PhoneSimulator({ onConnect, onDisconnect, phoneMode = "normal", onCapture }: PhoneSimulatorProps) {
const { config, setUserSettings } = useConfig();
const { setToastMessage } = useToast();
const room = useRoomContext();
@ -41,7 +42,6 @@ export function PhoneSimulator({ onConnect, phoneMode = "normal", onCapture }: P
const [processingSource, setProcessingSource] = useState<
"camera" | "upload" | null
>(null);
const [lastVoiceChangeAt, setLastVoiceChangeAt] = useState<number | null>(null);
useEffect(() => {
const voiceAttr = config.settings.attributes?.find(a => a.key === "voice");
@ -169,7 +169,7 @@ export function PhoneSimulator({ onConnect, phoneMode = "normal", onCapture }: P
};
const handleDisconnect = () => {
room.disconnect();
onDisconnect();
};
const handleCapture = async () => {
@ -328,8 +328,7 @@ export function PhoneSimulator({ onConnect, phoneMode = "normal", onCapture }: P
newSettings.attributes = attributes;
setUserSettings(newSettings);
setCurrentVoiceId(voiceId);
setLastVoiceChangeAt(Date.now());
setTimeout(() => setShowVoiceMenu(false), 100);
setTimeout(() => setShowVoiceMenu(false), 200);
};
const handleVoiceMenuToggle = (e: React.MouseEvent) => {
@ -360,9 +359,6 @@ export function PhoneSimulator({ onConnect, phoneMode = "normal", onCapture }: P
e.stopPropagation();
// Guard against accidental call when just changing voice
if (showVoiceMenu) return;
if (lastVoiceChangeAt && Date.now() - lastVoiceChangeAt < 400) {
return;
}
onConnect();
}}
disabled={showVoiceMenu}

View File

@ -597,6 +597,7 @@ export default function Playground({
>
<PhoneSimulator
onConnect={() => onConnect(true)}
onDisconnect={() => onConnect(false)}
phoneMode={phoneMode}
onCapture={async (content: File) => {
if (localParticipant) {
@ -669,6 +670,7 @@ export default function Playground({
>
<PhoneSimulator
onConnect={() => onConnect(true)}
onDisconnect={() => onConnect(false)}
phoneMode={phoneMode}
onCapture={async (content: File) => {
if (localParticipant) {