addIceCandidate在Web RTC中不能很好地工作

时间:2016-03-22 02:12:47

标签: javascript webrtc

我已经接触过Web RTC,我必须在网络基础上制作视频聊天应用程序。 当我添加Ice候选者时,我收到了这个错误:

Uncaught SyntaxError: Failed to execute 'addIceCandidate' on 'RTCPeerConnection': The ICE candidate could not be added.

我试图找出它并且有人告诉我那里errors when ICE Candidates are received before answer is sent但是没有给出任何解决方案。 谁能帮助我解决它。 非常感谢你!

这是我的代码:

...

serverConnection.onmessage = gotMessageFromServer;

...

function gotMessageFromServer(message) {
if(!peerConnection) { 
        start(false);
    }

var signal = JSON.parse(message.data);
if(signal.ice) {
    peerConnection.addIceCandidate(new RTCIceCandidate(signal.ice));
} else if(signal.sdp) {
    peerConnection.setRemoteDescription(new RTCSessionDescription(signal.sdp), function() {
        peerConnection.createAnswer(gotDescription, createAnswerError);
    });
}

}

0 个答案:

没有答案