feat: 真实连接链路、移除虚拟数据、全量打包脚本

This commit is contained in:
tongtong committed 2026-11-26 21:39:10 +08:00
1 parent 31b9a52eb4
commit 34340f4126
16 files changed
+601 -204

No files matched your search

+29 -71
View File
@@ -43,14 +43,13 @@ class _HomePageState extends State<HomePage> {
late final SenderBridge _bridge;
Timer? _demoStatusTimer;
List<DeviceInfo> _devices = SenderBridge.mockDevices;
DeviceInfo? _selected = SenderBridge.mockDevices.first;
List<DeviceInfo> _devices = const <DeviceInfo>[];
DeviceInfo? _selected;
ConnectionPhase _phase = ConnectionPhase.idle;
AppSettings _settings = AppSettings.defaults;
String _effectiveSignalingUrl = AppSettings.defaults.signalingUrl;
bool _localSignalingRunning = false;
bool _refreshing = false;
Map<String, dynamic>? _selfTest;
Map<String, dynamic> _demoStatus = const <String, dynamic>{'running': false};
String? _nativeError;
@@ -68,7 +67,6 @@ class _HomePageState extends State<HomePage> {
});
_applySignalingSettings();
_refreshDevices();
_runSelfTest();
_demoStatusTimer = Timer.periodic(
const Duration(seconds: 1),
(_) => _refreshDemoStatus(),
@@ -84,41 +82,26 @@ class _HomePageState extends State<HomePage> {
super.dispose();
}
void _runSelfTest() {
if (_nativeCore == null) return;
try {
final result = _bridge.runCryptoSelfTest();
if (mounted) setState(() => _selfTest = result);
} on Object catch (error) {
if (mounted) setState(() => _nativeError = error.toString());
}
}
void _refreshDemoStatus() {
if (_nativeCore == null || !mounted) return;
try {
final status = _bridge.demoStatus();
setState(() => _demoStatus = status);
setState(() {
_demoStatus = status;
final running = status['running'] == true;
final connected = status['peerConnected'] == true;
final keyEstablished = status['keyEstablished'] == true;
if (running && connected && keyEstablished) {
_phase = ConnectionPhase.direct;
} else if (running && _phase != ConnectionPhase.idle) {
_phase = ConnectionPhase.probing;
}
});
} on Object catch (_) {
// 动态库不可用时忽略轮询错误。
}
}
void _toggleDemoServer() {
if (_nativeCore == null) return;
try {
final running = _demoStatus['running'] == true;
if (running) {
_bridge.stopDemoServer();
} else {
_bridge.startDemoServer();
}
_refreshDemoStatus();
} on Object catch (error) {
if (mounted) setState(() => _nativeError = error.toString());
}
}
Future<void> _applySignalingSettings() async {
if (_settings.localSignalingEnabled) {
final started = await _bridge.startLocalSignaling(_settings.localSignalingPort);
@@ -153,8 +136,6 @@ class _HomePageState extends State<HomePage> {
if (device == null) return;
setState(() => _phase = ConnectionPhase.probing);
await _bridge.connect(device);
if (!mounted) return;
setState(() => _phase = ConnectionPhase.direct);
}
Future<void> _disconnect() async {
@@ -178,6 +159,12 @@ class _HomePageState extends State<HomePage> {
Future<void> _showPairing() async {
final uri = await _bridge.pairingUri();
if (!mounted) return;
if (uri == null) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('当前平台不支持扫码配对')),
);
return;
}
showDialog<void>(
context: context,
builder: (context) => AlertDialog(
@@ -298,16 +285,11 @@ class _HomePageState extends State<HomePage> {
);
}
Widget _buildNativeDemoCard() {
final native = _nativeCore;
final test = _selfTest;
Widget _buildConnectionStatusCard() {
final status = _demoStatus;
final running = status['running'] == true;
final connected = status['peerConnected'] == true;
final keyEstablished = status['keyEstablished'] == true;
final events = (status['events'] as List<dynamic>? ?? const <dynamic>[])
.map((item) => item.toString())
.toList();
final peerIp = (status['peerIp'] as String? ?? '').trim();
return Card(
child: Padding(
@@ -317,48 +299,24 @@ class _HomePageState extends State<HomePage> {
children: [
Row(
children: [
const Icon(Icons.bolt_outlined, size: 18),
const Icon(Icons.link, size: 18),
const SizedBox(width: 8),
const Text('Rust Core 协议自检', style: TextStyle(fontWeight: FontWeight.bold)),
const Spacer(),
if (native != null)
TextButton(
onPressed: _toggleDemoServer,
child: Text(running ? '停止 demo 服务' : '启动 demo 服务'),
),
const Text('连接状态', style: TextStyle(fontWeight: FontWeight.bold)),
],
),
const SizedBox(height: 8),
if (_nativeError != null)
Text(
_nativeError!,
style: TextStyle(color: Theme.of(context).colorScheme.error, fontSize: 12),
)
else if (native == null)
const Text('未加载 Rust Core 动态库(桌面端编译后自动可用)。')
else
Text(
'版本 ${native.versionString} · ABI ${native.abiRevision()} · '
'ECDH ${test?['ecdhMatch'] == true ? '一致' : '未验证'} · '
'控制帧 ${test?['controlFrameBytes'] ?? '-'} B · '
'媒体包 ${test?['mediaPacketBytes'] ?? '-'} B',
'被控端 ${connected ? '已连接' : '未连接'} · '
'${keyEstablished ? '会话密钥已建立' : '等待 ECDH 协商'}' +
(peerIp.isEmpty ? '' : ' · 对端 $peerIp'),
style: Theme.of(context).textTheme.bodySmall,
),
const SizedBox(height: 8),
Text(
'demo 服务:${running ? '运行中' : '已停止'} · '
'被控端 ${connected ? '已连接' : '未连接'} · '
'${keyEstablished ? '会话密钥已建立' : '等待 ECDH'} · '
'密钥 ${status['controlKey'] ?? '----'}',
style: Theme.of(context).textTheme.bodySmall,
),
if (events.isNotEmpty)
Padding(
padding: const EdgeInsets.only(top: 8),
child: Text(
events.take(5).join('\n'),
style: Theme.of(context).textTheme.bodySmall?.copyWith(fontSize: 11),
),
),
],
),
),
@@ -374,7 +332,7 @@ class _HomePageState extends State<HomePage> {
VideoView(
textureId: null,
connected: _phase.isConnected,
resolution: _selected?.resolution ?? '1920x1080',
resolution: _selected?.resolution ?? '',
),
const SizedBox(height: 16),
ConnectBar(
@@ -389,7 +347,7 @@ class _HomePageState extends State<HomePage> {
onEvent: _sendControl,
),
const SizedBox(height: 12),
_buildNativeDemoCard(),
_buildConnectionStatusCard(),
const SizedBox(height: 12),
Card(
child: Padding(