Javascript在冰候选人上返回undefined

时间:2016-04-18 17:44:42

标签: javascript socket.io webrtc

我正在尝试实现webRTC,在添加一些Ice候选者后,我收到此错误:错误:无法在'RTCPeerConnection'上执行'addIceCandidate':无法添加ICE候选

同样在控制台中,undefined正在打印出来。 这是我的代码。你看到我的webrtc实现有什么问题,或者是什么导致了这个错误,未定义的是在控制台中打印出来的?感谢

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));
  }    
 }  
});

function logError(error) {
       displayMessage(error.name + ': ' + error.message);
}

0 个答案:

没有答案