对接远程遥控
This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user