feat(sender): 设备指纹固定、/watch 实时刷新、中继连接与文件子协议上传
- 新增 PinStore:首次连接记录被控端签名指纹,变化时弹窗确认 - 新增 SignalingWatch:订阅 /watch,300ms 去抖后重拉设备列表 - 设置页新增"连接走信令中继",主控端按该开关走 ttstd_relay_start - 中继模式禁用投屏并提示原因,状态卡区分直连/中继 - 新增 ControlFileClient:通过 msgType=7 分片上传/列目录,文件页加入口 - NativeCore/Bridge 暴露 relayStart/relayStop/sendFileRequest
This commit is contained in:
1 parent
22bac28914
commit
a9ba4bb7bc
9 files changed
+752
-8
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
@@ -51,6 +52,24 @@ class SenderBridge {
|
||||
/// 事件形如 `{"type":8,"action":2,"text":""}`,`type` 是 msgType。
|
||||
Map<String, dynamic>? nextInboundEvent() => _native?.pollEvent();
|
||||
|
||||
/// 控制通道文件子协议(`msg_type=7`):发一条 JSON 请求并等响应。
|
||||
///
|
||||
/// FFI 那一层是阻塞的(等被控端响应),所以放到独立 isolate 里跑,
|
||||
/// 避免上传时把界面卡住几秒。
|
||||
Future<Map<String, dynamic>> sendFileRequest(Map<String, dynamic> request) async {
|
||||
if (_native == null) {
|
||||
throw StateError('当前平台没有原生控制通道');
|
||||
}
|
||||
return Isolate.run(() {
|
||||
final core = NativeCore();
|
||||
try {
|
||||
return core.fileRequest(request);
|
||||
} finally {
|
||||
core.dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _handleVideoCall(MethodCall call) async {
|
||||
switch (call.method) {
|
||||
case 'windowClosed':
|
||||
@@ -186,12 +205,37 @@ class SenderBridge {
|
||||
Future<void> disconnect() async {
|
||||
final native = _native;
|
||||
if (native != null) {
|
||||
native.stopRelay();
|
||||
native.stopDemoServer();
|
||||
return;
|
||||
}
|
||||
await _invokeIgnoringMissing('disconnect');
|
||||
}
|
||||
|
||||
/// 通过信令服务器建立中继控制会话(跨网段用)。
|
||||
///
|
||||
/// 成功返回 null,失败返回原因。中继只承载控制帧,视频/音频仍需同网段直连。
|
||||
String? startRelay(DeviceInfo device, String signalingUrl) {
|
||||
final native = _native;
|
||||
if (native == null) return '中继需要桌面端原生 Core';
|
||||
if (device.id.trim().isEmpty) return '这台设备没有信令 id,无法走中继';
|
||||
if (signalingUrl.trim().isEmpty) return '没有配置信令服务器地址';
|
||||
return native.startRelay(signalingUrl.trim(), device.id.trim());
|
||||
}
|
||||
|
||||
void stopRelay() => _native?.stopRelay();
|
||||
|
||||
/// 当前控制通道是否走中继(读 Rust 侧状态,避免界面自己记状态)。
|
||||
bool get isRelayActive {
|
||||
final native = _native;
|
||||
if (native == null) return false;
|
||||
try {
|
||||
return native.demoStatus()['relay'] == true;
|
||||
} on Object {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> sendControl(String type, Map<String, dynamic> payload) async {
|
||||
final native = _native;
|
||||
if (native != null) {
|
||||
|
||||
Reference in new issue
Block a user