RTCIceCandidatePairStats: selected 属性
非标准:此特性未标准化。我们不建议在生产环境中使用非标准特性,因为它们浏览器支持有限,并且可能会更改或被移除。但是,在没有标准选项的特定情况下,它们可以是合适的替代方案。
RTCIceCandidatePairStats 字典中的 selected 属性指示由该对象描述的候选对是否是当前用于与远程对等方通信的候选对。
此属性不是标准的,仅受 Firefox 支持。确定选定的候选对的标准方法是查看类型为 transport 的统计信息对象的 selectedCandidatePairId 属性。
值
如果此对象描述的候选对是当前正在使用的候选对,则为 true,否则为 false。
示例
此示例中显示的函数通过首先迭代每个报告来查找当前选定的候选对,查找 transport 报告。找到后,将使用该传输的 selectedCandidatePairId 来获取描述连接的 RTCIceCandidatePair。
如果失败,则第二部分将迭代报告,查找 Firefox 特有的 selected 属性为 true 的 candidate-pair 记录。然后将此候选对作为当前选定的候选对返回。
js
function getCurrentCandidatePair(statsResults) {
statsResults.forEach((report) => {
if (report.type === "transport") {
currentPair = statsResults.get(report.selectedCandidatePairId);
}
});
if (!currentPair) {
statsResults.forEach((report) => {
if (report.type === "candidate-pair" && report.selected) {
currentPair = report;
}
});
}
return currentPair;
}
规范
不属于任何规范。此属性是 Firefox 特有的。
浏览器兼容性
加载中…