I have a webrtc application, it works fine, but for testing purposes, I need to test if my TURN server works, but because both the testing devices are within the same network, I am unable to test, thought below code would restrict candidates to only the ones using TURN server,
function onIceCandidate(event, targetSessionID, targetUserName) {
if (event.candidate) {
var candidate = event.candidate.candidate;
if(candidate.indexOf("relay")<0){ // if no relay address is found, assuming it means no TURN server
return;
}
sendMessage(candidate); // using socket.io to send to the otherside
...
but I noticed that( with much frustration), this does not work, because when peer is creating answer description,
....
a=candidate:0 1 UDP 2128609535 13.198.98.221 58779 typ host
a=candidate:0 2 UDP 2128609534 13.198.98.221 58780 typ host
....
this means, the communcation is direct and not through TURN server, am I correct in assuming this? Now, how do I force the webrtc to use the TURN server?
I have no idea if or when the browsers will support this but have a look at the "ICE candidate policy" in section 4.1.1 of draft-ietf-rtcweb-jsep-08, you can see how setting the policy to "relay" will do what you want. In the current W3C API draft this is set using an RTCIceTransportPolicy value of "relay" for the iceTranportPolicy field in the configuration. Search for RTCIceTransportPolicy in https://w3c.github.io/webrtc-pc/
relay: The ICE Agent uses only media relay candidates such as candidates passing through a TURN server.