GeezerVison is showing developer.mozilla.org — RTCDataChannelStats - Web APIs | MDN
RTCDataChannelStats
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
bytesSent Optional
-
A positive integer value indicating the total number of payload bytes sent on the associated RTCDataChannel.
bytesReceived Optional
-
A positive integer value indicating the total number of payload bytes received on the associated RTCDataChannel.
dataChannelIdentifier Optional
-
A positive integer value containing the id of the associated RTCDataChannel.
label Optional
-
A string containing the label of the associated RTCDataChannel.
messagesReceived Optional
-
A positive integer value indicating the total number of message events fired for received messages on the associated RTCDataChannel.
messagesSent Optional
-
A positive integer value indicating the total number of message events fired for sent messages on the channel.
protocol Optional
-
A string containing the protocol of the associated RTCDataChannel.
state
-
The readyState of the associated RTCDataChannel.
The following properties are common to all WebRTC statistics objects (See RTCStatsReport 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.
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.
js
const stats = await myPeerConnection.getStats();
stats.forEach((report) => {
if (report.type === "data-channel") {
// Log the channel information
console.log(report);
}
});