【发布时间】:2016-08-08 22:20:36
【问题描述】:
我在浏览器控制台中遇到的错误(仅在 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 个候选冰,然后我收到一个 SDP,但这绝不是真的 if(rtcPeerConn.remoteDescription.type === 'offer') 即使它在控制台中打印 SDP类型等于提供。我不确定为什么它永远不会进入这个 if 语句。我不确定为什么我会收到错误消息。如果你有问题,就问吧。谢谢您的帮助。
【问题讨论】:
标签: javascript python angularjs node.js webrtc