fix(sender): 串流窗口锁定视频比例,关窗即停流,修正文件传输取 IP
- 独立窗口首帧到达后按视频宽高比自动调整并居中;WM_SIZING 锁定比例,最小 320x180 - 去掉 WS_MAXIMIZEBOX 与双击/F11 全屏,只保留关闭与最小化 - 移除停止投屏按钮;WM_DESTROY 通过 ttstd/video 通道回调 windowClosed,Dart 侧下发 stopMirror - 文件传输地址优先取设备局域网 IP,取不到时回退控制通道 peerIp,并在文件页提供可编辑 IP 输入
This commit is contained in:
1 parent
d3ff293877
commit
d8357a8491
8 files changed
+321
-127
No files matched your search
@@ -76,6 +76,8 @@ class _HomePageState extends State<HomePage> {
|
||||
_nativeError = error.toString();
|
||||
}
|
||||
_bridge = SenderBridge(nativeCore: _nativeCore);
|
||||
// 独立窗口被用户关闭 → 停止投屏。
|
||||
_bridge.onVideoWindowClosed = _handleVideoWindowClosed;
|
||||
_diagnosticLog.start();
|
||||
_diagnosticLog.write('app initialized; nativeError=${_nativeError ?? '-'}');
|
||||
_bridge.watchPhase().listen((phase) {
|
||||
@@ -196,32 +198,15 @@ class _HomePageState extends State<HomePage> {
|
||||
}
|
||||
}
|
||||
|
||||
/// 停止投屏:通知被控端结束推流,并关闭独立画面窗口。
|
||||
Future<void> _stopMirror() async {
|
||||
if (_phase.isConnected) {
|
||||
_sendControl('stopMirror', const {});
|
||||
_diagnosticLog.write('mirror stop sent');
|
||||
}
|
||||
await _bridge.closeVideoWindow();
|
||||
/// 用户关掉独立串流窗口(点关闭按钮 / 按 ESC)→ 直接停止投屏。
|
||||
Future<void> _handleVideoWindowClosed() async {
|
||||
if (!mounted) return;
|
||||
setState(() => _videoWindowOpen = false);
|
||||
}
|
||||
|
||||
/// 独立窗口显隐(不停流)。
|
||||
Future<void> _toggleVideoWindow() async {
|
||||
if (_videoWindowOpen) {
|
||||
await _bridge.closeVideoWindow();
|
||||
if (!mounted) return;
|
||||
setState(() => _videoWindowOpen = false);
|
||||
return;
|
||||
}
|
||||
final opened = await _bridge.openVideoWindow();
|
||||
if (!mounted) return;
|
||||
if (!opened) {
|
||||
_snack('当前平台不支持独立串流窗口');
|
||||
return;
|
||||
}
|
||||
setState(() => _videoWindowOpen = true);
|
||||
if (!_phase.isConnected) return;
|
||||
// 先通知被控端收流,再确保窗口已经关掉(用户已手动关了就无需重复动作)。
|
||||
_bridge.sendControl('stopMirror', const {});
|
||||
_diagnosticLog.write('video window closed -> stopMirror');
|
||||
_snack('串流窗口已关闭,已停止投屏');
|
||||
}
|
||||
|
||||
void _snack(String message) {
|
||||
@@ -248,7 +233,7 @@ class _HomePageState extends State<HomePage> {
|
||||
Text('文件传输', style: Theme.of(context).textTheme.titleMedium),
|
||||
const Spacer(),
|
||||
Text(
|
||||
host.isEmpty ? '未选设备' : '$host:${_settings.filePort}',
|
||||
host.isEmpty ? '未拿到被控端 IP' : '$host:${_settings.filePort}',
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
@@ -271,19 +256,39 @@ class _HomePageState extends State<HomePage> {
|
||||
);
|
||||
}
|
||||
|
||||
/// 文件服务要连的被控端地址。
|
||||
///
|
||||
/// 优先用设备列表里的局域网 IP;设备信息没带 IP 时退回到控制通道的对端 IP
|
||||
/// (`peerIp`),避免出现「连 127.0.0.1」这种必然失败的情况。
|
||||
String get _fileHost {
|
||||
final candidate = _selected?.ip.trim() ?? '';
|
||||
if (_isUsableHost(candidate)) return candidate;
|
||||
final peer = (_demoStatus['peerIp'] as String? ?? '').trim();
|
||||
if (_isUsableHost(peer)) return peer;
|
||||
return candidate;
|
||||
}
|
||||
|
||||
static bool _isUsableHost(String host) {
|
||||
if (host.isEmpty) return false;
|
||||
return host != '127.0.0.1' && host != '0.0.0.0' && host != '::1' && host != 'localhost';
|
||||
}
|
||||
|
||||
Future<void> _openFileBrowser() async {
|
||||
final device = _selected;
|
||||
if (device == null) {
|
||||
if (_selected == null) {
|
||||
_snack('请先选中被控端设备');
|
||||
return;
|
||||
}
|
||||
final host = _fileHost;
|
||||
if (!_isUsableHost(host)) {
|
||||
_snack('还没拿到被控端 IP:请先连接设备,或在文件页手动填写 IP');
|
||||
}
|
||||
await Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (_) => FileBrowserPage(
|
||||
host: device.ip,
|
||||
host: host,
|
||||
initialPort: _settings.filePort,
|
||||
initialToken: _settings.fileToken,
|
||||
onConfigChanged: (port, token) {
|
||||
onConfigChanged: (host, port, token) {
|
||||
final updated = _settings.copyWith(filePort: port, fileToken: token);
|
||||
setState(() => _settings = updated);
|
||||
_bridge.saveSettings(updated);
|
||||
@@ -674,8 +679,6 @@ class _HomePageState extends State<HomePage> {
|
||||
frames: _videoFrames,
|
||||
error: _videoError,
|
||||
onRequest: _requestMirror,
|
||||
onStop: _stopMirror,
|
||||
onToggleWindow: _toggleVideoWindow,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
ControlToolbar(
|
||||
|
||||
Reference in new issue
Block a user