Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

RTCPeerConnectionStats

Baseline2023
Newly available

TheRTCPeerConnectionStats dictionary of theWebRTC API provides information about the high level peer connection (RTCPeerConnection).

In particular, it provides the number of unique data channels that have been opened, and the number of opened channels that have been closed.This allows the current number of open channels to be calculated.

These statistics can be obtained by iterating theRTCStatsReport returned byRTCPeerConnection.getStats() until you find a report with thetype ofpeer-connection.

Instance properties

dataChannelsOpened

A positive integer value indicating the number of uniqueRTCDataChannel objects that have entered theopen state during their lifetime.

dataChannelsClosed

A positive integer value indicating the number of uniqueRTCDataChannel objects that have left theopen state during their lifetime (channels that transition toclosing orclosed without ever beingopen are not counted in this number).A channel will leave theopen state if either end of the connection or the underlying transport is closed.

Common instance properties

The following properties are common to all WebRTC statistics objects.

id

A string that uniquely identifies the object that is being monitored to produce this set of statistics.

timestamp

ADOMHighResTimeStamp object indicating the time at which the sample was taken for this statistics object.

type

A string with the value"peer-connection", indicating the type of statistics that the object contains.

Examples

This example shows a function to return the total number of open connections, ornull if no statistics are provided.This might be called in a loop, similar to the approach used inRTCPeerConnection.getStats() example

The function waits for the result of a call toRTCPeerConnection.getStats() and then iterates the returnedRTCStatsReport to get just the stats of type"peer-connection".It then returns the total number of open channels, ornull, using the data in the report.

js
async function numberOpenConnections (peerConnection) {  const stats = await peerConnection.getStats();  let peerConnectionStats = null;  stats.forEach((report) => {    if (report.type === "peer-connection") {      peerConnectionStats = report;      break;    }  });result = (typeof peerConnectionStats.dataChannelsOpened === 'undefined' || typeof peerConnectionStats.dataChannelsClosed=== 'undefined') ? null : peerConnectionStats.dataChannelsOpened - peerConnectionStats.dataChannelsClosed;return result}

Specifications

Specification
Identifiers for WebRTC's Statistics API
# dom-rtcstatstype-peer-connection

Browser compatibility

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp