1

At the moment, I am playing around with WebRTC. My goal is to setup a datachannel between two browsers. Chrome-Chrome is working well. Now I am playing with Firefox-Firefox. Here is a MEW from my current code:

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

As soon setLocalDescription is called, the function onicecandidate is called (as expected). In Chrome 36 the event.icecandidate is something like:

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

In Firefox the event.icecandidate is just null. But I need to send that ICE candidate over the signaling channel to establish the connection.

4

1 回答 1

2

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

于 2014-08-25T15:38:19.583 回答