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