0

when local RTCDatachannel connected to remote RTCDatachannel, I wanna to konw the connection type: host/srflx/prflx/relay..

I try to parse the following string, but it's not the current one which is connected

RTCPeerConnection.localDescription.sdp
RTCPeerConnection.remoteDescription.sdp
RTCPeerConnection.currentLocalDescription.sdp
RTCPeerConnection.currentRemoteDescription.sdp

I can use chrome://webrtc-internals/ to see the connected candidate type

user558185
  • 291
  • 3
  • 2

1 Answers1

0

The getStats() API provides that information. In essence, you search for the transport stats, traverse to its selected candidate pair using selectedCandidatePairId and then can access the local and remote candidates and their respective types.

In practice it is a bit more complicated, in particular if you want to support Firefox as well. The code around https://github.com/webrtc/samples/blob/gh-pages/src/content/peerconnection/constraints/js/main.js#L229 provides a full sample.

Philipp Hancke
  • 15,855
  • 2
  • 23
  • 31
  • https://stackoverflow.com/questions/53133745/how-to-check-if-webrtc-peers-communicated-in-p2p-mode-or-relay-mode? only one "transport", yes? then use selectedCandidatePairId to find the pair, so i will get pair.localCandidateId and pair.remoteCandidateId, finally local-candidate and remote-candidate, they contain candidateType fields... yes? – user558185 Jul 01 '23 at 09:37
  • Yes. There can be more than one transport but only in cases where you actively do something (and typically not for datachannel-only connections). – Philipp Hancke Jul 03 '23 at 08:06