Medialooks Knowledge Base Support Center

Contact Us

TURN server deployment and usage

The TURN server is a part of WebRTC environment that transmits media traffic between peers if a direct peer-to-peer connection is not available (for example due to firewall restrictions). 

When should I have it? 

- When you want to transmit WebRTC streams between any random points of the internet or have no information about the transmission routes.  

- When your WebRTC transmission is critical and the content should be delivered at any cost.

Deployment

There are a lot of TURN server installation packages. We have used a TurnServer from the SourceForge, but it's not a mandatory. You can use any other TURN server in your environment. 

To deploy the TurnServer you need to: 

  1. Download it from the SourceForge.
  2. Install it following the instructions.

Usage

To use a TURN server you should specify the address and password by "turn_server" and "turn_password" MWebRTC object properties.

Here is a syntax example: 

"old" style TURN configuration - was stayed for backward compatibility, you can use it if you are using only one TURN server or in the case when each of your TURN servers has the equal user and password.

turn_server = turn:custom.turn.server1:1234;turn:custom.turn.server2:1234 
turn_password = password1 

Where:
"turn" - service keyword
"user1" - the username
"turn:custom.turn.server1:1234" - turn server1 address and port
";" - sparating character for turn server1 and turn server2
"turn:custom.turn.server2:1234" - turn server 2 address and port
"password1" - password


"new" JSON style TURN configuration - was added with ability to use more than one TURN server,  unlike "old" style string configuration you are able to set different users and passwords for TURN servers

[{"username": "User1","credential": "Password1","urls": ["turn:custom.turn.server1:1234"]},{"username": "User2","credential": "Password2","urls": ["turn:custom.turn.server2:1234"]}]
HKEY_CURRENT_USER\Software\Medialooks\WebRTC 
turn_server = turn:custom.turn.server1:1234;turn:custom.turn.server2:1234 
turn_password = password1

 Please note register configuration working only for a desktop application, it will not set TURN server for your web pages, for web pages you should use iceServers SimpleWebRTC object field or signaling server configuration files.

          

..\SIGNALING SERVER\config\development.json
..\SIGNALING SERVER\config\production.json

-For desktop application using an "old" style TURN or JSON configuration strings

        a) Via "old" style TURN configuration string

PropsSet("stun_server", "stun:stun.l.google.com:19302;stun:custom.stun.server:12345");
PropsSet("turn_server", "turn:custom.turn.server1:1234;turn:custom.turn.server2:1234");
PropsSet("turn_user", "User1");
PropsSet("turn_password", "Password1");

           Please note in current case turn_user and turn_password should be equal for each turn_server.

        b) Via JSON string - this will give you the opportunity to set different users and passwords for each server.

PropsSet("stun_server", "[{"url": "stun:stun.l.google.com:19302"},{"url": "stun:custom.stun.server:12345"}] ");
PropsSet("turn_server", "[{"username": "User1","credential": "Password1","urls": ["turn:custom.turn.server1:1234"]},{"username": "User2","credential": "Password2","urls": ["turn:custom.turn.server2:1234"]}]");

-For Web pages

          Stun/Turn configuration available via iceServers

var webrtc = new SimpleWebRTC({
target: targetId,
url: signalingServer,
iceServers: [{url: "stun:stun.l.google.com:19302"},{url: "stun:custom.stun.server:12345"},{username: "User1", credential: "Password1", urls: ["turn:custom.turn.server1:1234"]}, {username: "User2", credential: "Password2", urls: ["turn:custom.turn.server2:1234"]}],
localVideoEl: ,
remoteVideosEl: ,
autoRequestMedia: false,
debug: false,
detectSpeakingEvents: true,
autoAdjustMic: false
});


Important!

TURN server consumes a lot of traffic and calculation power because it has to transmit the media content between the peers. Make sure that you have a powerful hardware and wide traffic bandwidth to manage this task.