RTCIceCandidateStats: deleted 屬性

RTCIceCandidateStats 字典的 deleted 屬性指示該候選者是否已被刪除或釋放。

一個布林值,指示該候選者是否已被刪除或釋放。如果此值為 true,則 RTCIceCandidateStats 物件描述的候選者不再被考慮。確切的含義取決於候選者的型別

本地候選者

值為 true 表示根據 RFC 5245, Section 8.3 的描述,該候選者已被刪除。

主機候選者

值為 true 表示該候選者的網路資源已釋放。這通常意味著任何關聯的套接字已關閉並釋放。

遠端 (TURN) 候選者

值為 true 表示該候選者的 TURN 分配已不再啟用。

最終結果是相同的;如果此值為 true,則該候選者不再被考慮。

示例

在此示例中,使用 setInterval() 設定一個定期執行的函式來顯示候選者的最新統計資訊。輸出僅包含尚未被刪除的候選者。

js
setInterval(() => {
  myPeerConnection.getStats(null).then((stats) => {
    let statsOutput = "";

    stats.forEach((report) => {
      if (
        (stats.type === "local-candidate" ||
          stats.type === "remote.candidate") &&
        !stats.deleted
      ) {
        statsOutput +=
          `<h2>Report: ${report.type}</h3>\n<strong>ID:</strong> ${report.id}<br>\n` +
          `<strong>Timestamp:</strong> ${report.timestamp}<br>\n`;

        // Now the statistics for this report; we intentionally drop the ones we
        // sorted to the top above
        Object.keys(report).forEach((statName) => {
          if (
            statName !== "id" &&
            statName !== "timestamp" &&
            statName !== "type"
          ) {
            statsOutput += `<strong>${statName}:</strong> ${report[statName]}<br>\n`;
          }
        });
      }
    });

    document.querySelector(".stats-box").innerHTML = statsOutput;
  });
}, 1000);

規範

此特性似乎未在任何規範中定義。

瀏覽器相容性