| OLD | NEW |
| (Empty) |
| 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 // The test succeeds after collecting stats for 10 seconds from both bots | |
| 11 // and then write these stats to a file. | |
| 12 // | |
| 13 // Note: the source of the video and audio stream is getUserMedia(). | |
| 14 function testOneWayVideo(test, bot1, bot2) { | |
| 15 var report = test.createStatisticsReport("webrtc_video_streaming"); | |
| 16 | |
| 17 test.wait([ | |
| 18 createPeerConnection.bind(bot1), | |
| 19 createPeerConnection.bind(bot2) ], | |
| 20 onPeerConnectionCreated); | |
| 21 | |
| 22 function createPeerConnection(done) { | |
| 23 test.createTurnConfig(onTurnConfig.bind(this), test.fail); | |
| 24 | |
| 25 function onTurnConfig(config) { | |
| 26 this.createPeerConnection(config, done, test.fail); | |
| 27 }; | |
| 28 } | |
| 29 | |
| 30 function onPeerConnectionCreated(pc1, pc2) { | |
| 31 test.log("RTC Peers created."); | |
| 32 pc1.addEventListener('addstream', test.fail); | |
| 33 pc2.addEventListener('addstream', onAddStream); | |
| 34 pc1.addEventListener('icecandidate', onIceCandidate.bind(pc2)); | |
| 35 pc2.addEventListener('icecandidate', onIceCandidate.bind(pc1)); | |
| 36 | |
| 37 bot1.getUserMedia({video:true, audio:true}, onUserMediaSuccess, test.fail); | |
| 38 | |
| 39 function onUserMediaSuccess(stream) { | |
| 40 test.log("User has granted access to local media."); | |
| 41 pc1.addStream(stream); | |
| 42 bot1.showStream(stream.id, true, true); | |
| 43 | |
| 44 createOfferAndAnswer(pc1, pc2); | |
| 45 } | |
| 46 } | |
| 47 | |
| 48 function onAddStream(event) { | |
| 49 test.log("On Add stream."); | |
| 50 bot2.showStream(event.stream.id, true, false); | |
| 51 } | |
| 52 | |
| 53 function onIceCandidate(event) { | |
| 54 if(event.candidate) { | |
| 55 test.log(event.candidate.candidate); | |
| 56 this.addIceCandidate(event.candidate, | |
| 57 onAddIceCandidateSuccess, test.fail); | |
| 58 } | |
| 59 | |
| 60 function onAddIceCandidateSuccess() { | |
| 61 test.log("Candidate added successfully"); | |
| 62 } | |
| 63 } | |
| 64 | |
| 65 function createOfferAndAnswer(pc1, pc2) { | |
| 66 test.log("Creating offer."); | |
| 67 pc1.createOffer(gotOffer, test.fail); | |
| 68 | |
| 69 function gotOffer(offer) { | |
| 70 test.log("Got offer"); | |
| 71 pc1.setLocalDescription(offer, onSetSessionDescriptionSuccess, test.fail); | |
| 72 pc2.setRemoteDescription(offer, onSetSessionDescriptionSuccess, | |
| 73 test.fail); | |
| 74 test.log("Creating answer"); | |
| 75 pc2.createAnswer(gotAnswer, test.fail); | |
| 76 } | |
| 77 | |
| 78 function gotAnswer(answer) { | |
| 79 test.log("Got answer"); | |
| 80 pc2.setLocalDescription(answer, onSetSessionDescriptionSuccess, | |
| 81 test.fail); | |
| 82 pc1.setRemoteDescription(answer, onSetSessionDescriptionSuccess, | |
| 83 test.fail); | |
| 84 collectStats(); | |
| 85 } | |
| 86 | |
| 87 function onSetSessionDescriptionSuccess() { | |
| 88 test.log("Set session description success."); | |
| 89 } | |
| 90 | |
| 91 function collectStats() { | |
| 92 report.collectStatsFromPeerConnection("bot1", pc1); | |
| 93 report.collectStatsFromPeerConnection("bot2", pc2); | |
| 94 | |
| 95 setTimeout(function() { | |
| 96 report.finish(test.done); | |
| 97 }, 10000); | |
| 98 } | |
| 99 } | |
| 100 } | |
| 101 | |
| 102 registerBotTest('testOneWayVideo/chrome-chrome', | |
| 103 testOneWayVideo, ['chrome', 'chrome']); | |
| OLD | NEW |