RTCPeerConnection.addIceCandidate() - 未捕获的SyntaxError:指定了无效或非法的字符串

时间:2014-04-20 13:31:58

标签: javascript webrtc

addIceCandidate()函数给出了帖子标题中的错误,“Uncaught SyntaxError:指定了无效或非法的字符串。”

我传递的参数显然是一个RTCIceCandidate对象。我可以打印出candidate - 属性结果,其中一些看起来像a=candidate:1086438664 2 udp 41754367 41.117.144.193 64564 typ relay raddr 82.146.26.23 rport 58089 generation 0,依此类推。

这是我传递参数的函数:

function receiveIceCandidate(candidate)
{
    parseCandidate = new RTCIceCandidate(JSON.parse(candidate));
    //console.log("parseCandidate.cand = " + parseCandidate.candidate);
    remotePc.addIceCandidate(parseCandidate);
    //remotePc is an RTCPeerConnection
}

在调用此函数之前,remotePc会在以下函数中接收SDP商品并将其设置为RemoteDescription:

function receiveOffer(offer)
{   
    var isChrome = !!navigator.webkitGetUserMedia;
    var STUN = {
    url: isChrome
        ? 'stun:stun.l.google.com:19302'
        : 'stun:23.21.150.121'
    };

    var TURN = {
        url: 'turn:homeo@turn.bistri.com:80',
        credential: 'homeo'
    };

    var iceServers = 
    {
        iceServers: [STUN, TURN]
    };

    var sdpConstraints = {
    optional: [],
    mandatory: {
        OfferToReceiveAudio: true,
        OfferToReceiveVideo: true
        }
    };

    pc_config = {"iceServers": [{"url": "stun:stun.l.google.com:19302"}]};

    remotePc = newPeerConnection(iceServers); // This returns a PeerConnection with suitable prefix for the browser
    remotePc.setRemoteDescription(new RTCSessionDescription(offer.sdp ));   

    remotePc.createAnswer(function(answer) 
    { 
        console.log("creating answer.");
        remotePc.setLocalDescription(answer);
    });

    remotePc.onaddstream = function (evt) 
    { 
        console.log("on add stream..");
        var remote_video = $("#remoteVideo");
        remote_video.src = createObjectURL(evt.stream);     
    }
}
到目前为止,{p> onaddstreamcreateAnswer实际上从未被调用过 - 这可能与问题有关吗?如果没有ICECandidates,我认为没有机会回答?

0 个答案:

没有答案