diff --git a/index.html b/index.html
index 44f5074..616d844 100644
--- a/index.html
+++ b/index.html
@@ -1577,6 +1577,9 @@
// turn.urls = ["turn:turn2.obs.ninja:443"]; // US WEST
// session.configuration.iceServers.push(turn);
+ // session.turn-mode == "twilio" // uncomment to use credentials for the turn-server provided by Twilio
+ // session.turn-mode = "php-credentials" // uncomment to distribute the turn-username, -password and -server via running turn-credentials.php, e.g., if you have a turn-server with a static-auth-secret
+
// session.configuration.iceTransportPolicy = "relay"; // uncomment to enable "&privacy" and force the TURN server
///// Different endpoints are available; each isolated from each other.
diff --git a/main.js b/main.js
index 3e24749..23c5d24 100644
--- a/main.js
+++ b/main.js
@@ -2474,7 +2474,7 @@ if (urlParams.has('speedtest')){ // forces essentially UDP mode, unless TCP is s
if (urlParams.has('turn')) {
var turnstring = urlParams.get('turn');
- if (turnstring == "twilio") { // a sample function on loading remote credentials for TURN servers.
+ if (turnstring == "twilio" || session.turn-mode == "twilio") { // a sample function on loading remote credentials for TURN servers.
try {
session.ws = false; // prevents connection
@@ -2515,6 +2515,45 @@ if (urlParams.has('turn')) {
errorlog("Twilio Failed");
}
+ } else if (turnstring == "php-credentials" || session.turn-mode == "php-credentials") { // a function loading the turn server credentials from the provided php-script "turn-credentials.php"
+ try {
+
+ session.ws = false; // prevents connection
+ var phpcredentialsRequest = new XMLHttpRequest();
+ phpcredentialsRequest.onreadystatechange = function() {
+ if (phpcredentialsRequest.status === 200) {
+ try{
+ var res = JSON.parse(phpcredentialsRequest.responseText);
+ } catch(e){return;}
+ session.configuration = {
+ iceServers: [{
+ "username": res["1"],
+ "credential": res["2"],
+ "urls": res["3"]
+ },
+ {
+ "username": res["1"],
+ "credential": res["2"],
+ "urls": res["4"]
+ }
+ ],
+ sdpSemantics: 'unified-plan' // future-proofing
+ };
+ if (session.ws===false){
+ session.ws=null; // allows connection (clears state)
+ session.connect(); // connect if not already connected.
+ }
+ }
+ // system does not connect if php script does not respond.
+ };
+ phpcredentialsRequest.open('GET', 'turn-credentials.php', true); // `false` makes the request synchronous
+ phpcredentialsRequest.send();
+
+
+ } catch (e) {
+ errorlog("php-credentials script Failed");
+ }
+
} else if ((turnstring == "false") || (turnstring == "off") || (turnstring == "0")) { // disable TURN servers
session.configuration = {
iceServers: [
diff --git a/turn-credentials.php b/turn-credentials.php
new file mode 100644
index 0000000..776d1fb
--- /dev/null
+++ b/turn-credentials.php
@@ -0,0 +1,11 @@
+:";
+ $turn_server = "turns::";
+ $turn_expiry = 86400;
+ $turn_username = time() + $turn_expiry;
+ $turn_secret = '';
+ $turn_password = base64_encode ( hash_hmac ( 'sha1', $turn_username, $turn_secret, true ) );
+
+ $arr = array('1' => $turn_username, '2' => $turn_password, '3' => $stun_server, '4' => $turn_server);
+ echo json_encode($arr);
+?>
\ No newline at end of file