【发布时间】: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