title: Apprtc with coturn STUN/TURN server
body: <p>Simply, I am going run locally popular example of WEBRTC app:
  github.com/webrtc/apprtc</p>
  
  <p>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:"<a href="https://apprtc.appspot.com" rel="nofollow">https://apprtc.appspot.com</a>").</p>
  
  <p>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:</p>
  
  <p>code.google.com/p/coturn/ </p>
  
  <p>I am trying integrate my apprtc with coturn:</p>
  
  <pre><code> +apprtc: http://localhost:8080/?wstls=false
   +coturn: http://localhost: 3478
  </code></pre>
  
  <p>and I have questions:</p>
  
  <p>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</p>
  
  <p>which contains:</p>
  
  <pre><code>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 $@
  </code></pre>
  
  <p>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?</p>
  
  <p>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?</p>
  
  <p>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?</p>
  
  <p>d) Are some other important issues, which person running apprtc app and coturn server should know?</p>
  
  <p>edit</p>
  
  <hr>
  
  <p>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:</p>
  
  <pre><code>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,
                     ]
          })
  </code></pre>
  
  <p>Helpful will be groups:</p>
  
  <p><a href="https://groups.google.com/forum/#!forum/turn-server-project-rfc5766-turn-server" rel="nofollow">https://groups.google.com/forum/#!forum/turn-server-project-rfc5766-turn-server</a></p>
  
  <p><a href="https://groups.google.com/forum/#!forum/discuss-webrtc" rel="nofollow">https://groups.google.com/forum/#!forum/discuss-webrtc</a></p>
  
  <p>If sombody needs webrtc in django code, please write to me.</p>