Search code examples
javascriptwebrtc

How do you access RTCSctpTransportStats?


I was learning about the webrtc-stats API spec and was hoping to get the SCTP round trip time. It looks like that is a legitimate thing you should be able to do: https://www.w3.org/TR/webrtc-stats/#sctptransportstats-dict*

I have a pion backend which creates two dataChannels and sends them as part of its Session Description offer. I then answer with JS. Next I tried to get the RTCSctpTransport stats object like this:

  pc.oniceconnectionstatechange = e => {
    console.log(pc.iceConnectionState)
    if (pc.iceConnectionState == "connected"){
      // Start collecting SCTP smoothedRoundTripTime for showing user ping
      pc.getStats().then(statsReport => {
    
      statsReport.forEach((item, i) => {
        if(item.type == "sctp-transport"){
          console.log(item.smoothedRoundTripTime);
        }
      });
    }
  }

I never got any output from that so I next tried to just list all the items in statsReport which gave me this as well as some ICE candidates:

RTCDataChannel_73
RTCDataChannel_74
RTCPeerConnection
RTCTransport_0_1

How can I get the RTCSctpTransportStats?


Solution

  • These statistics are not implemented yet. https://bugs.chromium.org/p/webrtc/issues/detail?id=13216 is tracking the implementation for libwebrtc's new sctp stack which may end up exposing them.