Apprtc with coturn STUN/TURN server

3.8k views Asked by At

Simply, I am going run locally popular example of WEBRTC app: github.com/webrtc/apprtc

The apprtc installed, and even works locally without turn server ( "Same origin policy" don't allow use Google TURN server, which works only from apprtc.appspot.com: access-control-allow-origin:"https://apprtc.appspot.com").

But I know that in real internet world (nats and firewalls) I need turn server. So I have decided to use own STUN/TURN server:

code.google.com/p/coturn/

I am trying integrate my apprtc with coturn:

 +apprtc: http://localhost:8080/?wstls=false
 +coturn: http://localhost: 3478

and I have questions:

a) Do I need execute some turnadmin commands, which are described in INSTALL guide? Or it will be enaugh to run turnserver from example: my_name@my_machine:~/WEBRTC/turnserver-4.4.5.2/examples/scripts/restapi$ ./secure_relay_secret.sh

which contains:

if [ -d examples ] ; then
       cd examples
fi

export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib/:/usr/local/mysql/lib/
export DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}:/usr/local/lib/:/usr/local/mysql/lib/

PATH="./bin/:../bin/:../../bin/:${PATH}" turnserver -v --syslog -a -L 127.0.0.1 -L ::1 -E 127.0.0.1 -E ::1 --max-bps=3000000 -f -m 3 --min-port=32355 --max-port=65535 --use-auth-secret --static-auth-secret=logen --realm=north.gov --cert=turn_server_cert.pem --pkey=turn_server_pkey.pem --log-file=stdout -q 100 -Q 300 --cipher-list=ALL $@

b) When I open localhost: 3478 in browser I see: "TURN Server use https connection for the admin session: What uri is for rest API?

c) In rest API I need pass some parameters: username and key. Is it enough? Will be enough to simply add extra -u switch to turnserver command? Need I some extra configurations?

e) How solve "Same origin policy"? I am not going experiment with the same ports and nginx, but simply set "access-control-allow-origin" header to turnserver response. How do it without nginx proxy? Or maby some others solutions?

d) Are some other important issues, which person running apprtc app and coturn server should know?

edit


For me the most problem was thinking that Coturn has own api method which return TURN servers - but has not. So it is requird to do it myself - on own http server. Below is example in python/django:

from hashlib import sha1
import hmac

TURN_SERVER_SECRET_KEY = 'my_pass'
def get_turn_servers(request):
    if 'username' not in request.GET.keys():
        return HttpResponseForbidden()

    unix_timestamp_tomorrow = int(time()) + (24*60*60)
    new_username = str(unix_timestamp_tomorrow)+':'+request.GET['username']
    hashed = hmac.new(TURN_SERVER_SECRET_KEY, new_username, sha1)
    password = hashed.digest().encode("base64").rstrip('\n')

    turn_udp_uri = 'turn:%s:3478?transport=udp' % settings.DOMAIN.split(':')[0] #bez portu
    turn_tcp_uri = 'turn:%s:3478?transport=tcp' % settings.DOMAIN.split(':')[0]

    return JsonResponse({
            'username':new_username,
            'password':password,
            'uris':[turn_udp_uri,
                    turn_tcp_uri,
                   ]
        })

Helpful will be groups:

https://groups.google.com/forum/#!forum/turn-server-project-rfc5766-turn-server

https://groups.google.com/forum/#!forum/discuss-webrtc

If sombody needs webrtc in django code, please write to me.

0

There are 0 answers