Fixed the sanity_check and started using the new webrtc_test.html file. Added capability for xvfb testing.
The purpose for the xvfb mode is to be able to run tests on the windowless environment on the Chromebot. Given the right input video, we can then write a relatively simple algorithm to analyze the screenshots and thereby conclude that video is playing. BUG= TEST= Review URL: https://webrtc-codereview.appspot.com/447004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@1890 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
cdbda4fc54
commit
754626b5ea
@ -1,10 +1,12 @@
|
||||
This folder can be used to pull together the chromium version of webrtc
|
||||
and libjingle, and build the peerconnection sample client and server.
|
||||
|
||||
Follow the instructions for WebRTC here:
|
||||
http://www.webrtc.org/reference/getting-started
|
||||
|
||||
but substitute this "gclient config" command:
|
||||
gclient config --name trunk
|
||||
http://webrtc.googlecode.com/svn/trunk/peerconnection
|
||||
and libjingle, and build the peerconnection sample client and server. This will
|
||||
check out a new repository in which you can build peerconnection_server.
|
||||
|
||||
Steps:
|
||||
1) Create a new directory for the new repository (outside the webrtc repo):
|
||||
mkdir peerconnection
|
||||
cd peerconnection
|
||||
2) gclient config --name trunk http://webrtc.googlecode.com/svn/trunk/peerconnection
|
||||
3) gclient sync
|
||||
4) cd trunk
|
||||
5) make peerconnection_server peerconnection_client
|
||||
|
@ -1,46 +0,0 @@
|
||||
This test client is a simple functional test for a WebRTC enabled browser. It
|
||||
has only been tested with Chrome, and is most likely only working with Chrome at
|
||||
the moment. The following instructions are in part Chrome specific.
|
||||
|
||||
The following is necessary to run the test:
|
||||
- A WebRTC enabled Chrome binary. (Available in dev or canary channel, 18.0.1008
|
||||
or newer.)
|
||||
- A peerconnection_server binary (make peerconnection_server).
|
||||
|
||||
It can be used in two scenarios:
|
||||
1. Single client calling itself with the server test page in loopback mode as a
|
||||
fake client.
|
||||
2. Call between two clients.
|
||||
|
||||
To start the test for scenario (1):
|
||||
1. Start peerconnection_server.
|
||||
2. Start the WebRTC Chrome build:
|
||||
$ <path_to_chrome_binary>/chrome --enable-media-stream
|
||||
The --enable-media-stream flag is required for the time being.
|
||||
3. Open the server test page, ensure loopback is enabled, choose a name (for
|
||||
example "loopback") and connect to the server.
|
||||
For version 18.0.1008 to 18.0.1020, use:
|
||||
http://libjingle.googlecode.com/svn-history/r103/trunk/talk/examples/peerconnection/server/server_test.html
|
||||
For version 18.0.1021 and later, use:
|
||||
http://libjingle.googlecode.com/svn/trunk/talk/examples/peerconnection/server/server_test.html
|
||||
4. Open the test page, connect to the server, select the loopback peer, click
|
||||
call.
|
||||
|
||||
To start the test for scenario (2):
|
||||
1. Start peerconnection_server.
|
||||
2. Start the WebRTC Chrome build, see scenario (1).
|
||||
3. Open the test page, connect to the server.
|
||||
4. Open a new new tab, open the test page, connect to the server.
|
||||
OR
|
||||
On another machine, repeat 2 and 3.
|
||||
5. Select the other peer, click call.
|
||||
|
||||
Note: The web page must normally be on a web server to be able to access the
|
||||
camera for security reasons.
|
||||
See http://blog.chromium.org/2008/12/security-in-depth-local-web-pages.html
|
||||
for more details on this topic. This can be overridden with the flag
|
||||
--allow-file-access-from-files, in which case running it over the file://
|
||||
URI scheme works.
|
||||
|
||||
Note: It's possible to specify the server and name in the url:
|
||||
.../webrtc.html?server=my_server&name=my_name
|
@ -3,11 +3,23 @@ one tab to the other tab, across the local network interface.
|
||||
|
||||
In order to run this test, you need to have:
|
||||
|
||||
- a WebRTC Chrome binary in
|
||||
$PROJECT_ROOT/../../chromium/src/out/Debug/chrome
|
||||
- an installed lighttpd in your $PATH
|
||||
- a built peerconnection_server (make peerconnection_server)
|
||||
- a built peerconnection_server
|
||||
- a sufficiently new google-chrome binary with WebRTC support.
|
||||
|
||||
You need to run the script from the test/sanity_check directory.
|
||||
To build peerconnection_server, refer to peerconnection_server/README. This
|
||||
script will assume you have a directory structure like so:
|
||||
|
||||
The first time you run it, you will be asked to choose a search engine :-(
|
||||
- webrtc/trunk/
|
||||
- peerconnection/trunk
|
||||
|
||||
That is, the script assumes it will find a peerconnection_server binary in
|
||||
../../../../peerconnection/out/Debug/ relative to the sanity check
|
||||
directory. If this doesn't suit you, feel free to change the script locally.
|
||||
|
||||
You need to run the script from the test/sanity_check directory. The first time
|
||||
you run it, you will be asked to choose a search engine. Additionally, you will
|
||||
have to let Chrome access your webcam by accepting the notice at the top.
|
||||
|
||||
This script uses the webrtc_test.html code, which is described by its own
|
||||
README in the www/html directory.
|
83
test/sanity_check/run_sanity_check
Normal file → Executable file
83
test/sanity_check/run_sanity_check
Normal file → Executable file
@ -3,18 +3,19 @@
|
||||
# Run a test with the WebRTC Chromium build.
|
||||
# Should work on any machine with a camera.
|
||||
#
|
||||
# Method:
|
||||
# - Start server
|
||||
# - Start 2 browser tabs
|
||||
# - Browser tab 1 captures camera
|
||||
# - Both browsers sign in
|
||||
# - Browser 1 calls browser 2
|
||||
# - Browser 2 displays camera feed from browser 1
|
||||
# Pass the argument --xvfb-and-screenshots to run in a xvfb environment and
|
||||
# capture screenshots from inside the virtual environment. If you don't what
|
||||
# that is, never mind and run this script without arguments.
|
||||
#
|
||||
# Method:
|
||||
# - Start peerconnection server.
|
||||
# - Start serving webrtc_test.html off a local web server.
|
||||
# - Start 2 browser tabs.
|
||||
# - Tab 1 connects to the server.
|
||||
# - Tab 2 connects to the server and calls tab 1.
|
||||
# - Both tabs will capture the webcam you have on the system and start
|
||||
# sending to each other.
|
||||
#
|
||||
|
||||
# Feel free to tweak this locally if your chrome build is somewhere else.
|
||||
# The default assumes that it is in a folder called chromium two levels
|
||||
# up from the project root ('trunk').
|
||||
|
||||
set -e
|
||||
|
||||
@ -23,12 +24,37 @@ if [ ! -x run_sanity_check ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
URLBASE=127.0.0.1:3000
|
||||
CALLER=$URLBASE/call_client.html
|
||||
CALLEE=$URLBASE/call_responder.html
|
||||
FLAGS="--enable-media-stream --enable-p2papi"
|
||||
# Tweakable parameters:
|
||||
URLBASE=localhost:3000
|
||||
CHROME_BINARY=google-chrome
|
||||
CALLEE="$URLBASE/webrtc_test.html?name=test1&autoconnect=yes"
|
||||
CALLER="$URLBASE/webrtc_test.html?name=test2&autocall=test1"
|
||||
FLAGS="--enable-media-stream"
|
||||
|
||||
run_chrome_for_user() {
|
||||
# Run the binary straight up and proceed with cleanup when the user closes
|
||||
# the browser.
|
||||
${CHROME_BINARY} $CALLEE $CALLER $FLAGS --user-data-dir=temp/user1
|
||||
}
|
||||
|
||||
run_chrome_in_xvfb_with_screenshots() {
|
||||
# Run chrome in a virtual window environment and capture screenshots.
|
||||
# It will run for 30 seconds and then exit.
|
||||
Xvfb :17 -screen 0 1024x768x24 &
|
||||
DISPLAY=:17 ${CHROME_BINARY} $CALLEE $CALLER $FLAGS --user-data-dir=temp/user1 &
|
||||
CHROME=$!
|
||||
|
||||
sleep 2
|
||||
|
||||
for (( i = 0; i < 6; i++ )) do
|
||||
FILENAME="IMAGE${i}.png"
|
||||
DISPLAY=:17 import -window root $FILENAME
|
||||
sleep 5
|
||||
done
|
||||
kill $CHROME || echo "No Chrome process."
|
||||
}
|
||||
|
||||
PROJECT_ROOT=../..
|
||||
CHROME_BINARY=$PROJECT_ROOT/../../chromium/src/out/Debug/chrome
|
||||
|
||||
if which lighttpd; then
|
||||
LOCAL_WEB_SERVER_BINARY=$(which lighttpd)
|
||||
@ -37,15 +63,10 @@ else
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SERVER_BINARY=${PROJECT_ROOT}/out/Debug/peerconnection_server
|
||||
SERVER_BINARY=${PROJECT_ROOT}/../../peerconnection/trunk/out/Debug/peerconnection_server
|
||||
if [ ! -e "$SERVER_BINARY" ]; then
|
||||
echo "Error: You must build peerconnection_server first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CHROME_BINARY=$PROJECT_ROOT/../../chromium/src/out/Debug/chrome
|
||||
if [ ! -e "$CHROME_BINARY" ]; then
|
||||
echo "Error: You must build chrome (could not open $CHROME_BINARY)."
|
||||
echo "I expected to find a binary at $SERVER_BINARY but found none."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@ -57,16 +78,14 @@ ${SERVER_BINARY} &
|
||||
SERVER=$!
|
||||
echo "Started server as $SERVER"
|
||||
|
||||
# We can make 2 browsers
|
||||
#${CHROME_BINARY} $CALLER $FLAGS --user-data-dir=temp/user1 &
|
||||
#USER1=$!
|
||||
#echo "Started first user as $USER1"
|
||||
#${CHROME_BINARY} $CALLEE $FLAGS --user-data-dir=temp/user2
|
||||
|
||||
# But it also works with separate tabs in one browser.
|
||||
${CHROME_BINARY} $CALLER $CALLEE $FLAGS --user-data-dir=temp/user1
|
||||
# Launch a browser with two tabs:
|
||||
if [ "$1" == "--xvfb-and-screenshots" ]; then
|
||||
run_chrome_in_xvfb_with_screenshots
|
||||
else
|
||||
run_chrome_for_user
|
||||
fi
|
||||
|
||||
echo "Test finished, cleaning up"
|
||||
|
||||
kill $SERVER || echo "No server"
|
||||
kill $SERVER || echo "No peerconnection_server"
|
||||
kill $LOCAL_WEB_SERVER || echo "No local web server"
|
||||
|
60
test/sanity_check/www/html/README
Normal file
60
test/sanity_check/www/html/README
Normal file
@ -0,0 +1,60 @@
|
||||
webrtc_test.html is a simple functional test for a WebRTC enabled browser. It
|
||||
has only been tested with Chrome, and is most likely only working with Chrome at
|
||||
the moment. The following instructions are in part Chrome specific.
|
||||
|
||||
If you want a quick, automated test, have a look at the test/sanity_check script
|
||||
which uses this page to quickly launch a call test on Linux.
|
||||
|
||||
Table of contents:
|
||||
* PREREQUISITES
|
||||
* SINGLE FAKE CLIENT IN LOOPBACK MODE
|
||||
* TWO CLIENTS CALLING EACH OTHER
|
||||
* TWO AUTOCALLING CLIENTS
|
||||
|
||||
* PREREQUISITES
|
||||
|
||||
The following is necessary to run the test:
|
||||
- A WebRTC enabled Chrome binary. (Available in dev or canary channel, version
|
||||
18.0.1008 or newer.)
|
||||
- A peerconnection_server binary. See peerconnection/README for more information
|
||||
on how to do this.
|
||||
|
||||
Note: The web page must normally be on a web server to be able to access the
|
||||
camera for security reasons.
|
||||
|
||||
See http://blog.chromium.org/2008/12/security-in-depth-local-web-pages.html
|
||||
for more details on this topic. This can be overridden with the flag
|
||||
--allow-file-access-from-files, in which case running it over the file://
|
||||
URI scheme works.
|
||||
|
||||
* SINGLE FAKE CLIENT IN LOOPBACK MODE
|
||||
|
||||
1. Start peerconnection_server.
|
||||
2. Start the WebRTC Chrome build:
|
||||
$ <path_to_chrome_binary>/chrome --enable-media-stream
|
||||
The --enable-media-stream flag is required for the time being.
|
||||
3. Open the server test page, ensure loopback is enabled, choose a name (for
|
||||
example "loopback") and connect to the server.
|
||||
For version 18.0.1008 to 18.0.1020, use:
|
||||
http://libjingle.googlecode.com/svn-history/r103/trunk/talk/examples/peerconnection/server/server_test.html
|
||||
For version 18.0.1021 and later, use:
|
||||
http://libjingle.googlecode.com/svn/trunk/talk/examples/peerconnection/server/server_test.html
|
||||
4. Open the test page, connect to the server, select the loopback peer, click
|
||||
call.
|
||||
|
||||
* TWO CLIENTS CALLING EACH OTHER
|
||||
|
||||
1. Start peerconnection_server.
|
||||
2. Start the WebRTC Chrome build, see scenario (1).
|
||||
3. Open the test page, connect to the server.
|
||||
4. Open a new new tab, open the test page, connect to the server.
|
||||
OR
|
||||
On another machine, repeat 2 and 3.
|
||||
5. Select the other peer, click call.
|
||||
|
||||
* TWO AUTOCALLING CLIENTS
|
||||
|
||||
1. Run the procedure for "two clients calling each other", but give the pages
|
||||
the following parameters:
|
||||
webrtc_test.html?name=test1&autoconnect=yes&server=localhost:8888
|
||||
webrtc_test.html?name=test2&autocall=test1&server=localhost:8888
|
@ -1,394 +0,0 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
||||
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>WebRTC Autocaller</title>
|
||||
<script type="text/javascript">
|
||||
|
||||
var local_name;
|
||||
var server;
|
||||
var my_id = -1;
|
||||
var other_peers = {};
|
||||
var request = null;
|
||||
var hanging_get = null;
|
||||
var pc = null;
|
||||
var local_stream = null;
|
||||
var call_state = 0;
|
||||
// 0 - Not started
|
||||
// 1 - Call ongoing
|
||||
// 2 - We have initiated closing the call
|
||||
// 3 - Other side has initiated closing the call
|
||||
|
||||
// General
|
||||
function toggleExtraButtons() {
|
||||
document.getElementById("createPcBtn").hidden =
|
||||
!document.getElementById("createPcBtn").hidden;
|
||||
document.getElementById("addStreamBtn").hidden =
|
||||
!document.getElementById("addStreamBtn").hidden;
|
||||
}
|
||||
|
||||
function trace(txt) {
|
||||
var elem = document.getElementById("debug");
|
||||
elem.innerHTML += txt + "<br>";
|
||||
}
|
||||
|
||||
function trace_warning(txt) {
|
||||
var wtxt = "<b>" + txt + "</b>";
|
||||
trace(wtxt);
|
||||
}
|
||||
|
||||
function setCallState(state) {
|
||||
trace("Changing call state: " + call_state + " -> " + state);
|
||||
call_state = state;
|
||||
}
|
||||
|
||||
function checkPeerConnection() {
|
||||
if (!pc) {
|
||||
trace_warning("No PeerConnection object exists.");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Local stream generation
|
||||
function gotStream(s) {
|
||||
var url = webkitURL.createObjectURL(s);
|
||||
document.getElementById("localView").src = url;
|
||||
trace("User has granted access to webcam. url = " + url);
|
||||
local_stream = s;
|
||||
}
|
||||
|
||||
function gotStreamFailed(error) {
|
||||
alert("Failed to get access to webcam. Error code was " + error.code);
|
||||
trace("Failed to get access to webcam. Error code was " + error.code);
|
||||
}
|
||||
|
||||
// Call control
|
||||
function createPeerConnection() {
|
||||
if (pc) {
|
||||
trace_warning("PeerConnection object already exists.");
|
||||
}
|
||||
trace("Creating PeerConnection object.");
|
||||
// CRASH TEST
|
||||
pc = new webkitPeerConnection("STUN 1.2.3.4:43", onSignalingMessage);
|
||||
pc.onaddstream = onAddStream;
|
||||
pc.onremovestream = onRemoveStream;
|
||||
}
|
||||
|
||||
function startCall() {
|
||||
document.getElementById("startcall").disabled = true;
|
||||
createPeerConnection();
|
||||
addStream();
|
||||
}
|
||||
|
||||
function addStream() {
|
||||
trace("Starting call. [pc.addStream(local_stream)]");
|
||||
pc.addStream(local_stream);
|
||||
document.getElementById("stopcall").disabled = false;
|
||||
}
|
||||
|
||||
function stopCall() {
|
||||
document.getElementById("stopcall").disabled = true;
|
||||
trace("Stopping call [pc.close()]");
|
||||
setCallState(2);
|
||||
pc.close();
|
||||
}
|
||||
|
||||
function test1() {
|
||||
addStream();
|
||||
}
|
||||
|
||||
function callHasStarted() {
|
||||
setCallState(1);
|
||||
}
|
||||
|
||||
// PeerConnection callbacks
|
||||
function onAddStream(e) {
|
||||
var stream = pc.remoteStreams[0];
|
||||
var url = webkitURL.createObjectURL(stream);
|
||||
document.getElementById("remoteView").src = url;
|
||||
trace("Started showing remote stream. url = " + url);
|
||||
setTimeout(callHasStarted, 5000); // TODO(hta): workaround, to be removed
|
||||
}
|
||||
|
||||
function onRemoveStream(e) {
|
||||
// Currently if we get this callback, call has ended.
|
||||
document.getElementById("remoteView").src = "";
|
||||
trace("Stopped showing remote stream.");
|
||||
if (call_state == 2) {
|
||||
// Finalize close call. We assume here that this callback comes
|
||||
// after onSignalingMessage.
|
||||
pc = null;
|
||||
setCallState(0);
|
||||
document.getElementById("startcall").disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
function onSignalingMessage(msg) {
|
||||
var peer_id = parseInt(document.getElementById("peer_id").value);
|
||||
trace("Sending message to " + other_peers[peer_id] +
|
||||
" (ID " + peer_id + "):\n" + msg);
|
||||
sendToPeer(peer_id, msg);
|
||||
}
|
||||
|
||||
// Server interaction
|
||||
|
||||
function handleServerNotification(data) {
|
||||
trace("Server notification: " + data);
|
||||
notePeerAndMaybeCall(data);
|
||||
}
|
||||
|
||||
function handlePeerMessage(peer_id, msg) {
|
||||
trace("Received message from " + other_peers[peer_id] +
|
||||
" (ID " + peer_id + "):\n" + msg);
|
||||
// Assuming we have created a PeerConnection and that we receive the
|
||||
// message from the peer want to communicate with
|
||||
document.getElementById("peer_id").value =
|
||||
peer_id; // Ensure we reply to the same peer
|
||||
|
||||
if (pc) {
|
||||
try {
|
||||
pc.processSignalingMessage(msg);
|
||||
} catch (e) {
|
||||
trace_warning("Signaling message error: " + e.description);
|
||||
}
|
||||
if (call_state == 1)
|
||||
setCallState(3);
|
||||
} else {
|
||||
createPeerConnection();
|
||||
pc.processSignalingMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
function getIntHeader(r, name) {
|
||||
var val = r.getResponseHeader(name);
|
||||
trace("header value: " + val);
|
||||
return val != null && val.length ? parseInt(val) : -1;
|
||||
}
|
||||
|
||||
function hangingGetCallback() {
|
||||
try {
|
||||
if (hanging_get.readyState != 4)
|
||||
return;
|
||||
if (hanging_get.status != 200) {
|
||||
trace("server error, status: " + hanging_get.status + ", text: " +
|
||||
hanging_get.statusText);
|
||||
disconnect();
|
||||
} else {
|
||||
var peer_id = getIntHeader(hanging_get, "Pragma");
|
||||
if (peer_id == my_id) {
|
||||
handleServerNotification(hanging_get.responseText);
|
||||
} else {
|
||||
handlePeerMessage(peer_id, hanging_get.responseText);
|
||||
}
|
||||
}
|
||||
|
||||
if (hanging_get) {
|
||||
hanging_get.abort();
|
||||
hanging_get = null;
|
||||
}
|
||||
|
||||
if (my_id != -1)
|
||||
window.setTimeout(startHangingGet, 0);
|
||||
} catch (e) {
|
||||
trace("Hanging get error: " + e.description);
|
||||
}
|
||||
}
|
||||
|
||||
function onHangingGetTimeout() {
|
||||
trace("hanging get timeout. issuing again.");
|
||||
hanging_get.abort();
|
||||
hanging_get = null;
|
||||
if (my_id != -1)
|
||||
window.setTimeout(startHangingGet, 0);
|
||||
}
|
||||
|
||||
function startHangingGet() {
|
||||
try {
|
||||
hanging_get = new XMLHttpRequest();
|
||||
hanging_get.onreadystatechange = hangingGetCallback;
|
||||
hanging_get.ontimeout = onHangingGetTimeout;
|
||||
hanging_get.open("GET", server + "/wait?peer_id=" + my_id, true);
|
||||
hanging_get.send();
|
||||
} catch (e) {
|
||||
trace("error" + e.description);
|
||||
}
|
||||
}
|
||||
|
||||
function sendToPeer(peer_id, data) {
|
||||
if (my_id == -1) {
|
||||
alert("Not connected");
|
||||
return;
|
||||
}
|
||||
if (peer_id == my_id) {
|
||||
alert("Can't send a message to oneself :)");
|
||||
return;
|
||||
}
|
||||
var r = new XMLHttpRequest();
|
||||
r.open("POST", server + "/message?peer_id=" + my_id + "&to=" +
|
||||
peer_id, false);
|
||||
r.setRequestHeader("Content-Type", "text/plain");
|
||||
r.send(data);
|
||||
r = null;
|
||||
}
|
||||
|
||||
function notePeerAndMaybeCall(peerInfo) {
|
||||
var parsed = peerInfo.split(",");
|
||||
if (parseInt(parsed[2]) != 0) {
|
||||
trace("Peer came on: " + peerInfo);
|
||||
other_peers[parseInt(parsed[1])] = parsed[0];
|
||||
// If we're not already in a call, call it.
|
||||
if (!document.getElementById("startcall").disabled) {
|
||||
document.getElementById("peer_id").value = parsed[1];
|
||||
startCall();
|
||||
}
|
||||
} else {
|
||||
trace("Peer went away: " + peerInfo);
|
||||
other_peers[parseInt(parsed[1])] = null;
|
||||
}
|
||||
}
|
||||
|
||||
function signInCallback() {
|
||||
try {
|
||||
if (request.readyState == 4) {
|
||||
if (request.status == 200) {
|
||||
var peers = request.responseText.split("\n");
|
||||
my_id = parseInt(peers[0].split(",")[1]);
|
||||
trace("My id: " + my_id);
|
||||
for (var i = 1; i < peers.length; ++i) {
|
||||
if (peers[i].length > 0) {
|
||||
trace("Peer " + i + ": " + peers[i]);
|
||||
notePeerAndMaybeCall(peers[i]);
|
||||
}
|
||||
}
|
||||
startHangingGet();
|
||||
request = null;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
trace("error: " + e.description);
|
||||
}
|
||||
}
|
||||
|
||||
function signIn() {
|
||||
try {
|
||||
request = new XMLHttpRequest();
|
||||
request.onreadystatechange = signInCallback;
|
||||
request.open("GET", server + "/sign_in?" + local_name, true);
|
||||
request.send();
|
||||
} catch (e) {
|
||||
trace("error: " + e.description);
|
||||
}
|
||||
}
|
||||
|
||||
function connect() {
|
||||
local_name = document.getElementById("local").value.toLowerCase();
|
||||
server = document.getElementById("server").value.toLowerCase();
|
||||
if (local_name.length == 0) {
|
||||
alert("I need a name please.");
|
||||
document.getElementById("local").focus();
|
||||
} else {
|
||||
document.getElementById("connect").disabled = true;
|
||||
document.getElementById("disconnect").disabled = false;
|
||||
trace("Connecting to server");
|
||||
signIn();
|
||||
}
|
||||
}
|
||||
|
||||
function disconnect() {
|
||||
if (request) {
|
||||
request.abort();
|
||||
request = null;
|
||||
}
|
||||
|
||||
if (hanging_get) {
|
||||
hanging_get.abort();
|
||||
hanging_get = null;
|
||||
}
|
||||
|
||||
if (my_id != -1) {
|
||||
request = new XMLHttpRequest();
|
||||
request.open("GET", server + "/sign_out?peer_id=" + my_id, false);
|
||||
request.send();
|
||||
request = null;
|
||||
my_id = -1;
|
||||
}
|
||||
|
||||
document.getElementById("connect").disabled = false;
|
||||
document.getElementById("disconnect").disabled = true;
|
||||
}
|
||||
|
||||
function toggleLog()
|
||||
{
|
||||
document.getElementById('debug').hidden =!
|
||||
document.getElementById('debug').hidden;
|
||||
}
|
||||
|
||||
window.onbeforeunload = disconnect;
|
||||
|
||||
// TODO: Add audio here when available. Note: now it's hard coded,
|
||||
// audio will also be started.
|
||||
navigator.webkitGetUserMedia("video", gotStream, gotStreamFailed);
|
||||
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>WebRTC autocaller</h1>
|
||||
This page should show your local camera, and connect to a remote browser.
|
||||
<table border="0">
|
||||
|
||||
<tr>
|
||||
<th align="left">Local Preview</th>
|
||||
<th align="left">Remote Video</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><video width="320" height="240" id="localView" autoplay="autoplay">
|
||||
</video></td>
|
||||
<td><video width="640" height="480" id="remoteView" autoplay="autoplay">
|
||||
</video></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top">
|
||||
<form>
|
||||
Target peer ID: <input type="text" id="peer_id" size="3" value="1"/><br>
|
||||
<button id="startcall" onclick="startCall();">(4) Start call</button><br>
|
||||
<button id="stopcall" onclick="stopCall();" disabled="true">(5) Stop call
|
||||
</button><br>
|
||||
<!--<input type="button" value="Test 1" onclick="test1()"/><br>-->
|
||||
</form>
|
||||
</td>
|
||||
<td valign="top">
|
||||
<button onclick="toggleExtraButtons();">Toggle extra buttons</button><br>
|
||||
<button id="createPcBtn" onclick="createPeerConnection();" hidden="true">
|
||||
Create peer connection</button><br>
|
||||
<button id="addStreamBtn" onclick="addStream();" hidden="true">
|
||||
Add stream</button><br>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr><td colspan="2">
|
||||
(1) Server: <input type="text" id="server" value="http://localhost:8888" />
|
||||
<br>
|
||||
(2) Your name: <input type="text" id="local" value="caller"/>
|
||||
<button id="connect" onclick="connect();" disabled="true">(3) Connect</button>
|
||||
<button id="disconnect" onclick="disconnect();" disabled="true">(6) Disconnect
|
||||
</button>
|
||||
<br>
|
||||
<br>
|
||||
<button onclick="toggleLog()">Toggle view log</button>
|
||||
<button onclick="document.getElementById('debug').innerHTML='';">
|
||||
Clear log</button>
|
||||
<pre id="debug">
|
||||
</pre>
|
||||
</td></tr>
|
||||
|
||||
</table>
|
||||
</body>
|
||||
<script>
|
||||
// On init, we connect to the server.
|
||||
connect();
|
||||
</script>
|
||||
|
||||
</html>
|
@ -1,373 +0,0 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
||||
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>WebRTC Autoresponder</title>
|
||||
This page should show a stream coming from a different browser.
|
||||
<script type="text/javascript">
|
||||
|
||||
var local_name;
|
||||
var server;
|
||||
var my_id = -1;
|
||||
var other_peers = {};
|
||||
var request = null;
|
||||
var hanging_get = null;
|
||||
var pc = null;
|
||||
var local_stream = null;
|
||||
var call_state = 0;
|
||||
// 0 - Not started
|
||||
// 1 - Call ongoing
|
||||
// 2 - We have initiated closing the call
|
||||
// 3 - Other side has initiated closing the call
|
||||
|
||||
// General
|
||||
function toggleExtraButtons() {
|
||||
document.getElementById("createPcBtn").hidden =
|
||||
!document.getElementById("createPcBtn").hidden;
|
||||
document.getElementById("addStreamBtn").hidden =
|
||||
!document.getElementById("addStreamBtn").hidden;
|
||||
}
|
||||
|
||||
function trace(txt) {
|
||||
var elem = document.getElementById("debug");
|
||||
elem.innerHTML += txt + "<br>";
|
||||
}
|
||||
|
||||
function trace_warning(txt) {
|
||||
var wtxt = "<b>" + txt + "</b>";
|
||||
trace(wtxt);
|
||||
}
|
||||
|
||||
function setCallState(state) {
|
||||
trace("Changing call state: " + call_state + " -> " + state);
|
||||
call_state = state;
|
||||
}
|
||||
|
||||
function checkPeerConnection() {
|
||||
if (!pc) {
|
||||
trace_warning("No PeerConnection object exists.");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Local stream generation
|
||||
function gotStream(s) {
|
||||
var url = webkitURL.createObjectURL(s);
|
||||
document.getElementById("localView").src = url;
|
||||
trace("User has granted access to webcam. url = " + url);
|
||||
local_stream = s;
|
||||
}
|
||||
|
||||
function gotStreamFailed(error) {
|
||||
alert("Failed to get access to webcam. Error code was " + error.code);
|
||||
trace("Failed to get access to webcam. Error code was " + error.code);
|
||||
}
|
||||
|
||||
// Call control
|
||||
function createPeerConnection() {
|
||||
if (pc) {
|
||||
trace_warning("PeerConnection object already exists.");
|
||||
}
|
||||
trace("Creating PeerConnection object.");
|
||||
pc = new webkitPeerConnection("STUN stun.l.google.com:19302",
|
||||
onSignalingMessage);
|
||||
pc.onaddstream = onAddStream;
|
||||
pc.onremovestream = onRemoveStream;
|
||||
}
|
||||
|
||||
function startCall() {
|
||||
document.getElementById("startcall").disabled = true;
|
||||
createPeerConnection();
|
||||
addStream();
|
||||
}
|
||||
|
||||
function addStream()
|
||||
{
|
||||
trace("Starting call. [pc.addStream(local_stream)]");
|
||||
pc.addStream(local_stream);
|
||||
document.getElementById("stopcall").disabled = false;
|
||||
}
|
||||
|
||||
function stopCall() {
|
||||
document.getElementById("stopcall").disabled = true;
|
||||
trace("Stopping call [pc.close()]");
|
||||
setCallState(2);
|
||||
pc.close();
|
||||
}
|
||||
|
||||
function test1() {
|
||||
addStream();
|
||||
}
|
||||
|
||||
function callHasStarted() {
|
||||
setCallState(1);
|
||||
}
|
||||
|
||||
// PeerConnection callbacks
|
||||
function onAddStream(e) {
|
||||
var stream = pc.remoteStreams[0];
|
||||
var url = webkitURL.createObjectURL(stream);
|
||||
document.getElementById("remoteView").src = url;
|
||||
trace("Started showing remote stream. url = " + url);
|
||||
setTimeout(callHasStarted, 5000); // TODO: Temp workaround, to be removed
|
||||
}
|
||||
|
||||
function onRemoveStream(e) {
|
||||
// Currently if we get this callback, call has ended.
|
||||
document.getElementById("remoteView").src = "";
|
||||
trace("Stopped showing remote stream.");
|
||||
if (call_state == 2) {
|
||||
// Finalize close call. We assume here that this
|
||||
// callback comes after onSignalingMessage.
|
||||
pc = null;
|
||||
setCallState(0);
|
||||
document.getElementById("startcall").disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
function onSignalingMessage(msg) {
|
||||
var peer_id = parseInt(document.getElementById("peer_id").value);
|
||||
trace("Sending message to " + other_peers[peer_id] +
|
||||
" (ID " + peer_id + "):\n" + msg);
|
||||
sendToPeer(peer_id, msg);
|
||||
}
|
||||
|
||||
// Server interaction
|
||||
|
||||
function handleServerNotification(data) {
|
||||
trace("Server notification: " + data);
|
||||
var parsed = data.split(",");
|
||||
if (parseInt(parsed[2]) != 0)
|
||||
other_peers[parseInt(parsed[1])] = parsed[0];
|
||||
}
|
||||
|
||||
function handlePeerMessage(peer_id, msg) {
|
||||
trace("Received message from " + other_peers[peer_id] +
|
||||
" (ID " + peer_id + "):\n" + msg);
|
||||
// Assuming we have created a PeerConnection and that we receive the message
|
||||
// from the peer we want to communicate with
|
||||
document.getElementById("peer_id").value = peer_id;
|
||||
if (pc) {
|
||||
try {
|
||||
pc.processSignalingMessage(msg);
|
||||
} catch (e) {
|
||||
trace_warning("Signaling message error: " + e.description);
|
||||
}
|
||||
if (call_state == 1)
|
||||
setCallState(3);
|
||||
} else {
|
||||
createPeerConnection();
|
||||
pc.processSignalingMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
function getIntHeader(r, name) {
|
||||
var val = r.getResponseHeader(name);
|
||||
trace("header value: " + val);
|
||||
return val != null && val.length ? parseInt(val) : -1;
|
||||
}
|
||||
|
||||
function hangingGetCallback() {
|
||||
try {
|
||||
if (hanging_get.readyState != 4)
|
||||
return;
|
||||
if (hanging_get.status != 200) {
|
||||
trace("server error, status: " + hanging_get.status +
|
||||
", text: " + hanging_get.statusText);
|
||||
disconnect();
|
||||
} else {
|
||||
var peer_id = getIntHeader(hanging_get, "Pragma");
|
||||
if (peer_id == my_id) {
|
||||
handleServerNotification(hanging_get.responseText);
|
||||
} else {
|
||||
handlePeerMessage(peer_id, hanging_get.responseText);
|
||||
}
|
||||
}
|
||||
|
||||
if (hanging_get) {
|
||||
hanging_get.abort();
|
||||
hanging_get = null;
|
||||
}
|
||||
|
||||
if (my_id != -1)
|
||||
window.setTimeout(startHangingGet, 0);
|
||||
} catch (e) {
|
||||
trace("Hanging get error: " + e.description);
|
||||
}
|
||||
}
|
||||
|
||||
function onHangingGetTimeout() {
|
||||
trace("hanging get timeout. issuing again.");
|
||||
hanging_get.abort();
|
||||
hanging_get = null;
|
||||
if (my_id != -1)
|
||||
window.setTimeout(startHangingGet, 0);
|
||||
}
|
||||
|
||||
function startHangingGet() {
|
||||
try {
|
||||
hanging_get = new XMLHttpRequest();
|
||||
hanging_get.onreadystatechange = hangingGetCallback;
|
||||
hanging_get.ontimeout = onHangingGetTimeout;
|
||||
hanging_get.open("GET", server + "/wait?peer_id=" + my_id, true);
|
||||
hanging_get.send();
|
||||
} catch (e) {
|
||||
trace("error" + e.description);
|
||||
}
|
||||
}
|
||||
|
||||
function sendToPeer(peer_id, data) {
|
||||
if (my_id == -1) {
|
||||
alert("Not connected");
|
||||
return;
|
||||
}
|
||||
if (peer_id == my_id) {
|
||||
alert("Can't send a message to oneself :)");
|
||||
return;
|
||||
}
|
||||
var r = new XMLHttpRequest();
|
||||
r.open("POST", server + "/message?peer_id=" + my_id + "&to=" + peer_id,
|
||||
false);
|
||||
r.setRequestHeader("Content-Type", "text/plain");
|
||||
r.send(data);
|
||||
r = null;
|
||||
}
|
||||
|
||||
function signInCallback() {
|
||||
try {
|
||||
if (request.readyState == 4) {
|
||||
if (request.status == 200) {
|
||||
var peers = request.responseText.split("\n");
|
||||
my_id = parseInt(peers[0].split(",")[1]);
|
||||
trace("My id: " + my_id);
|
||||
for (var i = 1; i < peers.length; ++i) {
|
||||
if (peers[i].length > 0) {
|
||||
trace("Peer " + i + ": " + peers[i]);
|
||||
var parsed = peers[i].split(",");
|
||||
other_peers[parseInt(parsed[1])] = parsed[0];
|
||||
}
|
||||
}
|
||||
startHangingGet();
|
||||
request = null;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
trace("error: " + e.description);
|
||||
}
|
||||
}
|
||||
|
||||
function signIn() {
|
||||
try {
|
||||
request = new XMLHttpRequest();
|
||||
request.onreadystatechange = signInCallback;
|
||||
request.open("GET", server + "/sign_in?" + local_name, true);
|
||||
request.send();
|
||||
} catch (e) {
|
||||
trace("error: " + e.description);
|
||||
}
|
||||
}
|
||||
|
||||
function connect() {
|
||||
local_name = document.getElementById("local").value.toLowerCase();
|
||||
server = document.getElementById("server").value.toLowerCase();
|
||||
if (local_name.length == 0) {
|
||||
alert("I need a name please.");
|
||||
document.getElementById("local").focus();
|
||||
} else {
|
||||
document.getElementById("connect").disabled = true;
|
||||
document.getElementById("disconnect").disabled = false;
|
||||
signIn();
|
||||
}
|
||||
}
|
||||
|
||||
function disconnect() {
|
||||
if (request) {
|
||||
request.abort();
|
||||
request = null;
|
||||
}
|
||||
|
||||
if (hanging_get) {
|
||||
hanging_get.abort();
|
||||
hanging_get = null;
|
||||
}
|
||||
|
||||
if (my_id != -1) {
|
||||
request = new XMLHttpRequest();
|
||||
request.open("GET", server + "/sign_out?peer_id=" + my_id, false);
|
||||
request.send();
|
||||
request = null;
|
||||
my_id = -1;
|
||||
}
|
||||
|
||||
document.getElementById("connect").disabled = false;
|
||||
document.getElementById("disconnect").disabled = true;
|
||||
}
|
||||
|
||||
function toggleLog()
|
||||
{
|
||||
document.getElementById('debug').hidden =!
|
||||
document.getElementById('debug').hidden;
|
||||
}
|
||||
|
||||
window.onbeforeunload = disconnect;
|
||||
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<table border="0">
|
||||
|
||||
<tr>
|
||||
<th align="left">Local Preview</th>
|
||||
<th align="left">Remote Video</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><video width="320" height="240" id="localView" autoplay="autoplay">
|
||||
</video></td>
|
||||
<td><video width="640" height="480" id="remoteView" autoplay="autoplay">
|
||||
</video></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top">
|
||||
<form>
|
||||
Target peer ID: <input type="text" id="peer_id" size="3" value="1"/><br>
|
||||
<button id="startcall" onclick="startCall();">(4) Start call</button><br>
|
||||
<button id="stopcall" onclick="stopCall();" disabled="true">(5) Stop call
|
||||
</button><br>
|
||||
<!--<input type="button" value="Test 1" onclick="test1()"/><br>-->
|
||||
</form>
|
||||
</td>
|
||||
<td valign="top">
|
||||
<button onclick="toggleExtraButtons();">Toggle extra buttons</button><br>
|
||||
<button id="createPcBtn" onclick="createPeerConnection();" hidden="true">
|
||||
Create peer connection</button><br>
|
||||
<button id="addStreamBtn" onclick="addStream();" hidden="true">Add stream
|
||||
</button><br>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr><td colspan="2">
|
||||
(1) Server: <input type="text" id="server" value="http://localhost:8888" />
|
||||
<br>
|
||||
(2) Your name: <input type="text" id="local" value="responder"/>
|
||||
<button id="connect" onclick="connect();" disabled="true">(3) Connect</button>
|
||||
<button id="disconnect" onclick="disconnect();" disabled="true">(6) Disconnect
|
||||
</button>
|
||||
<br>
|
||||
<br>
|
||||
<button onclick="toggleLog()">Toggle view log</button>
|
||||
<button onclick="document.getElementById('debug').innerHTML='';">Clear log
|
||||
</button>
|
||||
<pre id="debug">
|
||||
</pre>
|
||||
</td></tr>
|
||||
|
||||
</table>
|
||||
</body>
|
||||
<script>
|
||||
// On init, we connect to the server.
|
||||
connect();
|
||||
</script>
|
||||
</html>
|
@ -28,7 +28,7 @@ h1 {font-size: 40 px;}
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
// TODO: Catch more exceptions
|
||||
// TODO(henrikg): Catch more exceptions
|
||||
|
||||
var server;
|
||||
var myId = -1;
|
||||
@ -317,7 +317,7 @@ function onSignalingMessage(msg) {
|
||||
sendToPeer(remoteId, msg);
|
||||
}
|
||||
|
||||
// TODO: Add callbacks onconnecting, onopen and onstatechange.
|
||||
// TODO(henrikg): Add callbacks onconnecting, onopen and onstatechange.
|
||||
|
||||
|
||||
// Server interaction
|
||||
@ -354,8 +354,8 @@ function handlePeerMessage(peer_id, msg) {
|
||||
}
|
||||
trace("Received message from " + peerName + " (ID " + peer_id + "):\n" + msg);
|
||||
// Assuming we receive the message from the peer we want to communicate with.
|
||||
// TODO: Only accept messages from peer we communicate with with if call is
|
||||
// ongoing.
|
||||
// TODO(henrikg): Only accept messages from peer we communicate with with if
|
||||
// call is ongoing.
|
||||
if (msg.search("BYE") == 0) {
|
||||
// Other side has hung up.
|
||||
document.getElementById("hangup").disabled = true;
|
||||
@ -439,7 +439,7 @@ function startHangingGet() {
|
||||
hangingGet.onreadystatechange = hangingGetCallback;
|
||||
hangingGet.ontimeout = onHangingGetTimeout;
|
||||
hangingGet.open("GET", server + "/wait?peer_id=" + myId, true);
|
||||
hangingGet.send();
|
||||
hangingGet.send();
|
||||
} catch (e) {
|
||||
trace_exception(e, "Start hanging get error");
|
||||
}
|
||||
@ -519,8 +519,8 @@ function connect() {
|
||||
alert("I need a name please.");
|
||||
document.getElementById("local").focus();
|
||||
} else {
|
||||
// TODO: Disable connect button here, but we need a timeout and check if we
|
||||
// have connected, if so enable it again.
|
||||
// TODO(henrikg): Disable connect button here, but we need a timeout and
|
||||
// check if we have connected, if so enable it again.
|
||||
signIn();
|
||||
}
|
||||
}
|
||||
@ -530,7 +530,7 @@ function disconnect() {
|
||||
hangUp();
|
||||
|
||||
disconnecting = true;
|
||||
|
||||
|
||||
if (request) {
|
||||
request.abort();
|
||||
request = null;
|
Loading…
x
Reference in New Issue
Block a user