Added turn-prober.sh: a super-simple prober for TURN servers & candidates.
BUG=2187 R=juberti@google.com, juberti@webrtc.org Review URL: https://webrtc-codereview.appspot.com/8689004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@5604 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
78ea3d50e0
commit
bf88eccf33
9
samples/js/apprtc/turn-prober/README
Normal file
9
samples/js/apprtc/turn-prober/README
Normal file
@ -0,0 +1,9 @@
|
||||
This script contains a simple prober that verifies that:
|
||||
- CEOD vends TURN server URIs with credentials on demand (mimicking apprtc)
|
||||
- rfc5766-turn-server vends TURN candidates from the servers vended by CEOD.
|
||||
|
||||
To use simply run ./turn-prober.sh
|
||||
If it prints "PASS" (and exits 0) then all is well.
|
||||
If it prints a mess of logs (and exits non-0) then something has gone sideways
|
||||
and apprtc.appspot.com is probably not working well (b/c of missing TURN
|
||||
functionality).
|
132
samples/js/apprtc/turn-prober/turn-prober.html
Normal file
132
samples/js/apprtc/turn-prober/turn-prober.html
Normal file
@ -0,0 +1,132 @@
|
||||
<html>
|
||||
<head>
|
||||
<script>
|
||||
var CEOD_URL = ("https://computeengineondemand.appspot.com/turn?" +
|
||||
"username=1234&key=5678");
|
||||
var xmlhttp = null;
|
||||
var turnServers = []; // Array of {turnUri, username, password}.
|
||||
// The next two arrays' entries correspond 1:1 to turnServers.
|
||||
var gotTurn = []; // Entries are null (not done), "PASS", or "FAIL"
|
||||
var pcs = []; // Entries are RTCPeerConnection objects.
|
||||
|
||||
// Test is done; log & replace document body with an appropriate message.
|
||||
function finish(msg) {
|
||||
msg = "DONE: " + msg;
|
||||
console.log(msg);
|
||||
document.body.innerHTML = msg;
|
||||
}
|
||||
|
||||
// Handle created offer SDP.
|
||||
function offerHandler(i, c) {
|
||||
var pc = pcs[i];
|
||||
pc.setLocalDescription(c,
|
||||
function() {},
|
||||
function(e) {console.log("sLD error: " + e); });
|
||||
pc = null;
|
||||
}
|
||||
|
||||
// Handle SDP offer creation error.
|
||||
function offerError(i, e) {
|
||||
console.log("createOffer error: " + e);
|
||||
checkForCompletion(i, "FAIL (offerError)");
|
||||
}
|
||||
|
||||
// Register a terminal condition |msg| for the |index|'th server and
|
||||
// terminate the test with an appropriate message if all servers are done.
|
||||
function checkForCompletion(index, msg) {
|
||||
gotTurn[index] = msg;
|
||||
var pass = true;
|
||||
for (var i = 0; i < gotTurn.length; ++i) {
|
||||
if (!gotTurn[i])
|
||||
return;
|
||||
if (gotTurn[i] != "PASS") {
|
||||
pass = false;
|
||||
// Don't "break" because a later still-null gotTurn value should let
|
||||
// us wait more.
|
||||
}
|
||||
}
|
||||
if (pass) {
|
||||
finish("PASS");
|
||||
} else {
|
||||
finish("FAIL: " + JSON.stringify(gotTurn));
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure we don't wait forever for TURN to complete.
|
||||
function nanny(i) {
|
||||
if (!gotTurn[i]) {
|
||||
checkForCompletion(i, "FAIL (TURN server failed to respond)");
|
||||
}
|
||||
}
|
||||
|
||||
// Handle incoming ICE candidate |c| from |turnServers[i]|.
|
||||
function onIceCandidate(i, c) {
|
||||
var pc = pcs[i];
|
||||
if (!c || !c.candidate) {
|
||||
checkForCompletion(
|
||||
i, !gotTurn[i] ? "FAIL (no TURN candidate)" :
|
||||
(gotTurn[i] == "PASS") ? "PASS" : gotTurn[i]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (c.candidate.candidate.indexOf(" typ relay ") >= 0) {
|
||||
gotTurn[i] = "PASS";
|
||||
}
|
||||
}
|
||||
|
||||
// Kick off the test.
|
||||
function go() {
|
||||
xmlhttp = new XMLHttpRequest();
|
||||
xmlhttp.onreadystatechange = onTurnResult;
|
||||
xmlhttp.open('GET', CEOD_URL, true);
|
||||
xmlhttp.send();
|
||||
}
|
||||
|
||||
// Handle the XMLHttpRequest's response.
|
||||
function onTurnResult() {
|
||||
if (xmlhttp.readyState != 4)
|
||||
return;
|
||||
|
||||
if (xmlhttp.status != 200) {
|
||||
finish("FAIL (no TURN server)");
|
||||
return;
|
||||
}
|
||||
|
||||
var turnServer = JSON.parse(xmlhttp.responseText);
|
||||
for (i = 0; i < turnServer.uris.length; i++) {
|
||||
if (turnServer.uris[i].indexOf(":3479?") >= 0) {
|
||||
// Why does CEOD vend useless port 3479 URIs?
|
||||
continue;
|
||||
}
|
||||
console.log("Adding to test: " +
|
||||
[turnServer.uris[i], turnServer.username,
|
||||
turnServer.password]);
|
||||
gotTurn.push(null);
|
||||
pcs.push(new webkitRTCPeerConnection({
|
||||
"iceServers": [{
|
||||
"url": turnServer.uris[i],
|
||||
"username": turnServer.username,
|
||||
"credential": turnServer.password
|
||||
}]
|
||||
}));
|
||||
var index = pcs.length - 1;
|
||||
var pc = pcs[index];
|
||||
if (!pc) {
|
||||
checkForCompletion(index, "FAIL (PeerConnection ctor failed)");
|
||||
continue;
|
||||
}
|
||||
pc.onicecandidate = (
|
||||
function(p) { return function(c) { onIceCandidate(p, c); } })(index);
|
||||
pc.createOffer(
|
||||
(function(p) { return function(o) { offerHandler(p, o); } })(index),
|
||||
(function(p) { return function(e) { offerError(p, e); } })(index),
|
||||
{'mandatory': { 'OfferToReceiveAudio': true } });
|
||||
window.setTimeout(
|
||||
(function(p) { return function() { nanny(p); } })(index), 10000);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body onload="go()">
|
||||
</body>
|
||||
</html>
|
45
samples/js/apprtc/turn-prober/turn-prober.sh
Executable file
45
samples/js/apprtc/turn-prober/turn-prober.sh
Executable file
@ -0,0 +1,45 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
function chrome_pids() {
|
||||
ps axuwww|grep $D|grep c[h]rome|awk '{print $2}'
|
||||
}
|
||||
|
||||
cd $(dirname $0)
|
||||
export D=$(mktemp -d)
|
||||
|
||||
CHROME_LOG_FILE="${D}/chrome_debug.log"
|
||||
touch $CHROME_LOG_FILE
|
||||
|
||||
chrome \
|
||||
--enable-logging=stderr \
|
||||
--no-first-run \
|
||||
--disable-web-security \
|
||||
--user-data-dir=$D \
|
||||
--vmodule="*media/*=3,*turn*=3" \
|
||||
"file://${PWD}/turn-prober.html" > $CHROME_LOG_FILE 2>&1 &
|
||||
CHROME_PID=$!
|
||||
|
||||
while ! grep -q DONE $CHROME_LOG_FILE && chrome_pids|grep -q .; do
|
||||
sleep 0.1
|
||||
done
|
||||
|
||||
# Suppress bash's Killed message for the chrome above.
|
||||
exec 3>&2
|
||||
exec 2>/dev/null
|
||||
while [ ! -z "$(chrome_pids)" ]; do
|
||||
kill -9 $(chrome_pids)
|
||||
done
|
||||
exec 2>&3
|
||||
exec 3>&-
|
||||
|
||||
DONE=$(grep DONE $CHROME_LOG_FILE)
|
||||
EXIT_CODE=0
|
||||
if grep -q "DONE: PASS" $CHROME_LOG_FILE; then
|
||||
echo "PASS"
|
||||
else
|
||||
cat $CHROME_LOG_FILE
|
||||
EXIT_CODE=1
|
||||
fi
|
||||
|
||||
rm -rf $D
|
||||
exit $EXIT_CODE
|
Loading…
x
Reference in New Issue
Block a user