- 增加信令访问令牌、HTTPS 校验、限流及跨网段中继连接修复 - 同步三端媒体 v2 协议,实现 AES-GCM、防重放和乱序分片重组,升级 Rust ABI 6 - 修复文件鉴权、权限协商及剪贴板越权,完善上传校验和串流超时处理 - 增加跨端回归测试及部署文档,在 AGENTS.md 记录真机与真实跨网段待验收项目
98 lines
2.6 KiB
Dart
98 lines
2.6 KiB
Dart
import 'dart:io';
|
|
|
|
class LocalSignalingProcess {
|
|
LocalSignalingProcess() {
|
|
_refreshLocalIp();
|
|
}
|
|
|
|
Process? _process;
|
|
bool _running = false;
|
|
String _localIp = '127.0.0.1';
|
|
|
|
bool get isRunning => _running;
|
|
|
|
Future<bool> start({int port = 8080}) async {
|
|
if (_running) return true;
|
|
await _refreshLocalIp();
|
|
final binary = _resolveBinary();
|
|
if (binary == null) return false;
|
|
|
|
try {
|
|
final process = await Process.start(
|
|
binary.path,
|
|
const <String>[],
|
|
workingDirectory: binary.parent.path,
|
|
environment: <String, String>{
|
|
'LISTEN_ADDR': ':$port', 'ALLOW_INSECURE_SIGNALING': '1',
|
|
'SIGNALING_TOKEN': '', 'TLS_CERT_FILE': '', 'TLS_KEY_FILE': '',
|
|
},
|
|
);
|
|
process.stdout.listen((_) {});
|
|
process.stderr.listen((_) {});
|
|
process.exitCode.then((_) {
|
|
_running = false;
|
|
_process = null;
|
|
});
|
|
_process = process;
|
|
_running = true;
|
|
return true;
|
|
} on Object {
|
|
_running = false;
|
|
_process = null;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
Future<void> stop() async {
|
|
final process = _process;
|
|
if (process == null) return;
|
|
_process = null;
|
|
_running = false;
|
|
try {
|
|
process.kill();
|
|
await process.exitCode.timeout(const Duration(seconds: 3));
|
|
} on Object {
|
|
// 进程未能及时退出时忽略,避免阻塞 UI。
|
|
}
|
|
}
|
|
|
|
String url({int port = 8080}) => 'http://${localIp()}:$port';
|
|
|
|
String localIp() => _localIp;
|
|
|
|
Future<void> _refreshLocalIp() async {
|
|
try {
|
|
final interfaces = await NetworkInterface.list();
|
|
for (final interface in interfaces) {
|
|
for (final address in interface.addresses) {
|
|
if (address.type == InternetAddressType.IPv4 && !address.isLoopback) {
|
|
_localIp = address.address;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
} on Object {
|
|
// 网络接口不可用时保留 127.0.0.1。
|
|
}
|
|
}
|
|
|
|
File? _resolveBinary() {
|
|
final candidates = <String>[
|
|
if (Platform.isWindows) 'signaling_server.exe' else 'signaling_server',
|
|
if (Platform.isWindows) 'ttstd-signaling.exe' else 'ttstd-signaling',
|
|
];
|
|
final directories = <Directory>[
|
|
File(Platform.resolvedExecutable).parent,
|
|
Directory.current,
|
|
Directory('${Directory.current.path}${Platform.pathSeparator}signaling_server'),
|
|
];
|
|
for (final directory in directories) {
|
|
for (final name in candidates) {
|
|
final file = File('${directory.path}${Platform.pathSeparator}$name');
|
|
if (file.existsSync()) return file;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|