fix select voice will triger agent call
This commit is contained in:
parent
026cde6d47
commit
974cf0994f
@ -17,11 +17,12 @@ import { useToast } from "@/components/toast/ToasterProvider";
|
|||||||
|
|
||||||
export interface PhoneSimulatorProps {
|
export interface PhoneSimulatorProps {
|
||||||
onConnect: () => void;
|
onConnect: () => void;
|
||||||
|
onDisconnect: () => void;
|
||||||
phoneMode?: "normal" | "capture";
|
phoneMode?: "normal" | "capture";
|
||||||
onCapture?: (image: File) => void;
|
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 { config, setUserSettings } = useConfig();
|
||||||
const { setToastMessage } = useToast();
|
const { setToastMessage } = useToast();
|
||||||
const room = useRoomContext();
|
const room = useRoomContext();
|
||||||
@ -41,7 +42,6 @@ export function PhoneSimulator({ onConnect, phoneMode = "normal", onCapture }: P
|
|||||||
const [processingSource, setProcessingSource] = useState<
|
const [processingSource, setProcessingSource] = useState<
|
||||||
"camera" | "upload" | null
|
"camera" | "upload" | null
|
||||||
>(null);
|
>(null);
|
||||||
const [lastVoiceChangeAt, setLastVoiceChangeAt] = useState<number | null>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const voiceAttr = config.settings.attributes?.find(a => a.key === "voice");
|
const voiceAttr = config.settings.attributes?.find(a => a.key === "voice");
|
||||||
@ -169,7 +169,7 @@ export function PhoneSimulator({ onConnect, phoneMode = "normal", onCapture }: P
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleDisconnect = () => {
|
const handleDisconnect = () => {
|
||||||
room.disconnect();
|
onDisconnect();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCapture = async () => {
|
const handleCapture = async () => {
|
||||||
@ -328,8 +328,7 @@ export function PhoneSimulator({ onConnect, phoneMode = "normal", onCapture }: P
|
|||||||
newSettings.attributes = attributes;
|
newSettings.attributes = attributes;
|
||||||
setUserSettings(newSettings);
|
setUserSettings(newSettings);
|
||||||
setCurrentVoiceId(voiceId);
|
setCurrentVoiceId(voiceId);
|
||||||
setLastVoiceChangeAt(Date.now());
|
setTimeout(() => setShowVoiceMenu(false), 200);
|
||||||
setTimeout(() => setShowVoiceMenu(false), 100);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleVoiceMenuToggle = (e: React.MouseEvent) => {
|
const handleVoiceMenuToggle = (e: React.MouseEvent) => {
|
||||||
@ -360,9 +359,6 @@ export function PhoneSimulator({ onConnect, phoneMode = "normal", onCapture }: P
|
|||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
// Guard against accidental call when just changing voice
|
// Guard against accidental call when just changing voice
|
||||||
if (showVoiceMenu) return;
|
if (showVoiceMenu) return;
|
||||||
if (lastVoiceChangeAt && Date.now() - lastVoiceChangeAt < 400) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
onConnect();
|
onConnect();
|
||||||
}}
|
}}
|
||||||
disabled={showVoiceMenu}
|
disabled={showVoiceMenu}
|
||||||
|
|||||||
@ -597,6 +597,7 @@ export default function Playground({
|
|||||||
>
|
>
|
||||||
<PhoneSimulator
|
<PhoneSimulator
|
||||||
onConnect={() => onConnect(true)}
|
onConnect={() => onConnect(true)}
|
||||||
|
onDisconnect={() => onConnect(false)}
|
||||||
phoneMode={phoneMode}
|
phoneMode={phoneMode}
|
||||||
onCapture={async (content: File) => {
|
onCapture={async (content: File) => {
|
||||||
if (localParticipant) {
|
if (localParticipant) {
|
||||||
@ -669,6 +670,7 @@ export default function Playground({
|
|||||||
>
|
>
|
||||||
<PhoneSimulator
|
<PhoneSimulator
|
||||||
onConnect={() => onConnect(true)}
|
onConnect={() => onConnect(true)}
|
||||||
|
onDisconnect={() => onConnect(false)}
|
||||||
phoneMode={phoneMode}
|
phoneMode={phoneMode}
|
||||||
onCapture={async (content: File) => {
|
onCapture={async (content: File) => {
|
||||||
if (localParticipant) {
|
if (localParticipant) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user