gpt4 book ai didi

javascript - WebRTC - 'RTCPeerConnection' : The ICE candidate could not be added

转载 作者:行者123 更新时间:2023-12-03 07:09:24 31 4
gpt4 key购买 nike

我在浏览器控制台中遇到的错误(仅出现在 Chrome 中,Firefox 中没有错误)是错误:无法在“RTCPeerConnection”上执行“addIceCandidate”:无法添加 ICE 候选者。

我按照教程进行操作,并能够使用 Nodejs 进行 p2p 视频聊天。现在我在服务器端使用 Flask 和 python,在客户端使用 angularjs。

两个对等点的信令过程是通过 Angular-socketio 完成的。

console.log("The user connected to the socket");
socket.emit('readyToJoinRoom', {"signal_room": SIGNAL_ROOM});

//Send a first signaling message to anyone listening
//This normally would be on a button click

socket.emit('signal',{"type":"user_joined", "message":"Are you ready for a call?", "room":SIGNAL_ROOM});

socket.forward('signaling_message', $scope);
$scope.$on('socket:signaling_message', function (ev, data) {
displaySignalMessage("Signal received: " + data.type);
// Setup the RTC Peer Connection object
if (!rtcPeerConn) {
startSignaling();
}

if(data.type != "user_joined") {
console.log(data.message);
var message = JSON.parse(data.message);
console.log(message);
if(message.sdp) {
console.log("inside 2nd if statement");
rtcPeerConn.setRemoteDescription(new RTCSessionDescription(message.sdp), function () {

// if we received an offer, we need to answer
if(rtcPeerConn.remoteDescription.type === 'offer') {
console.log("inside third if for remoteDescription."); // This never executes, error happens right before this line
rtcPeerConn.createAnswer(sendLocalDesc, logError);
}
}, logError);
}
else {
console.log("addedddddddd ice candidate.");
rtcPeerConn.addIceCandidate(new RTCIceCandidate(message.candidate));
}
}
});

一旦两个人加入房间,就会调用 startSignaling() 方法。它设置本地描述并完成 3 个ice候选,然后我收到一个 SDP,但这永远不是真的 if(rtcPeerConn.remoteDescription.type === 'offer') 即使它在控制台中打印 SDP类型等于offer。我不知道为什么它永远不会出现在这个 if 语句中。我不知道为什么我会收到错误。如果你有问题,就问吧。谢谢您的帮助。

最佳答案

我认为

rtcPeerConn.setRemoteDescription(new RTCSessionDescription(message.sdp),...

将不起作用,因为 RTCSessionDescription 的构造函数需要有关类型和 sdp 的信息。尝试:

var desc = new RTCSessionDescription();
desc.sdp = message.sdp;
desc.type = "offer";
rtcPeerConn.setRemoteDescription(desc,.....

我在从 JSON 构建 RTCSessionDescription 时也遇到了一些问题。希望这有帮助...

关于javascript - WebRTC - 'RTCPeerConnection' : The ICE candidate could not be added,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36672633/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com