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 two way video and audio flowing test between bot 1 and 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 testTwoWayVideoStreaming(test, bot1, bot2) { | |
15 var report = test.createStatisticsReport("two_way_video_streaming"); | |
16 var statsCollector; | |
17 | |
18 test.wait([ | |
19 createPeerConnectionWithLocalStream.bind(bot1), | |
20 createPeerConnectionWithLocalStream.bind(bot2)], | |
21 onPeerConnectionCreated); | |
22 | |
23 function createPeerConnectionWithLocalStream(done) { | |
24 this.getUserMedia({video:true, audio:true}, | |
25 onUserMediaSuccess.bind(this), test.fail); | |
26 | |
27 function onUserMediaSuccess(stream) { | |
28 test.log("User has granted access to local media."); | |
29 test.createTurnConfig(onTurnConfig.bind(this), test.fail); | |
30 | |
31 function onTurnConfig(config) { | |
32 this.createPeerConnection(config, addAndShowStream.bind(this), | |
33 test.fail); | |
34 }; | |
35 | |
36 function addAndShowStream(pc) { | |
37 pc.addStream(stream); | |
38 this.showStream(stream.id, true, true); | |
39 | |
40 done(pc); | |
41 } | |
42 } | |
43 } | |
44 | |
45 function onPeerConnectionCreated(pc1, pc2) { | |
46 test.log("RTC Peers created."); | |
47 pc1.addEventListener('addstream', onAddStream.bind(bot1)); | |
48 pc2.addEventListener('addstream', onAddStream.bind(bot2)); | |
49 pc1.addEventListener('icecandidate', onIceCandidate.bind(pc2)); | |
50 pc2.addEventListener('icecandidate', onIceCandidate.bind(pc1)); | |
51 | |
52 createOfferAndAnswer(pc1, pc2); | |
53 } | |
54 | |
55 function onAddStream(event) { | |
56 test.log("On Add stream."); | |
57 this.showStream(event.stream.id, true, false); | |
58 } | |
59 | |
60 function onIceCandidate(event) { | |
61 if(event.candidate) { | |
62 test.log(event.candidate.candidate); | |
63 this.addIceCandidate(event.candidate, | |
64 onAddIceCandidateSuccess, test.fail); | |
65 }; | |
66 | |
67 function onAddIceCandidateSuccess() { | |
68 test.log("Candidate added successfully"); | |
69 }; | |
70 } | |
71 | |
72 function createOfferAndAnswer(pc1, pc2) { | |
73 test.log("Creating offer."); | |
74 pc1.createOffer(gotOffer, test.fail); | |
75 | |
76 function gotOffer(offer) { | |
77 test.log("Got offer"); | |
78 pc1.setLocalDescription(offer, onSetSessionDescriptionSuccess, test.fail); | |
79 pc2.setRemoteDescription(offer, onSetSessionDescriptionSuccess, | |
80 test.fail); | |
81 test.log("Creating answer"); | |
82 pc2.createAnswer(gotAnswer, test.fail); | |
83 } | |
84 | |
85 function gotAnswer(answer) { | |
86 test.log("Got answer"); | |
87 pc2.setLocalDescription(answer, onSetSessionDescriptionSuccess, | |
88 test.fail); | |
89 pc1.setRemoteDescription(answer, onSetSessionDescriptionSuccess, | |
90 test.fail); | |
91 collectStats(); | |
92 } | |
93 | |
94 function onSetSessionDescriptionSuccess() { | |
95 test.log("Set session description success."); | |
96 } | |
97 | |
98 function collectStats() { | |
99 report.collectStatsFromPeerConnection("bot1", pc1); | |
100 report.collectStatsFromPeerConnection("bot2", pc2); | |
101 | |
102 setTimeout(function() { | |
103 report.finish(test.done); | |
104 }, 10000); | |
105 } | |
106 } | |
107 } | |
108 | |
109 registerBotTest('testTwoWayVideo/android-android', | |
110 testTwoWayVideoStreaming, ['android-chrome', 'android-chrome']); | |
111 registerBotTest('testTwoWayVideo/chrome-chrome', | |
112 testTwoWayVideoStreaming, ['chrome', 'chrome']); | |
OLD | NEW |