feat(voice-call): Improve socket connection and mic permission handling

This commit is contained in:
cogwheel0
2025-11-29 13:30:31 +05:30
parent 24bf1f06cb
commit 2ef49a2974
4 changed files with 83 additions and 8 deletions

View File

@@ -158,11 +158,15 @@ class VoiceCallService {
throw Exception('Preferred speech recognition engine is unavailable');
}
// Check microphone permissions
final hasMicPermission = await _voiceInput.checkPermissions();
// Check and request microphone permissions if needed
var hasMicPermission = await _voiceInput.checkPermissions();
if (!hasMicPermission) {
_updateState(VoiceCallState.error);
throw Exception('Microphone permission not granted');
// Try to request permission
hasMicPermission = await _voiceInput.requestMicrophonePermission();
if (!hasMicPermission) {
_updateState(VoiceCallState.error);
throw Exception('Microphone permission not granted');
}
}
// Initialize TTS with current app settings (engine/voice/rate/pitch/volume)
@@ -309,11 +313,14 @@ class VoiceCallService {
// Enable wake lock to keep screen on and prevent audio interruption
await WakelockPlus.enable();
// Ensure socket connection
await _socketService.ensureConnected();
// Ensure socket connection with extended timeout for app startup scenarios.
// Default 2s is too short when app is launched from deep links/shortcuts.
final connected = await _socketService.ensureConnected(
timeout: const Duration(seconds: 10),
);
_sessionId = _socketService.sessionId;
if (_sessionId == null) {
if (!connected || _sessionId == null) {
throw Exception('Failed to establish socket connection');
}