【问题标题】:WebRTC ICE candidate in FirefoxFirefox 中的 WebRTC ICE 候选
【发布时间】:2014-10-18 17:53:50
【问题描述】:

目前,我正在使用 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 候选来建立连接。

【问题讨论】:

    标签: javascript google-chrome firefox webrtc rtcdatachannel


    【解决方案1】:

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

    【讨论】:

    • 感谢您的回复。我意识到,对于 Chrome-Chrome 连接,我需要 SDP 和 ICE 候选者。对于 Firefox-Firefox 连接仅 SDP;所以两者都运作良好。我没有在 Firefox 和 Chrome 之间获得 DataChannel。你知道这是否可能吗?这是我的整个测试应用程序:boldt.github.io/webrtc/two-tabs
    猜你喜欢
    • 2016-08-08
    • 2015-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多