- Flutter 桌面端通过 dart:ffi 调用 Rust Core cdylib - 实现 ECDH P-256 密钥协商、HKDF 子密钥派生、AES-256-GCM 控制帧 - Android 被控端用派生密钥做控制帧加密与媒体包 MAC - 新增 libopus JNI 骨架,默认回退 MediaCodec - 新增 aosp/zhanxun/neutral 签名变体与系统 sharedUserId - 本机独立信令服务与设置页开关 - 新增 .gitignore 排除所有编译产物与打包目录
95 lines
2.4 KiB
Dart
95 lines
2.4 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'},
|
|
);
|
|
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;
|
|
}
|
|
}
|