diff --git a/webrtc/tools/rtcbot/README b/webrtc/tools/rtcbot/README index 8b5bab10cd..72f9f63f87 100644 --- a/webrtc/tools/rtcbot/README +++ b/webrtc/tools/rtcbot/README @@ -17,12 +17,7 @@ access its exposed API. Details are in botmanager.js. == How to run the test == $ cd trunk/webrtc/tool/rtcbot $ npm install express browserify ws websocket-stream dnode - $ node test.js - - — the type of the running bot. For example: - - chrome: chrome on host machine. - - android: android device. Details in "Android" Section. - - android-chrome: chrome on android device. Details in "Android" Section. + $ node test.js == Example on how to install nodejs == $ cd /work/tools/ @@ -31,6 +26,12 @@ access its exposed API. Details are in botmanager.js. $ nvm install 0.10 $ nvm use 0.10 +== Supported Bot Types == + - "chrome": chrome on host machine. + - "android-chrome": chrome on android device. Details in "Android" Section. + + * Bot type is specified for each spawned bot in the test file. + == Android == Before running test with Android one MUST forward the device port 8080 to the host machine. That is easy to achieve with chrome port forwarding tools. diff --git a/webrtc/tools/rtcbot/bot/browser/bot.js b/webrtc/tools/rtcbot/bot/browser/bot.js index 808d88a8b1..f278d893b5 100644 --- a/webrtc/tools/rtcbot/bot/browser/bot.js +++ b/webrtc/tools/rtcbot/bot/browser/bot.js @@ -25,10 +25,10 @@ function getUserMedia(constraints, onSuccessCallback, onFailCallback){ } } -function createPeerConnection(doneCallback, failCallback) { +function createPeerConnection(config, doneCallback, failCallback) { console.log("Creating peer connection"); var obj = {}; - var pc = new webkitRTCPeerConnection(null); + var pc = new webkitRTCPeerConnection(config); expose(obj, pc, "close"); expose(obj, pc, "createOffer"); @@ -113,9 +113,38 @@ function getStreamFromIdentifier_(id) { return null; }; +// Ask computeengineondemand to give us TURN server credentials and URIs. +function asyncCreateTurnConfig(onSuccess, onError) { + var CEOD_URL = ('https://computeengineondemand.appspot.com/turn?' + + 'username=1234&key=5678'); + var xhr = new XMLHttpRequest(); + function onResult() { + if (xhr.readyState != 4) + return; + + if (xhr.status != 200) { + onError('TURN request failed'); + return; + } + + var response = JSON.parse(xhr.responseText); + var iceServer = { + 'username': response.username, + 'credential': response.password, + 'urls': response.uris + }; + onSuccess({ 'iceServers': [ iceServer ] }); + } + + xhr.onreadystatechange = onResult; + xhr.open('GET', CEOD_URL, true); + xhr.send(); +}; + connectToServer({ ping: ping, getUserMedia: getUserMedia, createPeerConnection: createPeerConnection, showStream: showStream, + asyncCreateTurnConfig: asyncCreateTurnConfig, }); diff --git a/webrtc/tools/rtcbot/test.js b/webrtc/tools/rtcbot/test.js index 785d5e89d5..e1173985d3 100644 --- a/webrtc/tools/rtcbot/test.js +++ b/webrtc/tools/rtcbot/test.js @@ -16,11 +16,10 @@ var fs = require('fs'); var vm = require('vm'); var BotManager = require('./botmanager.js'); -function Test(botType) { +function Test() { this.timeout_ = setTimeout( this.fail.bind(this, "Test timeout!"), 100000); - this.botType_ = botType; } Test.prototype = { @@ -67,11 +66,11 @@ Test.prototype = { } }, - spawnBot: function (name, doneCallback) { + spawnBot: function (name, botType, doneCallback) { // Lazy initialization of botmanager. if (!this.botManager_) this.botManager_ = new BotManager(); - this.botManager_.spawnNewBot(name, this.botType_, doneCallback); + this.botManager_.spawnNewBot(name, botType, doneCallback); }, createStatisticsReport: function (outputFileName) { @@ -137,11 +136,11 @@ StatisticsReport.prototype = { }, } -function runTest(botType, testfile) { +function runTest(testfile) { console.log("Running test: " + testfile); var script = vm.createScript(fs.readFileSync(testfile), testfile); - script.runInNewContext({ test: new Test(botType), setInterval: setInterval, + script.runInNewContext({ test: new Test(), setInterval: setInterval, setTimeout: setTimeout }); } -runTest(process.argv[2], process.argv[3]); +runTest(process.argv[2]); diff --git a/webrtc/tools/rtcbot/test/ping_pong.js b/webrtc/tools/rtcbot/test/ping_pong.js index e519738be9..feee3bcb9b 100644 --- a/webrtc/tools/rtcbot/test/ping_pong.js +++ b/webrtc/tools/rtcbot/test/ping_pong.js @@ -16,4 +16,4 @@ function testPingPong(bot) { } } -test.spawnBot("alice", testPingPong); +test.spawnBot("alice", "chrome", testPingPong); diff --git a/webrtc/tools/rtcbot/test/simple_offer_answer.js b/webrtc/tools/rtcbot/test/simple_offer_answer.js index 61eb0bafab..e052598922 100644 --- a/webrtc/tools/rtcbot/test/simple_offer_answer.js +++ b/webrtc/tools/rtcbot/test/simple_offer_answer.js @@ -17,7 +17,7 @@ function testOfferAnswer(peer1, peer2) { establishCall); function createPeerConnection(done) { - this.createPeerConnection(done, test.fail); + this.createPeerConnection(null, done, test.fail); } function establishCall(pc1, pc2) { @@ -49,6 +49,6 @@ function expectedCall() { test.done(); } -test.wait( [ test.spawnBot.bind(test, "alice"), - test.spawnBot.bind(test, "bob") ], +test.wait( [ test.spawnBot.bind(test, "alice", "chrome"), + test.spawnBot.bind(test, "bob", "chrome") ], testOfferAnswer); diff --git a/webrtc/tools/rtcbot/test/webrtc_video_streaming.js b/webrtc/tools/rtcbot/test/webrtc_video_streaming.js index 7b0457c96a..62b7056b20 100644 --- a/webrtc/tools/rtcbot/test/webrtc_video_streaming.js +++ b/webrtc/tools/rtcbot/test/webrtc_video_streaming.js @@ -24,7 +24,9 @@ function testVideoStreaming(bot1, bot2) { onPeerConnectionCreated); function createPeerConnection(done) { - this.createPeerConnection(done, test.fail); + this.asyncCreateTurnConfig(function(config) { + this.createPeerConnection(config, done, test.fail); + }.bind(this), test.fail); } function onPeerConnectionCreated(peer1, peer2) { @@ -101,6 +103,6 @@ function testVideoStreaming(bot1, bot2) { } } -test.wait( [ test.spawnBot.bind(test, "alice"), - test.spawnBot.bind(test, "bob") ], +test.wait( [ test.spawnBot.bind(test, "alice", "chrome"), + test.spawnBot.bind(test, "bob", "android-chrome") ], testVideoStreaming);