Search code examples
angularjswebrtcstunturnsimplewebrtc

WebRTC and authentication implementations


Ok so recently I have been in need of creating a application with WebRTC for video voice etc.

So after looking into some libraries I found SimpleWebRTC to be pretty handly looking: https://github.com/andyet/SimpleWebRTC

So what I am interested in is how do I implement a STUN/TURN server? (Would be great if someone could explain the differences in plain English!) And also is there a authentication mechanism. At the moment my app contacts my database and logins in user etc, but the stun and turn server would be private and not in any way involved in the authentication procedure.

So basically:

  • What is the best way to implement STUN/TURN
  • Is there any authentication mechanism?

Note, this is for a hybrid app so I will be using JavaScript/AngularJS for this. The main reason why I chose SimpleWebRTC.

Thank you!


Solution

  • I suggest you use an existing STUN or TURN server like coturn.

    STUN servers are very lightweight and often left without authentication. A STUN server basically tells a client what its IP address appears to be, which is necessary to make peer connections across NAT (network address translation) boundaries.

    TURN servers are very resource intensive because they relay media; all of the media for a call can go through the TURN server, so it's important to secure TURN. You use TURN servers in situations where UDP may be blocked, or for particular kinds of NATs that cause problems.

    The authentication for coturn's TURN server can take one of two forms:

    1. Simple (username, password) pair
    2. TURN REST API. This uses a secret between the TURN server and another entity. The entity issues tokens with expiration times, and the TURN server verifies the token has not expired and was issued with knowledge of the shared secret. This is passed by the TURN client as a username, password pair in a format described in the documentation.