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 video conference between 3 bots streaming video and audio between
11 // The test succeeds after establishing the call between the three
14 // Note: the source of the video and audio stream is getUserMedia().
15 function testTwoWayVideoStreaming(test, bot1, bot2, bot3) {
20 createBotPeerConnectionsWithLocalStream.bind(bot1),
21 createBotPeerConnectionsWithLocalStream.bind(bot2),
22 createBotPeerConnectionsWithLocalStream.bind(bot3)],
23 onPeerConnectionCreated);
25 // done() callback is called with list of peers as argument.
26 function createBotPeerConnectionsWithLocalStream(done) {
27 var peerConnections = [];
29 this.getUserMedia({video:true, audio:true},
30 onUserMediaSuccess.bind(this), test.fail);
32 function onUserMediaSuccess(stream) {
33 test.log("User has granted access to local media.");
34 this.showStream(stream.id, true, true);
36 test.createTurnConfig(onTurnConfig.bind(this), test.fail);
38 function onTurnConfig(config) {
39 this.createPeerConnection(config, addStream.bind(this),
41 this.createPeerConnection(config, addStream.bind(this),
45 function addStream(pc) {
47 pc.addEventListener('addstream', onAddStream.bind(this));
49 peerConnections.push(pc);
50 if(peerConnections.length == 2)
51 done(peerConnections);
56 function onPeerConnectionCreated(peerConnections1,
57 peerConnections2, peerConnections3) {
58 test.log("RTC Peers created.");
61 establichCall(peerConnections1[0], peerConnections2[1]);
63 establichCall(peerConnections2[0], peerConnections3[1]);
65 establichCall(peerConnections3[0], peerConnections1[1]);
68 function establichCall(pc1, pc2) {
69 pc1.addEventListener('icecandidate', onIceCandidate.bind(pc2));
70 pc2.addEventListener('icecandidate', onIceCandidate.bind(pc1));
72 createOfferAndAnswer(pc1, pc2);
75 function onAddStream(event) {
76 test.log("On Add stream.");
77 this.showStream(event.stream.id, true, false);
80 function onIceCandidate(event) {
82 this.addIceCandidate(event.candidate,
83 onAddIceCandidateSuccess, test.fail);
86 function onAddIceCandidateSuccess() {
87 test.log("Candidate added successfully");
91 function createOfferAndAnswer(pc1, pc2) {
92 test.log("Creating offer.");
93 pc1.createOffer(gotOffer, test.fail);
95 function gotOffer(offer) {
96 test.log("Got offer");
97 pc1.setLocalDescription(offer, onSetSessionDescriptionSuccess, test.fail);
98 pc2.setRemoteDescription(offer, onSetSessionDescriptionSuccess,
100 test.log("Creating answer");
101 pc2.createAnswer(gotAnswer, test.fail);
104 function gotAnswer(answer) {
105 test.log("Got answer");
106 pc2.setLocalDescription(answer, onSetSessionDescriptionSuccess,
108 pc1.setRemoteDescription(answer, onSetSessionDescriptionSuccess,
112 if(answersCount == 3) {
113 // SetTimeout used because creating the three answers will very fast
114 // and test will success and the vm will be closed before establishing
116 setTimeout(function() {
122 function onSetSessionDescriptionSuccess() {
123 test.log("Set session description success.");
128 registerBotTest('threeBotsVideoConference/android+android+chrome',
129 testTwoWayVideoStreaming, ['android-chrome', 'android-chrome',
131 registerBotTest('threeBotsVideoConference/chrome-chrome-chrome',
132 testTwoWayVideoStreaming, ['chrome', 'chrome', 'chrome']);
133 registerBotTest('threeBotsVideoConference/android-android-android',
134 testTwoWayVideoStreaming, ['android-chrome', 'android-chrome',