1 // Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
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.
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.
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");
18 createPeerConnection.bind(bot1),
19 createPeerConnection.bind(bot2) ],
20 onPeerConnectionCreated);
22 function createPeerConnection(done) {
23 test.createTurnConfig(onTurnConfig.bind(this), test.fail);
25 function onTurnConfig(config) {
26 this.createPeerConnection(config, done, test.fail);
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));
37 bot1.getUserMedia({video:true, audio:true}, onUserMediaSuccess, test.fail);
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);
44 createOfferAndAnswer(pc1, pc2);
48 function onAddStream(event) {
49 test.log("On Add stream.");
50 bot2.showStream(event.stream.id, true, false);
53 function onIceCandidate(event) {
55 test.log(event.candidate.candidate);
56 this.addIceCandidate(event.candidate,
57 onAddIceCandidateSuccess, test.fail);
60 function onAddIceCandidateSuccess() {
61 test.log("Candidate added successfully");
65 function createOfferAndAnswer(pc1, pc2) {
66 test.log("Creating offer.");
67 pc1.createOffer(gotOffer, test.fail);
69 function gotOffer(offer) {
70 test.log("Got offer");
71 pc1.setLocalDescription(offer, onSetSessionDescriptionSuccess, test.fail);
72 pc2.setRemoteDescription(offer, onSetSessionDescriptionSuccess,
74 test.log("Creating answer");
75 pc2.createAnswer(gotAnswer, test.fail);
78 function gotAnswer(answer) {
79 test.log("Got answer");
80 pc2.setLocalDescription(answer, onSetSessionDescriptionSuccess,
82 pc1.setRemoteDescription(answer, onSetSessionDescriptionSuccess,
87 function onSetSessionDescriptionSuccess() {
88 test.log("Set session description success.");
91 function collectStats() {
92 report.collectStatsFromPeerConnection("bot1", pc1);
93 report.collectStatsFromPeerConnection("bot2", pc2);
95 setTimeout(function() {
96 report.finish(test.done);
102 registerBotTest('testOneWayVideo/chrome-chrome',
103 testOneWayVideo, ['chrome', 'chrome']);