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

RTCTransportStats

· 52CE 我爱测

The **`RTCTransportStats`** dictionary of the WebRTC API provides information about the transport (RTCDtlsTransport and its underlying RTCIceTransport) used by a particular candidate pair.

WebRTC

The RTCTransportStats dictionary of the WebRTC API provides information about the transport (RTCDtlsTransport and its underlying RTCIceTransport) used by a particular candidate pair.

The BUNDLE feature is an SDP extension that allows negotiation to use a single transport for sending and receiving media described by multiple SDP media descriptions. If the remote endpoint is aware of this feature, all MediaStreamTrack and data channels are bundled onto a single transport at the completion of negotiation. This is true for current browsers, but if connecting to an older endpoint that is not BUNDLE-aware, then separate transports might be used for different media. The policy to use in the negotiation is configured in the RTCPeerConnection constructor.

These statistics can be obtained by iterating the RTCStatsReport returned by RTCPeerConnection.getStats() until you find a report with the type of transport.

Instance properties

  • RTCTransportStats.bytesReceived
    • : The total number of payload bytes received on this transport (bytes received, not including headers, padding or ICE connectivity checks).
  • RTCTransportStats.bytesSent
    • : The total number of payload bytes sent on this transport (bytes sent, not including headers, padding or ICE connectivity checks).
  • RTCTransportStats.dtlsCipher
    • : A string indicating the name of the cipher suite used for the DTLS transport, such as TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256.
  • RTCTransportStats.dtlsRole
    • : A string indicating the DTLS role of the associated RTCPeerConnection. This is one of: client, server, unknown (before the DTLS negotiation starts).
  • RTCTransportStats.dtlsState
    • : A string indicating the current RTCDtlsTransport.state of the underlying RTCDtlsTransport. This is one of: new, connecting, connected, closed, failed.
  • RTCTransportStats.iceLocalUsernameFragment
    • : A string indicating the local username fragment that uniquely identifies the ICE interaction session managed by this transport.
  • RTCTransportStats.iceRole
    • : A string indicating the ICE role of the underlying RTCIceTransport. This is one of: controlled, controlling, or unknown.
  • RTCTransportStats.iceState
    • : A string indicating the current RTCIceTransport.state of the underlying RTCIceTransport. This is one of: new, checking, connected, completed, disconnected, failed, or closed.
  • RTCTransportStats.localCertificateId
    • : A string containing the id of the local certificate used by this transport. Only present for DTLS transports, and after DTLS has been negotiated.
  • RTCTransportStats.packetsReceived
    • : The total number of packets received on this transport.
  • RTCTransportStats.packetsSent
    • : The total number of packets sent over this transport.
  • RTCTransportStats.remoteCertificateId
    • : A string containing the id or the remote certificate used by this transport. Only present for DTLS transports, and after DTLS has been negotiated.
  • RTCTransportStats.selectedCandidatePairChanges
    • : The number of times that the selected candidate pair of this transport has changed. The value is initially zero and increases whenever a candidate pair selected or lost.
  • RTCTransportStats.selectedCandidatePairId
    • : A string containing the unique identifier for the object that was inspected to produce the RTCIceCandidatePairStats associated with this transport.
  • RTCTransportStats.srtpCipher
  • RTCTransportStats.tlsVersion
    • : A string containing the negotiated TLS version. This is present for DTLS transports, and only exists after DTLS has been negotiated.

Common instance properties

The following properties are common to all WebRTC statistics objects.

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

Examples

This example shows a function to return the transport statistics, or null if no statistics are provided.

The function waits for the result of a call to RTCPeerConnection.getStats() and then iterates the returned RTCStatsReport to get just the stats of type "transport". It then returns the statistics, or null, using the data in the report.

async function getTransportStats(peerConnection) {
  const stats = await peerConnection.getStats();

  for (const report of stats.values()) {
    if (report.type === "transport") {
      return report;
    }
  }

  return null;
}

Specifications

Browser compatibility

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

资料来源与适用范围

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

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

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