简体   繁体   English

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

[英]WebRTC - 'RTCPeerConnection': The ICE candidate could not be added

The error I am getting in the browser console (only appears in chrome, no errors in firefox) is Error: Failed to execute 'addIceCandidate' on 'RTCPeerConnection': The ICE candidate could not be added. 我在浏览器控制台中遇到的错误(仅出现在chrome中,firefox中没有错误)是错误:无法在“ RTCPeerConnection”上执行“ addIceCandidate”:无法添加ICE候选者。

I followed a tutorial and was able to get p2p video chat to work using nodejs. 我遵循了一个教程,并且能够使用nodejs进行p2p视频聊天。 Now I am using Flask and python on the server side and angularjs on client side. 现在我在服务器端使用Flask和python,在客户端使用angularjs。

Signaling process for two peers is being done with angular-socketio. 两个对等节点的信令过程是通过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));
  }    
 }
});

Once two people join the room the startSignaling() method is called. 一旦两个人加入会议室,就会调用startSignaling()方法。 It sets the local description and completes 3 ice candidates then I receive an SDP but this is never true if(rtcPeerConn.remoteDescription.type === 'offer') even though it prints the SDP in the console with a type equal to offer. 它设置了本地描述并完成了3个ice候选对象,然后我收到了SDP,但是即使它在控制台中以等于提供的类型打印SDP,它也永远不会是if(rtcPeerConn.remoteDescription.type ==='offer') I am not sure why it never goes inside this if statement. 我不确定为什么它永远不会出现在if语句中。 I am not sure why I am getting an error. 我不确定为什么会出错。 If you have any questions just ask. 如果你有问题,就问吧。 Thanks for the help. 谢谢您的帮助。

I think 我认为

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

will not work because the constructor of RTCSessionDescription needs the information about the type and the sdp. 将不起作用,因为RTCSessionDescription的构造函数需要有关类型和sdp的信息。 Try: 尝试:

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

I had some issues constructing the RTCSessionDescription from JSON as well. 我也有一些从JSON构造RTCSessionDescription问题。 Hope this helps... 希望这可以帮助...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM