user8380672
user8380672

Reputation: 710

How to determine if TURN server is being used (WebRTC)?

I want to gather stats on the number of users having to fallback to TURN servers. Thus is there a way to find if a RTCPeerConnection is using a TURN server instead of "directly" communicating with a remote peer?

I've tried using pc.getStats() but that only gives me an object with a size property.

Upvotes: 4

Views: 1184

Answers (2)

Philipp Hancke
Philipp Hancke

Reputation: 17305

the getStats() result is a Javascript Map object. You can iterate it to find what you need. To get the active candidate pair (and then determine its type) it is best to follow the code from this sample (which works around the quirks of some browsers) and then check whether either the local or remote candidateType is 'relay'.

Upvotes: 0

Sean DuBois
Sean DuBois

Reputation: 4242

You want to use getSelectedCandidatePair. This will return the local/remote candidate that is being used. Each candidate will have a type host, srflx, prflx or relay. relay means it is using TURN.

Make sure to check both candidates. It is possible that both pairs are TURN (or maybe just one)

Upvotes: 4

Related Questions