From b6c966197ad96914f291406a2e62108f0f34a713 Mon Sep 17 00:00:00 2001 From: Jumper78 <52802286+Jumper78@users.noreply.github.com> Date: Wed, 19 May 2021 10:23:03 +0200 Subject: [PATCH] move turn-credentials request to index.html main.js remove the section with the request to the turn-credentials.php script index.html add and uncomment the request to the turn-credentials.php script --- index.html | 37 +++++++++++++++++++++++++++++++++++-- main.js | 41 +---------------------------------------- 2 files changed, 36 insertions(+), 42 deletions(-) diff --git a/index.html b/index.html index 8be9494..e5fb440 100644 --- a/index.html +++ b/index.html @@ -1577,8 +1577,41 @@ // turn.urls = ["turn:turn2.obs.ninja:443"]; // US WEST // session.configuration.iceServers.push(turn); - // session.turnmode == "twilio" // uncomment to use credentials for the turn-server provided by Twilio - // session.turnmode = "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 + // use this section if you plan to use the turn-credentials.php to provide usename and password of the turn-server, e.g., because you use a turn-server that uses use-auth-secret and static-auth-secret + // 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"); + // } // session.configuration.iceTransportPolicy = "relay"; // uncomment to enable "&privacy" and force the TURN server diff --git a/main.js b/main.js index 4d22b8d..3e24749 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" || session.turnmode == "twilio") { // a sample function on loading remote credentials for TURN servers. + if (turnstring == "twilio") { // a sample function on loading remote credentials for TURN servers. try { session.ws = false; // prevents connection @@ -2515,45 +2515,6 @@ if (urlParams.has('turn')) { errorlog("Twilio Failed"); } - } else if (turnstring == "php-credentials" || session.turnmode == "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: [