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 特有的。
瀏覽器相容性
載入中…