我正在使用 Kurento Utils用于与 Kurento 媒体服务器(ver 5.x)的 WebRTC 连接
在初始化期间的 kurento-utils-js 库中,简化代码如下所示:
if (!this.pc) {
this.pc = new RTCPeerConnection(server, options);
}
var ended = false;
pc.onicecandidate = function(e) {
// candidate exists in e.candidate
if (e.candidate) {
ended = false;
return;
}
if (ended) {
return;
}
var offerSdp = pc.localDescription.sdp;
console.log('ICE negotiation completed');
self.onsdpoffer(offerSdp, self);
ended = true;
};
我的问题是它似乎在等待 onicecandidate
传递“null”值,这表示流程已经结束,因此能够继续创建 SDP 报价,但我找不到这种行为在 WebRTC 规范中?
我的下一个问题是,我们还能如何知道寻找 ice candidates 的过程已经结束?
我办公室的一台 PC 无法访问代码 console.log('ICE negotiation completed');
因为没有传递 null 值。
最佳答案
您可以检查 iceGatheringState 属性(在 chrome 中运行):
var config = {'iceServers': [{ url: 'stun:stun.l.google.com:19302' }] };
var pc = new webkitRTCPeerConnection(config);
pc.onicecandidate = function(event) {
if (event && event.target && event.target.iceGatheringState === 'complete') {
alert('done gathering candidates - got iceGatheringState complete');
} else if (event && event.candidate == null) {
alert('done gathering candidates - got null candidate');
} else {
console.log(event.target.iceGatheringState, event);
}
};
pc.createOffer(function(offer) {
pc.setLocalDescription(offer);
}, function(err) {
console.log(err);
}, {'mandatory': {'OfferToReceiveAudio': true}});
window.pc = pc;
https://stackoverflow.com/questions/31784602/