blob: a907976384eb2e4feb12b537dbe4213f14de2bb7 [file] [log] [blame]
houssainy@google.com07ca9492014-09-22 13:52:39 +00001// 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//
11// Note: the source of the video and audio stream is getUserMedia().
12//
13// TODO(houssainy): get a condition to terminate the test.
14//
15function testVideoStreaming(bot1, bot2) {
16 var pc1 = null;
17 var pc2 = null;
18
19 test.wait([
20 createPeerConnection.bind(bot1),
21 createPeerConnection.bind(bot2) ],
22 onPeerConnectionCreated);
23
24 function createPeerConnection(done) {
25 this.createPeerConnection(done, test.fail);
26 }
27
28 function onPeerConnectionCreated(peer1, peer2) {
29 test.log("RTC Peers created.");
30 pc1 = peer1;
31 pc2 = peer2;
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();
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() {
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 }
85
86 function onSetSessionDescriptionSuccess() {
87 test.log("Set session description success.");
88 }
89 }
90}
91
92test.wait( [ test.spawnBot.bind(test, "alice"),
93 test.spawnBot.bind(test, "bob") ],
94 testVideoStreaming);