RTCCertificateStats

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

WebRTC API 中的 RTCCertificateStats 字典用於報告由 RTCDtlsTransport 及其底層 RTCIceTransport 使用的證書的資訊。

可以透過迭代 RTCPeerConnection.getStats() 返回的 RTCStatsReport 來獲取報告,直到找到一個 typecertificate 的條目。

例項屬性

fingerprint

一個包含證書指紋的字串,該指紋使用 fingerprintAlgorithm 中指定的雜湊函式進行計算。

fingerprintAlgorithm

一個包含用於計算證書 fingerprint 的雜湊函式的字串,例如 "sha-256"。

base64Certificate

包含 DER 編碼證書的 base-64 表示形式的字串。

常見例項屬性

以下屬性是所有 WebRTC 統計物件共有的(有關更多資訊,請參閱 RTCStatsReport)。

id

一個字串,唯一標識正在監控以生成這組統計資訊的物件。

時間戳

一個 DOMHighResTimeStamp 物件,表示此統計資訊物件樣本的採集時間。

type

一個值為 "certificate" 的字串,表示該物件包含的統計資訊的型別。

示例

給定一個變數 myPeerConnection,它是 RTCPeerConnection 的一個例項,下面的程式碼使用 await 等待統計報告,然後使用 RTCStatsReport.forEach() 進行迭代。然後,它過濾字典,只保留型別為 certificate 的報告,並記錄結果。

js
const stats = await myPeerConnection.getStats();

stats.forEach((report) => {
  if (report.type === "certificate") {
    // Log the certificate information
    console.log(report);
  }
});

規範

規範
WebRTC 統計 API 的識別符號
# dom-rtcstatstype-certificate

瀏覽器相容性

另見