Skip to content

Commit

Permalink
Adds autoconnect and autocall functionality to web test page.
Browse files Browse the repository at this point in the history
Use ?autoconnect=yes or ?autocall=name_to_call

BUG=313
Review URL: https://webrtc-codereview.appspot.com/439005

git-svn-id: http://webrtc.googlecode.com/svn/trunk@1858 4adac7df-926f-26a2-2b94-8c16560cd09d
  • Loading branch information
[email protected] committed Mar 8, 2012
1 parent 0e8b52c commit 50d9e26
Showing 1 changed file with 51 additions and 3 deletions.
54 changes: 51 additions & 3 deletions test/functional_test/webrtc_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,26 @@
var localStream = null;
var disconnecting = false;
var callState = 0; // 0 - Not started, 1 - Call ongoing
var startupAction = "";
var autoCallName = "";
var autoCallTries = 0;


// General

function setElementValuesFromURL() {
function parseUrlParameters() {
window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,
function(m, key, value) {
document.getElementById(key).value = unescape(value);
// Some specific parameters.
if ((key == "autoconnect") && (value == "yes")) {
startupAction = "connect";
} else if (key == "autocall") {
startupAction = "call";
autoCallName = unescape(value);
// The rest are set to elements with corresponding id.
} else {
document.getElementById(key).value = unescape(value);
}
});
}

Expand Down Expand Up @@ -88,6 +100,8 @@
document.getElementById("localView").src = url;
trace("User has granted access to local media. url = " + url);
localStream = s;
if (startupAction == "connect" || startupAction == "call")
connect();
}

function gotStreamFailed(error) {
Expand Down Expand Up @@ -184,6 +198,21 @@
return;
}

function getPeerId(peer_name) {
try {
var peerList = document.getElementById("peers");
for (var i = 0; i < peerList.length; i++) {
if (peerList.options[i].text == peer_name) {
return parseInt(peerList.options[i].value);
}
}
} catch (e) {
trace_exception(e, "Error finding peer ID");
return -1;
}
return -1;
}

function storeRemoteInfo() {
try {
var peerList = document.getElementById("peers");
Expand Down Expand Up @@ -252,6 +281,21 @@
setCallState(0);
}

function autoCall() {
var peer_id = getPeerId(autoCallName);
if (peer_id < 0) {
// Retry a couple of times before giving up.
if (autoCallTries < 3)
window.setTimeout(autoCall, ++autoCallTries * 1000);
else
trace_warning("Could not find a peer with name " + autoCallName +
", giving up");
return;
}
setSelectedPeer(peer_id);
doCall(0);
}


// PeerConnection callbacks

Expand Down Expand Up @@ -444,6 +488,10 @@
request = null;
document.getElementById("connect").disabled = true;
document.getElementById("disconnect").disabled = false;
if (startupAction == "call") {
startupAction = "";
window.setTimeout(autoCall, 1000);
}
}
}
} catch (e) {
Expand Down Expand Up @@ -517,7 +565,7 @@
window.onload = function() {
if (navigator.webkitGetUserMedia) {
document.getElementById('testApp').hidden = false;
setElementValuesFromURL();
parseUrlParameters();
getUserMedia();
} else {
document.getElementById('errorText').hidden = false;
Expand Down

0 comments on commit 50d9e26

Please sign in to comment.