【问题标题】:How do we know when webRTC already finished collecting ICE candidates我们如何知道 webRTC 何时已经完成了 ICE 候选人的收集
【发布时间】:2015-08-03 10:05:02
【问题描述】:

我正在使用Kurento Utils 与 Kurento 媒体服务器(版本 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 规范中找不到这种行为?

我的下一个问题是,我们如何才能知道寻找候选冰的过程已经结束?

我办公室的一台 PC 无法访问代码 console.log('ICE negotiation completed');,因为未传递 null 值。

【问题讨论】:

  • 哪些设置没有完成?我们已经使用该库一年多了,以前从未见过。无论如何,KMS6 使用 Trickle ICE,所以也许升级比尝试修复它更好。

标签: webrtc kurento


【解决方案1】:

您可以检查 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;

【讨论】:

  • 我认为在 FF 中这不是很可靠,至少在某些版本之前。
【解决方案2】:

http://www.w3.org/TR/webrtc/

4.3.1

" 如果 ICE 代理的意图是通知脚本:

[...]

  • 收集过程完成。

设置连接的结冰状态为完成,并让newCandidate为空。"

因此,您可以根据“已完成”(在现实生活中,这不是很可靠)检查冰收集状态,或者等待空候选(超级可靠)。

【讨论】:

  • 那个图书馆正在等待一个空候选人,所以奇怪的是它没有得到那个候选人......
猜你喜欢
  • 2015-12-17
  • 1970-01-01
  • 1970-01-01
  • 2014-01-03
  • 2014-10-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多