Phase 3 completed: Flutter MVP with live streaming and auto-refresh
This commit is contained in:
37
frontend/lib/providers/auth_provider.dart
Normal file
37
frontend/lib/providers/auth_provider.dart
Normal file
@@ -0,0 +1,37 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class AuthProvider with ChangeNotifier {
|
||||
String? _token;
|
||||
bool _isAuthenticated = false;
|
||||
|
||||
bool get isAuthenticated => _isAuthenticated;
|
||||
String? get token => _token;
|
||||
|
||||
AuthProvider() {
|
||||
_loadToken();
|
||||
}
|
||||
|
||||
void _loadToken() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
_token = prefs.getString('token');
|
||||
_isAuthenticated = _token != null;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> login(String token) async {
|
||||
_token = token;
|
||||
_isAuthenticated = true;
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString('token', token);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> logout() async {
|
||||
_token = null;
|
||||
_isAuthenticated = false;
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.remove('token');
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
33
frontend/lib/providers/settings_provider.dart
Normal file
33
frontend/lib/providers/settings_provider.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class SettingsProvider with ChangeNotifier {
|
||||
// Default server address for local development.
|
||||
// Using 10.0.2.2 for Android emulator or localhost for Desktop.
|
||||
String _baseUrl = "http://localhost:8080";
|
||||
|
||||
String get baseUrl => _baseUrl;
|
||||
|
||||
SettingsProvider() {
|
||||
_loadSettings();
|
||||
}
|
||||
|
||||
void _loadSettings() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
_baseUrl = prefs.getString('baseUrl') ?? _baseUrl;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void setBaseUrl(String url) async {
|
||||
_baseUrl = url;
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString('baseUrl', url);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// Also provide the RTMP URL based on the same hostname
|
||||
String get rtmpUrl {
|
||||
final uri = Uri.parse(_baseUrl);
|
||||
return "rtmp://${uri.host}:1935/live";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user