Search code examples
androidwebrtcwebrtc-android

Determine if TURN is used from webrtc getStats api data


I am using WebRTC getStats() API on android to get stats and I am getting most of the data which I need. But I can't find data to determine if TURN used or not.

Please check the sample json data. https://pastebin.com/v89aaL2H

private void getStats() {
if (peerConnection == null || isError) {
    return;
}
boolean success = peerConnection.getStats(reports -> events.onPeerConnectionStatsReady(reports), null);
}

Solution

  • It seems you are using legacy stats. So, let me answer your question based on legacy stats -

    In your legacy stats, googCandidatePair list represent the ICE candidate pairs ( a pairing of a local and a remote ICE candidate ) for your current WebRTC session. If you look into the googCandidatePair list you will find the candidate pairs that is currently being used by a transport (googCandidatePair.googActiveConnection will be true in that case ).

    Now you can look into the local and remote candidate type ( googLocalCandidateType, and googRemoteCandidateType ) of this active googCandidatePair to know what exactly you are using for your transport.

    For example, from the sample stats dump - you are using stun only.

    Note: You might also be interested in reading Chrome Standard getStats() Migration Guide