大网数据广告活动
Web 标准与前端开发

RTCDataChannelStats

· 52CE 我爱测

The **`RTCDataChannelStats`** dictionary of the WebRTC API provides statistics related to one RTCDataChannel object on the connection.

WebRTC

The RTCDataChannelStats dictionary of the WebRTC API provides statistics related to one RTCDataChannel object on the connection.

The report can be obtained by iterating the RTCStatsReport returned by RTCPeerConnection.getStats() until you find an entry with the type of data-channel.

The data channels statistics may be correlated to a particular channel by comparing the dataChannelIdentifier property to a matching RTCDataChannel.id.

Instance properties

  • RTCDataChannelStats.bytesSent
    • : A positive integer value indicating the total number of payload bytes sent on the associated RTCDataChannel.
  • RTCDataChannelStats.bytesReceived
    • : A positive integer value indicating the total number of payload bytes received on the associated RTCDataChannel.
  • RTCDataChannelStats.dataChannelIdentifier
    • : A positive integer value containing the RTCDataChannel.id of the associated RTCDataChannel.
  • RTCDataChannelStats.label
    • : A string containing the RTCDataChannel.label of the associated RTCDataChannel.
  • RTCDataChannelStats.messagesReceived
    • : A positive integer value indicating the total number of message events fired for received messages on the associated RTCDataChannel.
  • RTCDataChannelStats.messagesSent
    • : A positive integer value indicating the total number of message events fired for sent messages on the channel.
  • RTCDataChannelStats.protocol
    • : A string containing the RTCDataChannel.protocol of the associated RTCDataChannel.
  • RTCDataChannelStats.state
    • : The RTCDataChannel.readyState of the associated RTCDataChannel.

Common instance properties

The following properties are common to all WebRTC statistics objects (See RTCStatsReport for more information).

  • RTCDataChannelStats.id
    • : A string that uniquely identifies the object that is being monitored to produce this set of statistics.
  • RTCDataChannelStats.timestamp
    • : A DOMHighResTimeStamp object indicating the time at which the sample was taken for this statistics object.
  • RTCDataChannelStats.type
    • : A string with the value "data-channel", indicating the type of statistics that the object contains.

Examples

Given a variable myPeerConnection, which is an instance of RTCPeerConnection, the code below uses await to wait for the statistics report, and then iterates it using RTCStatsReport.forEach(). It then filters the dictionaries for just those reports that have the type of data-channel and logs the result.

const stats = await myPeerConnection.getStats();

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

Specifications

Browser compatibility

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。