WebRTC - ' RTCPeerConnection':无法添加ICE候选人

时间:2016-04-17 04:20:10

标签: javascript python angularjs node.js webrtc

我在浏览器控制台中遇到的错误(仅在Chrome中显示,在Firefox中没有错误)错误:无法执行' addIceCandidate' on' RTCPeerConnection':无法添加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语句。我不知道为什么我会收到错误。如果你有问题,就问吧。谢谢您的帮助。

1 个答案:

答案 0 :(得分:1)

我认为

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

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

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

我也有一些问题从JSON构建RTCSessionDescription。 希望这会有所帮助...