Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebRTC: force peers to use TURN server

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?

like image 989
mido Avatar asked Dec 01 '14 08:12

mido


People also ask

Does WebRTC need TURN server?

For most WebRTC applications to function a server is required for relaying the traffic between peers, since a direct socket is often not possible between the clients (unless they reside on the same local network). The common way to solve this is by using a TURN server.

What is peer reflexive candidate?

A peer reflexive candidate is one whose IP address comes from a symmetric NAT between the two peers, usually as an additional candidate during trickle ICE (that is, additional candidate exchanges that occur after primary signaling but before the connection verification phase is finished).

What is ice candidate in WebRTC?

An ICE candidate describes the protocols and routing needed for WebRTC to be able to communicate with a remote device.


1 Answers

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/

like image 82
Cullen Fluffy Jennings Avatar answered Oct 08 '22 21:10

Cullen Fluffy Jennings