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:
parent
0881a9565d
commit
b3d5dcd94e
@ -56,7 +56,7 @@ function MenuItem({
|
||||
|
||||
export default function ProfileScreen() {
|
||||
const { user, logout } = useAuth();
|
||||
const { updateVoiceApiType } = useVoice();
|
||||
const { updateVoiceApiType, stopSession, isActive } = useVoice();
|
||||
const [deploymentId, setDeploymentId] = useState<string>('');
|
||||
const [deploymentName, setDeploymentName] = useState<string>('');
|
||||
const [showDeploymentModal, setShowDeploymentModal] = useState(false);
|
||||
@ -150,11 +150,17 @@ export default function ProfileScreen() {
|
||||
}, [tempDeploymentId]);
|
||||
|
||||
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);
|
||||
setVoiceApiType(tempVoiceApiType);
|
||||
updateVoiceApiType(tempVoiceApiType);
|
||||
setShowVoiceApiModal(false);
|
||||
}, [tempVoiceApiType, updateVoiceApiType]);
|
||||
}, [tempVoiceApiType, updateVoiceApiType, isActive, stopSession]);
|
||||
|
||||
const openTerms = () => {
|
||||
router.push('/terms');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user