RTCStatsReport: forEach() 方法
RTCStatsReport 介面的 forEach() 方法會按照插入順序,對 RTCStatsReport 物件中的每一對鍵/值執行一次提供的函式。
鍵是監視的統計物件(統計資料來源於這些物件)的唯一 id 值,而關聯的值是統計資訊字典物件。
該方法在其他方面與 Map.prototype.forEach() 相同。
語法
js
forEach(callbackFn)
forEach(callbackFn, thisArg)
引數
callbackFn-
一個函式,為報告中的每個條目執行。該函式將使用以下引數呼叫:
thisArg可選-
執行
callbackFn時用作this的值。
返回值
示例
給定一個變數 myPeerConnection,它是 RTCPeerConnection 的一個例項,程式碼呼叫 getStats() 並使用 await 等待統計報告。然後,它使用 RTCStatsReport.forEach() 迭代報告,並篩選出 type 為 inbound-rtp 且 kind 為 video 的字典。對於匹配的字典,它會記錄入站影片的 framesPerSecond 屬性。
js
const stats = await myPeerConnection.getStats();
stats.forEach((report) => {
if (report.type === "inbound-rtp" && report.kind === "video") {
// Log the frame rate
console.log(report.framesPerSecond);
}
});
規範
| 規範 |
|---|
| WebRTC:瀏覽器中的即時通訊 # dom-rtcstatsreport |
瀏覽器相容性
載入中…