From 50d9e26eea38dfd2763a11c3eeaf35e584eb4c58 Mon Sep 17 00:00:00 2001 From: "henrikg@webrtc.org" Date: Thu, 8 Mar 2012 09:53:55 +0000 Subject: [PATCH] Adds autoconnect and autocall functionality to web test page. 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 --- test/functional_test/webrtc_test.html | 54 +++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/test/functional_test/webrtc_test.html b/test/functional_test/webrtc_test.html index 300884cd26..3adfdc40f8 100644 --- a/test/functional_test/webrtc_test.html +++ b/test/functional_test/webrtc_test.html @@ -41,14 +41,26 @@ var pc = null; 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); + } }); } @@ -88,6 +100,8 @@ function gotStream(s) { 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) { @@ -184,6 +198,21 @@ function getPeerName(id) { 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"); @@ -252,6 +281,21 @@ function closeCall() { 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 @@ -444,6 +488,10 @@ function signInCallback() { request = null; document.getElementById("connect").disabled = true; document.getElementById("disconnect").disabled = false; + if (startupAction == "call") { + startupAction = ""; + window.setTimeout(autoCall, 1000); + } } } } catch (e) { @@ -517,7 +565,7 @@ function disconnect() { window.onload = function() { if (navigator.webkitGetUserMedia) { document.getElementById('testApp').hidden = false; - setElementValuesFromURL(); + parseUrlParameters(); getUserMedia(); } else { document.getElementById('errorText').hidden = false;