RTCTransportStats
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
TheRTCTransportStats dictionary of theWebRTC API provides information about the transport (RTCDtlsTransport and its underlyingRTCIceTransport) used by a particular candidate pair.
TheBUNDLE 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, allMediaStreamTrack 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 theRTCPeerConnection constructor.
These statistics can be obtained by iterating theRTCStatsReport returned byRTCPeerConnection.getStats() until you find a report with thetype oftransport.
In this article
Instance properties
bytesReceivedOptionalThe total number of payload bytes received on this transport (bytes received, not including headers, padding or ICE connectivity checks).
bytesSentOptionalThe total number of payload bytes sent on this transport (bytes sent, not including headers, padding or ICE connectivity checks).
dtlsCipherOptionalA string indicating the name of the cipher suite used for the DTLS transport, such as
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256.dtlsRoleOptionalExperimentalA string indicating the DTLS role of the associated
RTCPeerConnection.This is one of:client,server,unknown(before the DTLS negotiation starts).dtlsStateA string indicating the current
stateof the underlyingRTCDtlsTransport.This is one of:new,connecting,connected,closed,failed.iceLocalUsernameFragmentOptionalExperimentalA string indicating the local username fragment that uniquely identifies the ICE interaction session managed by this transport.
iceRoleOptionalExperimentalA string indicating the ICE
roleof the underlyingRTCIceTransport.This is one of:controlled,controlling, orunknown.iceStateOptionalExperimentalA string indicating the current
stateof the underlyingRTCIceTransport.This is one of:new,checking,connected,completed,disconnected,failed, orclosed.localCertificateIdOptionalA string containing the id of the local certificate used by this transport.Only present for DTLS transports, and after DTLS has been negotiated.
packetsReceivedOptionalExperimentalThe total number of packets received on this transport.
packetsSentOptionalExperimentalThe total number of packets sent over this transport.
remoteCertificateIdOptionalA string containing the id or the remote certificate used by this transport.Only present for DTLS transports, and after DTLS has been negotiated.
selectedCandidatePairChangesOptionalThe 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.
selectedCandidatePairIdOptionalA string containing the unique identifier for the object that was inspected to produce the
RTCIceCandidatePairStatsassociated with this transport.srtpCipherOptionalA string indicating the descriptive name of the protection profile used for theSecure Real-time Transport Protocol (SRTP) transport.
tlsVersionOptionalA 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.
idA string that uniquely identifies the object that is being monitored to produce this set of statistics.
timestampA
DOMHighResTimeStampobject indicating the time at which the sample was taken for this statistics object.typeA 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, ornull if no statistics are provided.
The function waits for the result of a call toRTCPeerConnection.getStats() and then iterates the returnedRTCStatsReport to get just the stats of type"transport".It then returns the statistics, ornull, using the data in the report.
async function numberOpenConnections (peerConnection) { const stats = await peerConnection.getStats(); let transportStats = null; stats.forEach((report) => { if (report.type === "transport") { transportStats = report; break; } });return transportStats}Specifications
| Specification |
|---|
| Identifiers for WebRTC's Statistics API> # dom-rtcstatstype-transport> |