对接远程遥控

This commit is contained in:
2026-06-05 19:06:21 +08:00
parent d8879dad62
commit 7c9734d918
53 changed files with 4683 additions and 1612 deletions

View File

@@ -53,6 +53,13 @@ class _WebRTCLocalPlayerState extends State<WebRTCLocalPlayer> {
}
Future<void> _initWebRTCConnection() async {
// 🔥 安全检查: URL 为空时不初始化
if (widget.streamUrl.isEmpty) {
debugPrint('⚠️ [WebRTC] streamUrl 为空,跳过初始化');
setState(() => _isInitialized = true); // 🔥 标记为已初始化,避免卡loading
return;
}
_peerConnection = await createPeerConnection({
"sdpSemantics": "unified-plan",
"iceServers": [
@@ -86,7 +93,15 @@ class _WebRTCLocalPlayerState extends State<WebRTCLocalPlayer> {
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
await _peerConnection!.setRemoteDescription(RTCSessionDescription(data['sdp'], 'answer'));
final sdp = data['sdp'];
// 🔥 安全检查: SDP 不能为 null
if (sdp != null && sdp is String && sdp.isNotEmpty) {
await _peerConnection!.setRemoteDescription(RTCSessionDescription(sdp, 'answer'));
debugPrint('✅ [WebRTC] setRemoteDescription 成功');
} else {
debugPrint('❌ [WebRTC] SDP 为空或无效,跳过 setRemoteDescription');
}
}
} catch (e) {
debugPrint("信令错误: $e");