-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrest-sample.html
60 lines (50 loc) · 1.9 KB
/
rest-sample.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Server Side Sample PHP code for the usage of the REST API</title>
<meta name="description" content="REST API STUN/TURN federation" />
<!-- base theme -->
<link rel="stylesheet" type="text/css" href="css/styles.css">
<!-- prettyprint -->
<link href="prettify.css" type="text/css" rel="css/stylesheet" />
<!-- prettyprint theme -->
<link rel="stylesheet" type="text/css" href="css/sunburst.css">
</head>
<body>
<script type="text/javascript" src="js/run_prettify.js"></script>
<pre class="prettyprint">
<?php
$ip=$_SERVER["REMOTE_ADDR"];
$apikey="api_key=PLACE_OF_YOUR_API_KEY";
//any desired application data (e.g. abc123)
$ufrag="abc123";
$url="https://api.turn.geant.org/stun?$apikey";
if(isset($ufrag)) {
$url .= "&ufrag=".$ufrag;
}
if(isset($ip)) {
$url .= "&ip=".$ip;
}
// create curl resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, $url);
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$output = curl_exec($ch);
//handle curl error
if($output === false)
{
echo "Curl error: " . curl_error($ch);
}
// close curl resource to free up system resources
curl_close($ch);
$response = json_decode($output,true);
$result[] = array("urls" => $response["uris"], "username"=> $response["username"], "credential"=> $response["password"], credentialType => "password");
$iceServers = json_encode($result);
?>
</pre>
</body>
</html>