webrtc - 我们怎么知道 webRTC 何时已经完成收集 ICE 候选人

我正在使用 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/

相关文章:

asp.net - ResponseMode ="File"不工作

cordova - 地理位置总是在 cordova 应用程序中超时

php - 学说 : Set CURRENT_TIMESTAMP as default value

git - 为什么 git clone 有时创建一个 .git 目录,有时不创建?

python - 如果在 Python 中出现异常重试

javascript - 检查字符串的第一个字符是否为数字会报错,表明 charat 不是有效方法

xml - Odoo:如何继承菜单项(使菜单项不可见)

php - Laravel 5.1 如何检查目录中是否存在文件?

Java - 编译器错误地解析 unicode 源文件

sql - 如何用 SQL 删除 Oracle 数据库中的所有数据?