"use strict";

var crypto = require('crypto');
var Store = require( './lib/redis' );
var keys = require( './lib/keys' );

var SEP = keys.SEP;

function TURN_REST_API( conf ) {

	var store = new Store( { redis : conf.db } );

	function getTurn( username ) {
		var csk = store.getCurrentSharedKey();
		var hash = keys.genSharedKey( username, csk );

		/* Define expiration timestamp */
		var timestamp = Math.floor( Date.now() / 1000 ).toString();
		username = username ? timestamp + SEP + username : timestamp;

		var result = {
			username : username,
			password : hash,
			ttl      : 86400,
			uris     : conf.urls
		};

		return result;
	}

	this.getTurn = getTurn;

};

module.exports = TURN_REST_API;

@@ -136,16 +136,42 @@
 s.SEP;%0A%0A
+var DEFAULT_TTL = 86400;%0A%0A
 function
@@ -196,16 +196,53 @@
 nf ) %7B%0A%0A
+%09var ttl = conf.ttl %7C%7C DEFAULT_TTL;%0A%0A
 %09var sto
@@ -258,17 +258,19 @@
 Store( %7B
- 
+%0A%09%09
 redis : 
@@ -280,11 +280,26 @@
 f.db
- %7D 
+,%0A%09%09ttl   : ttl%0A%09%7D
 );%0A%0A
@@ -334,99 +334,8 @@
 ) %7B%0A
-%09%09var csk = store.getCurrentSharedKey();%0A%09%09var hash = keys.genSharedKey( username, csk );%0A%0A
 %09%09/*
@@ -493,16 +493,107 @@
 stamp;%0A%0A
+%09%09var csk = store.getCurrentSharedKey();%0A%09%09var hash = keys.genSharedKey( username, csk );%0A%0A
 %09%09var re
@@ -659,21 +659,19 @@
       : 
-86400
+ttl
 ,%0A%09%09%09uri

Add ttl from confs