我有一个基本的WebRTC应用程序,支持两个对等方之间的视频/音频通信和文件共享。当我在Mozilla Firefox上打开它时,应用程序按预期运行,但是当我在Google Chrome上运行它时,onicecandidate返回null。
我的RTCPeerConnection
myConnection = new RTCPeerConnection();
建立对等连接
myConnection.createOffer().then(offer => {
currentoffer = offer
myConnection.setLocalDescription(offer);
})
.then(function () {
myConnection.onicecandidate = function (event) {
console.log(event.candidate);
if (event.candidate) {
send({
type: "candidate",
candidate: event.candidate
});
}
};
send({
type: "offer",
offer: currentoffer
});
})
.catch(function (reason) {
alert("Problem with creating offer. " + reason);
});
在 Mozilla Firefox 中,您可以在控制台日志中查看每个“onicecandidate”事件收集的所有ICE候选项。
火狐输出如下图所示: 而在 Chrome 中,输出为 null。 Chrome 输出如下图所示: