Add TWP Softphone Flutter app and complete mobile backend API
Backend: Add /voice/token endpoint with AccessToken + VoiceGrant for
mobile VoIP, implement unhold_call() with call leg detection, wire FCM
push notifications into call queue and webhook missed call handlers,
add data-only FCM message support for Android background wake, and add
Twilio API Key / Push Credential settings fields.
Flutter app: Full softphone with Twilio Voice SDK integration, JWT auth
with auto-refresh, SSE real-time queue updates, FCM push notifications,
Material 3 UI with dashboard, active call screen, dialpad, and call
controls (mute/speaker/hold/transfer).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-06 13:01:23 -08:00
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
|
import '../models/user.dart';
|
|
|
|
|
import '../services/api_client.dart';
|
|
|
|
|
import '../services/auth_service.dart';
|
|
|
|
|
import '../services/voice_service.dart';
|
|
|
|
|
import '../services/push_notification_service.dart';
|
|
|
|
|
import '../services/sse_service.dart';
|
|
|
|
|
|
|
|
|
|
enum AuthState { unauthenticated, authenticating, authenticated }
|
|
|
|
|
|
|
|
|
|
class AuthProvider extends ChangeNotifier {
|
|
|
|
|
final ApiClient _apiClient;
|
2026-03-07 17:11:02 -08:00
|
|
|
late AuthService _authService;
|
|
|
|
|
late VoiceService _voiceService;
|
|
|
|
|
late PushNotificationService _pushService;
|
|
|
|
|
late SseService _sseService;
|
Add TWP Softphone Flutter app and complete mobile backend API
Backend: Add /voice/token endpoint with AccessToken + VoiceGrant for
mobile VoIP, implement unhold_call() with call leg detection, wire FCM
push notifications into call queue and webhook missed call handlers,
add data-only FCM message support for Android background wake, and add
Twilio API Key / Push Credential settings fields.
Flutter app: Full softphone with Twilio Voice SDK integration, JWT auth
with auto-refresh, SSE real-time queue updates, FCM push notifications,
Material 3 UI with dashboard, active call screen, dialpad, and call
controls (mute/speaker/hold/transfer).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-06 13:01:23 -08:00
|
|
|
|
|
|
|
|
AuthState _state = AuthState.unauthenticated;
|
|
|
|
|
User? _user;
|
|
|
|
|
String? _error;
|
|
|
|
|
|
|
|
|
|
AuthState get state => _state;
|
|
|
|
|
User? get user => _user;
|
|
|
|
|
String? get error => _error;
|
|
|
|
|
VoiceService get voiceService => _voiceService;
|
|
|
|
|
SseService get sseService => _sseService;
|
|
|
|
|
ApiClient get apiClient => _apiClient;
|
|
|
|
|
|
|
|
|
|
AuthProvider(this._apiClient) {
|
|
|
|
|
_authService = AuthService(_apiClient);
|
|
|
|
|
_voiceService = VoiceService(_apiClient);
|
|
|
|
|
_pushService = PushNotificationService(_apiClient);
|
|
|
|
|
_sseService = SseService(_apiClient);
|
|
|
|
|
|
|
|
|
|
_apiClient.onForceLogout = _handleForceLogout;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> tryRestoreSession() async {
|
2026-03-07 17:11:02 -08:00
|
|
|
final user = await _authService.tryRestoreSession();
|
|
|
|
|
if (user != null) {
|
|
|
|
|
_user = user;
|
Add TWP Softphone Flutter app and complete mobile backend API
Backend: Add /voice/token endpoint with AccessToken + VoiceGrant for
mobile VoIP, implement unhold_call() with call leg detection, wire FCM
push notifications into call queue and webhook missed call handlers,
add data-only FCM message support for Android background wake, and add
Twilio API Key / Push Credential settings fields.
Flutter app: Full softphone with Twilio Voice SDK integration, JWT auth
with auto-refresh, SSE real-time queue updates, FCM push notifications,
Material 3 UI with dashboard, active call screen, dialpad, and call
controls (mute/speaker/hold/transfer).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-06 13:01:23 -08:00
|
|
|
_state = AuthState.authenticated;
|
|
|
|
|
await _initializeServices();
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> login(String serverUrl, String username, String password) async {
|
|
|
|
|
_state = AuthState.authenticating;
|
|
|
|
|
_error = null;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
_user = await _authService.login(serverUrl, username, password);
|
|
|
|
|
_state = AuthState.authenticated;
|
|
|
|
|
await _initializeServices();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
_state = AuthState.unauthenticated;
|
|
|
|
|
_error = e.toString().replaceFirst('Exception: ', '');
|
|
|
|
|
}
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _initializeServices() async {
|
|
|
|
|
try {
|
|
|
|
|
await _pushService.initialize();
|
2026-03-06 18:05:54 -08:00
|
|
|
} catch (e) {
|
|
|
|
|
debugPrint('AuthProvider: push service init error: $e');
|
|
|
|
|
}
|
Add TWP Softphone Flutter app and complete mobile backend API
Backend: Add /voice/token endpoint with AccessToken + VoiceGrant for
mobile VoIP, implement unhold_call() with call leg detection, wire FCM
push notifications into call queue and webhook missed call handlers,
add data-only FCM message support for Android background wake, and add
Twilio API Key / Push Credential settings fields.
Flutter app: Full softphone with Twilio Voice SDK integration, JWT auth
with auto-refresh, SSE real-time queue updates, FCM push notifications,
Material 3 UI with dashboard, active call screen, dialpad, and call
controls (mute/speaker/hold/transfer).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-06 13:01:23 -08:00
|
|
|
try {
|
2026-03-07 17:11:02 -08:00
|
|
|
await _voiceService.initialize(deviceToken: _pushService.fcmToken);
|
2026-03-06 18:05:54 -08:00
|
|
|
} catch (e) {
|
|
|
|
|
debugPrint('AuthProvider: voice service init error: $e');
|
|
|
|
|
}
|
Add TWP Softphone Flutter app and complete mobile backend API
Backend: Add /voice/token endpoint with AccessToken + VoiceGrant for
mobile VoIP, implement unhold_call() with call leg detection, wire FCM
push notifications into call queue and webhook missed call handlers,
add data-only FCM message support for Android background wake, and add
Twilio API Key / Push Credential settings fields.
Flutter app: Full softphone with Twilio Voice SDK integration, JWT auth
with auto-refresh, SSE real-time queue updates, FCM push notifications,
Material 3 UI with dashboard, active call screen, dialpad, and call
controls (mute/speaker/hold/transfer).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-06 13:01:23 -08:00
|
|
|
try {
|
|
|
|
|
await _sseService.connect();
|
2026-03-06 18:05:54 -08:00
|
|
|
} catch (e) {
|
|
|
|
|
debugPrint('AuthProvider: SSE connect error: $e');
|
|
|
|
|
}
|
Add TWP Softphone Flutter app and complete mobile backend API
Backend: Add /voice/token endpoint with AccessToken + VoiceGrant for
mobile VoIP, implement unhold_call() with call leg detection, wire FCM
push notifications into call queue and webhook missed call handlers,
add data-only FCM message support for Android background wake, and add
Twilio API Key / Push Credential settings fields.
Flutter app: Full softphone with Twilio Voice SDK integration, JWT auth
with auto-refresh, SSE real-time queue updates, FCM push notifications,
Material 3 UI with dashboard, active call screen, dialpad, and call
controls (mute/speaker/hold/transfer).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-06 13:01:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> logout() async {
|
|
|
|
|
_voiceService.dispose();
|
|
|
|
|
_sseService.disconnect();
|
|
|
|
|
await _authService.logout();
|
|
|
|
|
|
|
|
|
|
_state = AuthState.unauthenticated;
|
|
|
|
|
_user = null;
|
|
|
|
|
_error = null;
|
|
|
|
|
|
|
|
|
|
// Re-create services for potential re-login
|
|
|
|
|
_voiceService = VoiceService(_apiClient);
|
|
|
|
|
_pushService = PushNotificationService(_apiClient);
|
|
|
|
|
_sseService = SseService(_apiClient);
|
|
|
|
|
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _handleForceLogout() {
|
2026-03-07 17:11:02 -08:00
|
|
|
_voiceService.dispose();
|
|
|
|
|
_sseService.disconnect();
|
|
|
|
|
|
Add TWP Softphone Flutter app and complete mobile backend API
Backend: Add /voice/token endpoint with AccessToken + VoiceGrant for
mobile VoIP, implement unhold_call() with call leg detection, wire FCM
push notifications into call queue and webhook missed call handlers,
add data-only FCM message support for Android background wake, and add
Twilio API Key / Push Credential settings fields.
Flutter app: Full softphone with Twilio Voice SDK integration, JWT auth
with auto-refresh, SSE real-time queue updates, FCM push notifications,
Material 3 UI with dashboard, active call screen, dialpad, and call
controls (mute/speaker/hold/transfer).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-06 13:01:23 -08:00
|
|
|
_state = AuthState.unauthenticated;
|
|
|
|
|
_user = null;
|
|
|
|
|
_error = 'Session expired. Please log in again.';
|
2026-03-07 17:11:02 -08:00
|
|
|
|
|
|
|
|
// Re-create services for potential re-login
|
|
|
|
|
_voiceService = VoiceService(_apiClient);
|
|
|
|
|
_pushService = PushNotificationService(_apiClient);
|
|
|
|
|
_sseService = SseService(_apiClient);
|
|
|
|
|
|
Add TWP Softphone Flutter app and complete mobile backend API
Backend: Add /voice/token endpoint with AccessToken + VoiceGrant for
mobile VoIP, implement unhold_call() with call leg detection, wire FCM
push notifications into call queue and webhook missed call handlers,
add data-only FCM message support for Android background wake, and add
Twilio API Key / Push Credential settings fields.
Flutter app: Full softphone with Twilio Voice SDK integration, JWT auth
with auto-refresh, SSE real-time queue updates, FCM push notifications,
Material 3 UI with dashboard, active call screen, dialpad, and call
controls (mute/speaker/hold/transfer).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-06 13:01:23 -08:00
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
_authService.dispose();
|
|
|
|
|
_voiceService.dispose();
|
|
|
|
|
_sseService.dispose();
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|