Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trickle-ice #2

Merged
merged 3 commits into from
Jan 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions samples/web/content/peerconnection/trickle-ice/index.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ <h2>ICE servers</h2>

<select id="servers" size="4">
<option value="{&quot;url&quot;:&quot;stun:stun.l.google.com:19302&quot;}">stun:stun.l.google.com:19302</option>
<option value="{&quot;url&quot;:[&quot;stun:stun.voxgratia.org&quot;,&quot;stun:stunserver.org&quot;]}">[stun:stun.voxgratia.org ; stun:stunserver.org]</option>
<option value="{&quot;url&quot;:&quot;stun:stun.callwithus.com&quot;}">stun:stun.callwithus.com</option>
</select>

<div>
<label for="url">STUN or TURN URI:</label>
<input id="url">
Expand All @@ -58,6 +59,7 @@ <h2>ICE servers</h2>
<div>
<button id="add">Add Server</button>
<button id="remove">Remove Server</button>
<button id="changeStruct">Change url structure</button>
</div>

</section>
Expand Down Expand Up @@ -110,7 +112,6 @@ <h2>ICE options</h2>

<script src="https://cdn.temasys.com.sg/adapterjs/0.10.x/adapter.debug.js"></script>
<script src="js/main.js"></script>

<script src="../../../js/lib/ga.js"></script>
</body>
</html>
43 changes: 37 additions & 6 deletions samples/web/content/peerconnection/trickle-ice/js/main.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,43 @@ var candidateTBody = document.getElementById('candidatesBody');
var gatherButton = document.getElementById('gather');
var passwordInput = document.getElementById('password');
var removeButton = document.getElementById('remove');
var changeButton = document.getElementById('changeStruct');
var servers = document.getElementById('servers');
var urlInput = document.getElementById('url');
var usernameInput = document.getElementById('username');
var ipv6Check = document.getElementById('ipv6');
var unbundleCheck = document.getElementById('unbundle');
var output = document.getElementById('output');


addButton.onclick = addServer;
gatherButton.onclick = start;
removeButton.onclick = removeServer;
changeButton.onclick = changeStruct;

var begin, pc;

var arrayURLStruc = false;

function changeStruct(){
if(!arrayURLStruc){
for(var i = servers.options.length - 1; i>=0; --i) {
var sers = JSON.parse(servers[i].value);
if(typeof sers.url === "string"){
servers[i].value = servers[i].value.replace("\""+sers.url+"\"" , "[\""+ sers.url + "\"]");
servers[i].text = '[' + servers[i].text + ']';
}
}
arrayURLStruc = !arrayURLStruc;
}else{
for(var i = servers.options.length - 1; i>=0; --i) {
var sers = JSON.parse(servers[i].value);
if(sers.url.length === 1 ){
servers[i].value = servers[i].value.replace("[\""+ sers.url + "\"]", "\""+sers.url+"\"" );
servers[i].text = servers[i].text.substr(1, servers[i].text.length - 2);
}
}
arrayURLStruc = !arrayURLStruc;
}
}
function addServer() {
var scheme = urlInput.value.split(':')[0];
if (scheme !== 'stun' && scheme !== 'turn' && scheme !== 'turns') {
Expand All @@ -34,8 +57,13 @@ function addServer() {
// Store the ICE server as a stringified JSON object in option.value.
var option = document.createElement('option');
var iceServer = createIceServer(urlInput.value, usernameInput.value, passwordInput.value);
option.value = JSON.stringify(iceServer);
option.text = urlInput.value + ' ';
if(arrayURLStruc){
option.value = JSON.stringify(iceServer).replace("\""+iceServer.url+"\"" , "[\""+ iceServer.url + "\"]");
option.text = '[' + urlInput.value + ']';
}else{
option.text = urlInput.value + ' ';
option.value = JSON.stringify(iceServer);
}
var username = usernameInput.value;
var password = passwordInput.value;
if (username || password) {
Expand Down Expand Up @@ -64,7 +92,10 @@ function start() {
output.value = '';
var iceServers = [];
for (var i = 0; i < servers.length; ++i) {
iceServers.push(JSON.parse(servers[i].value));
if(servers[i].value.search("hasCredentials") === -1){
servers[i].value = servers[i].value.replace("}" , ",\"hasCredentials\":false}");
}
iceServers.push(JSON.parse(servers[i].value));
}
var transports = document.getElementsByName('transports');
var iceTransports;
Expand All @@ -78,7 +109,7 @@ function start() {
// Create a PeerConnection with no streams, but force a m=audio line.
// This will gather candidates for either 1 or 2 ICE components, depending
// on whether the unbundle RTCP checkbox is checked.
var config = {"iceServers": iceServers };
var config = {"iceServers":iceServers};
var pcConstraints = {"mandatory": {"IceTransports": iceTransports}};
var offerConstraints = {"mandatory": {"OfferToReceiveAudio": true}};
// Whether we gather IPv6 candidates.
Expand Down
87 changes: 0 additions & 87 deletions samples/web/content/trickle-ice/js/main.js

This file was deleted.