Merge pull request #860 from Jumper78/feature/turn-server_with_static-auth-secret

turn-server with static-auth-secret in a separate php script
This commit is contained in:
Steve Seguin 2023-01-22 06:01:49 -05:00 committed by GitHub
commit 92197d6033
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 1 deletions

View File

@ -2282,7 +2282,43 @@
// session.configuration.iceServers.push(turn);
/////////////// ------------ END OF TURN SETUP SECTION -------
// session.configuration.iceTransportPolicy = "relay"; // uncomment to enable "&privacy" and force the TURN server
// 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
// session.wss = "wss://api.vdo.ninja:443"; // US-East (Default)

View File

@ -0,0 +1,13 @@
<?php
// If using static-auth-secret for your turn server, modify this file as needed; also rename to "turn-credentials.php"
$stun_server = "stun:<stun-server>:<stun-port>";
$turn_server = "turns:<turn-server>:<https-turn-port>";
$turn_expiry = 86400;
$turn_username = time() + $turn_expiry;
$turn_secret = '<turn-server static-auth-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);
?>