Stop voice session when changing API type

Changes:
- Add stopSession and isActive from VoiceContext to Profile
- Stop active voice session before saving new API type
- Prevents mid-session API type changes

Now when user switches between voice_ask and ask_wellnuo_ai in Profile settings, any active voice session will be stopped automatically.
This commit is contained in:
Sergei 2026-01-28 19:50:44 -08:00
parent 0881a9565d
commit b3d5dcd94e

View File

@ -56,7 +56,7 @@ function MenuItem({
export default function ProfileScreen() { export default function ProfileScreen() {
const { user, logout } = useAuth(); const { user, logout } = useAuth();
const { updateVoiceApiType } = useVoice(); const { updateVoiceApiType, stopSession, isActive } = useVoice();
const [deploymentId, setDeploymentId] = useState<string>(''); const [deploymentId, setDeploymentId] = useState<string>('');
const [deploymentName, setDeploymentName] = useState<string>(''); const [deploymentName, setDeploymentName] = useState<string>('');
const [showDeploymentModal, setShowDeploymentModal] = useState(false); const [showDeploymentModal, setShowDeploymentModal] = useState(false);
@ -150,11 +150,17 @@ export default function ProfileScreen() {
}, [tempDeploymentId]); }, [tempDeploymentId]);
const saveVoiceApiType = useCallback(async () => { const saveVoiceApiType = useCallback(async () => {
// Stop active voice session if any before changing API type
if (isActive) {
console.log('[Profile] Stopping active voice session before API type change');
stopSession();
}
await api.setVoiceApiType(tempVoiceApiType); await api.setVoiceApiType(tempVoiceApiType);
setVoiceApiType(tempVoiceApiType); setVoiceApiType(tempVoiceApiType);
updateVoiceApiType(tempVoiceApiType); updateVoiceApiType(tempVoiceApiType);
setShowVoiceApiModal(false); setShowVoiceApiModal(false);
}, [tempVoiceApiType, updateVoiceApiType]); }, [tempVoiceApiType, updateVoiceApiType, isActive, stopSession]);
const openTerms = () => { const openTerms = () => {
router.push('/terms'); router.push('/terms');