Firefox中的WebRTC ICE候选人

时间:2014-08-25 14:35:28

标签: javascript google-chrome firefox webrtc rtcdatachannel

目前,我正在玩WebRTC。我的目标是在两个浏览器之间设置数据通道。 Chrome-Chrome运行良好。现在我正在使用Firefox-Firefox。这是我当前代码中的MEW:

var servers = { "iceServers": [{ "url": "stun:stun.l.google.com:19302" }] };
var RTCPeerConnection = window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
var SessionDescription = window.mozRTCSessionDescription || window.RTCSessionDescription;
var IceCandidate = window.mozRTCIceCandidate || window.RTCIceCandidate;

var peerConnection = new RTCPeerConnection(servers, { optional: [{ RtpDataChannels: true }] });
peerConnection.onicecandidate = function (event) {
    peerConnection.onicecandidate = null;
    console.log('ICE Candidate:', JSON.stringify(event.candidate))
};

var channel = peerConnection.createDataChannel("sendDataChannel", {reliable: false});

peerConnection.createOffer(
    function (offer) {
        peerConnection.setLocalDescription(offer);
    }, function (e) { }
);

一旦调用setLocalDescription,就会调用函数onicecandidate(如预期的那样)。在Chrome 36中,event.icecandidate类似于:

{"sdpMLineIndex":0,"sdpMid":"audio","candidate":"a=candidate:3430859439 1 udp 2122260223 xxx.xxx.xxx.xxx 59773 typ host generation 0\r\n"} 

在Firefox中,event.icecandidate只是null。但我需要通过信令通道发送ICE候选者以建立连接。

1 个答案:

答案 0 :(得分:1)

Chrome会触发onicecandidate事件,因为它支持“涓涓细流”。另一方面,Firefox不支持涓涓细流。如果您注意到Firefox生成的SDP,它应该已经包含必要的候选行。 null onicecandidate事件表示冰收集已完成(对于Chrome和Firefox),您可以将SDP发送给对等方。