From 80d59fddc603d9b5b02d59f336dd525691b1b90e Mon Sep 17 00:00:00 2001 From: Xin Wang Date: Fri, 10 Jul 2026 22:48:40 +0800 Subject: [PATCH] Update MobileCallPage and useVoicePreview to handle call end state - Introduce a new state variable `callEnded` in `useVoicePreview` to manage call termination more effectively. - Modify `MobileCallPage` to adjust the `inCall` condition based on `callEnded`, ensuring accurate UI updates during and after calls. - Update rendering logic to display appropriate messages based on call status, enhancing user feedback during call transitions. - Refactor button visibility to only show when in an active call, improving user interface clarity. --- .../src/components/pages/MobileCallPage.tsx | 60 +++++++++++-------- frontend/src/hooks/use-voice-preview.ts | 19 +++++- 2 files changed, 52 insertions(+), 27 deletions(-) diff --git a/frontend/src/components/pages/MobileCallPage.tsx b/frontend/src/components/pages/MobileCallPage.tsx index 39191d2..7769b95 100644 --- a/frontend/src/components/pages/MobileCallPage.tsx +++ b/frontend/src/components/pages/MobileCallPage.tsx @@ -248,6 +248,7 @@ export function MobileCallPage({ assistantId }: { assistantId: string }) { selectOutputDevice, supportsOutputSelection, messages, + callEnded, networkQuality, connect, replaceVideoStream, @@ -267,7 +268,7 @@ export function MobileCallPage({ assistantId }: { assistantId: string }) { const videoRef = useRef(null); const [view, setView] = useState("camera"); const connecting = status === "connecting"; - const inCall = connecting || status === "connected"; + const inCall = !callEnded && (connecting || status === "connected"); useEffect(() => { if (videoRef.current) videoRef.current.srcObject = cameraStream; @@ -282,6 +283,7 @@ export function MobileCallPage({ assistantId }: { assistantId: string }) { }, [connect, startCamera]); const endCall = useCallback(() => { + setView("camera"); disconnect(); stopCamera(); }, [disconnect, stopCamera]); @@ -300,11 +302,10 @@ export function MobileCallPage({ assistantId }: { assistantId: string }) { }, [startCall]); useEffect(() => { - if (status === "idle" || status === "failed") { + if (callEnded || status === "idle" || status === "failed") { stopCamera(); - setView("camera"); } - }, [status, stopCamera]); + }, [callEnded, status, stopCamera]); const error = previewError || cameraError; @@ -341,33 +342,39 @@ export function MobileCallPage({ assistantId }: { assistantId: string }) { - {status === "connected" - ? "通话中" - : connecting - ? "正在连接…" - : "通话已结束"} + {callEnded + ? "通话已结束" + : status === "connected" + ? "通话中" + : connecting + ? "正在连接…" + : "通话已结束"} - + {inCall && ( + + )} {!cameraStream && inCall && view === "camera" && (
@@ -391,7 +398,10 @@ export function MobileCallPage({ assistantId }: { assistantId: string }) {