RTCDataChannelStats
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
TheRTCDataChannelStats
dictionary of theWebRTC API provides statistics related to oneRTCDataChannel
object on the connection.
The report can be obtained by iterating theRTCStatsReport
returned byRTCPeerConnection.getStats()
until you find an entry with thetype
ofdata-channel
.
The data channels statistics may be correlated to a particular channel by comparing thedataChannelIdentifier
property to a matchingRTCDataChannel.id
.
Instance properties
bytesSent
OptionalA positive integer value indicating the total number of payload bytes sent on the associated
RTCDataChannel
.bytesReceived
OptionalA positive integer value indicating the total number of payload bytes received on the associated
RTCDataChannel
.dataChannelIdentifier
OptionalA positive integer value containing the
id
of the associatedRTCDataChannel
.label
OptionalA string containing the
label
of the associatedRTCDataChannel
.messagesReceived
OptionalA positive integer value indicating the total number of
message
events fired for received messages on the associatedRTCDataChannel
.messagesSent
OptionalA positive integer value indicating the total number of
message
events fired for sent messages on the channel.protocol
OptionalA string containing the
protocol
of the associatedRTCDataChannel
.state
The
readyState
of the associatedRTCDataChannel
.
Common instance properties
The following properties are common to all WebRTC statistics objects (SeeRTCStatsReport
for more information).
id
A string that uniquely identifies the object that is being monitored to produce this set of statistics.
timestamp
A
DOMHighResTimeStamp
object indicating the time at which the sample was taken for this statistics object.type
A string with the value
"data-channel"
, indicating the type of statistics that the object contains.
Examples
Given a variablemyPeerConnection
, which is an instance ofRTCPeerConnection
, the code below usesawait
to wait for the statistics report, and then iterates it usingRTCStatsReport.forEach()
.It then filters the dictionaries for just those reports that have the type ofdata-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
Specification |
---|
Identifiers for WebRTC's Statistics API # dom-rtcstatstype-data-channel |