gpt4 book ai didi

javascript - 得到答案后启动 `onicecandidate` 事件

转载 作者:行者123 更新时间:2023-11-30 19:40:48 26 4
gpt4 key购买 nike

我在 Chrome 浏览器中遇到了一个非常奇怪的 WebRTC 行为。我使用这样的简单代码:

peerConn.onicecandidate = function (event) {
if (event.candidate) {
let candidate = new RTCIceCandidate(event.candidate)
// Send the -candidate - to the remote peer
} else {
console.log('all candidates are set');
}
}

还有这个:

function obtainCandidatesFromSignalServer (){
console.log('obtain candidates ...');
peerConn.addIceCandidate(candidate);
}

我希望在节点 A 和节点 B 交换 offeranswer 之后调用该事件,但事实并非如此。当我刚从 A 向 B 发送 offer 时触发了 onicecandidate 事件,但直到对等 B 不发送 answer 时,obtainCandidatesFromSignalServer 函数将失败。那么,如何才能在 offer-answer exchange 之后调用 onicecandidate 函数呢?

最佳答案

I expect the event to be called after peer A and peer B exchange offer and answer, but this is not so.

这种期望是不正确的。 Trickle ICE 的全部意义在于加快协商速度,因此提议者候选者会立即追逐提议,反之,应答者候选者追逐答案。

换句话说,您将在信号 channel 上看到的一种方式是:

offer candidate candidate candidate

...反之亦然:

answer candidate candidate candidate

将它们视为对已发送描述的更新。事实上,如果您在发送 pc.localDescription 之前等待几秒钟,那么描述中将已经包含所有候选对象,您无需细化它们。 Trickle ICE 是一种优化,因为连接时间通常很关键。

关于javascript - 得到答案后启动 `onicecandidate` 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55421735/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com