1 // Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 // 3 // Use of this source code is governed by a BSD-style license 4 // that can be found in the LICENSE file in the root of the source 5 // tree. An additional intellectual property rights grant can be found 6 // in the file PATENTS. All contributing project authors may 7 // be found in the AUTHORS file in the root of the source tree. 8 // 9 // A unidirectional video and audio flowing test from bot 1 to bot 2, 10 // and download a file from a server after 2 seconds of establishing 11 // the call. 12 // 13 // The test succeeds after collecting stats for 10 seconds from both bots 14 // and then write these stats to a file. 15 // 16 // Note: the source of the video and audio stream is getUserMedia(). 17 // 18 function testOneWayVideoWithDownloading(test, bot1, bot2) { 19 var report = test.createStatisticsReport("testOneWayVideoWithDownloading"); 20 21 test.wait([ 22 createPeerConnection.bind(bot1), 23 createPeerConnection.bind(bot2) ], 24 onPeerConnectionCreated); 25 26 function createPeerConnection(done) { 27 test.createTurnConfig(onTurnConfig.bind(this), test.fail); 28 29 function onTurnConfig(config) { 30 this.createPeerConnection(config, done, test.fail); 31 }; 32 } 33 34 function onPeerConnectionCreated(pc1, pc2) { 35 test.log("RTC Peers created."); 36 pc1.addEventListener('addstream', test.fail); 37 pc2.addEventListener('addstream', onAddStream); 38 pc1.addEventListener('icecandidate', onIceCandidate.bind(pc2)); 39 pc2.addEventListener('icecandidate', onIceCandidate.bind(pc1)); 40 41 bot1.getUserMedia({video:true, audio:true}, onUserMediaSuccess, test.fail); 42 43 function onUserMediaSuccess(stream) { 44 test.log("User has granted access to local media."); 45 pc1.addStream(stream); 46 bot1.showStream(stream.id, true, true); 47 48 createOfferAndAnswer(pc1, pc2); 49 } 50 } 51 52 function onAddStream(event) { 53 test.log("On Add stream."); 54 bot2.showStream(event.stream.id, true, false); 55 } 56 57 function onIceCandidate(event) { 58 if(event.candidate) { 59 test.log(event.candidate.candidate); 60 this.addIceCandidate(event.candidate, 61 onAddIceCandidateSuccess, test.fail); 62 } 63 64 function onAddIceCandidateSuccess() { 65 test.log("Candidate added successfully"); 66 } 67 } 68 69 function createOfferAndAnswer(pc1, pc2) { 70 test.log("Creating offer."); 71 pc1.createOffer(gotOffer, test.fail); 72 73 function gotOffer(offer) { 74 test.log("Got offer"); 75 pc1.setLocalDescription(offer, onSetSessionDescriptionSuccess, test.fail); 76 pc2.setRemoteDescription(offer, onSetSessionDescriptionSuccess, 77 test.fail); 78 test.log("Creating answer"); 79 pc2.createAnswer(gotAnswer, test.fail); 80 } 81 82 function gotAnswer(answer) { 83 test.log("Got answer"); 84 pc2.setLocalDescription(answer, onSetSessionDescriptionSuccess, 85 test.fail); 86 pc1.setRemoteDescription(answer, onSetSessionDescriptionSuccess, 87 test.fail); 88 collectStats(); 89 90 setTimeout(function() { 91 downloadFile(bot1, "bot1"); 92 downloadFile(bot2, "bot2"); 93 }, 2000); 94 } 95 96 function onSetSessionDescriptionSuccess() { 97 test.log("Set session description success."); 98 } 99 100 function collectStats() { 101 report.collectStatsFromPeerConnection("bot1", pc1); 102 report.collectStatsFromPeerConnection("bot2", pc2); 103 104 setTimeout(function() { 105 report.finish(test.done); 106 }, 10000); 107 } 108 109 function downloadFile(bot, name) { 110 bot.downloadFile("https://test.webrtc.org/test-download-file/9000KB.data", 111 onDownloadSuccess.bind(null, name), test.fail); 112 113 function onDownloadSuccess(name, data) { 114 test.log( name + " downloaded " + 115 Math.round(data.length/(1024*1024)) + "MB."); 116 } 117 } 118 } 119 } 120 121 registerBotTest('testOneWayVideoWithDownloading/chrome-chrome', 122 testOneWayVideoWithDownloading, ['chrome', 'chrome']); 123