Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 128 lines (102 sloc) 3.299 kb
2f4da79 Anant Narayanan Add constraints test
authored
1 <html>
2 <head>
3 <title>Simple PeerConnection Constraints Test</title>
4 </head>
5 <body>
6
7 <h1>Simple PeerConnection Constraints Test</h1>
8
9 <div><video id="pc1video" width="640" height="480" controls></video></div><br/>
10 <div><video id="pc2video" width="640" height="480" controls></video></div><br/>
11
12 <div><button id="tehbutton" onClick="start();">Start!</button></div><br/>
13 <div id="log"></div>
14
15 <div><video id="localvideo" width="640" height="480" controls></video></div><br/>
16
17 <script type="application/javascript;version=1.8">
18 function log(msg) {
19 let div = document.getElementById("log");
20 div.innerHTML = div.innerHTML + "<p>" + msg + "</p>";
21 }
22
23 let pc1video = document.getElementById("pc1video");
24 let pc2video = document.getElementById("pc2video");
25
26 let button = document.getElementById("tehbutton");
27 let localvideo = document.getElementById("localvideo");
28
29 let pc1;
30 let pc2;
31
32 let pc1_offer;
33 let pc2_answer;
34
35 function failed(code) {
36 log("Failure callback: " + code);
37 }
38
39 // pc1.createOffer finished, call pc1.setLocal
40 function step1(offer) {
41 pc1_offer = offer;
42 pc1.setLocalDescription(offer, step2, failed);
43 }
44
45 // pc1.setLocal finished, call pc2.setRemote
46 function step2() {
47 pc2.setRemoteDescription(pc1_offer, step3, failed);
48 };
49
50 // pc2.setRemote finished, call pc2.createAnswer
51 function step3() {
52 pc2.createAnswer(step4, failed, {
f734461 Anant Narayanan Add pause/stop support
authored
53 "optional": [
2f4da79 Anant Narayanan Add constraints test
authored
54 {"OfferToReceiveAudio": true},
55 {"OfferToReceiveVideo": true}
56 ]
57 });
58 }
59
60 // pc2.createAnswer finished, call pc2.setLocal
61 function step4(answer) {
62 pc2_answer = answer;
63 pc2.setLocalDescription(answer, step5, failed);
64 }
65
66 // pc2.setLocal finished, call pc1.setRemote
67 function step5() {
68 pc1.setRemoteDescription(pc2_answer, step6, failed);
69 }
70
71 // pc1.setRemote finished, media should be running!
72 function step6() {
73 log("HIP HIP HOORAY");
74 }
75
76 function start() {
77 button.innerHTML = "Stop!";
78 button.onclick = stop;
79
80 pc1 = new mozRTCPeerConnection();
81 pc2 = new mozRTCPeerConnection();
82
83 pc1.onaddstream = function(obj) {
84 log("pc1 got remote stream from pc2 " + obj.type);
85 pc2video.mozSrcObject = obj.stream;
86 pc2video.play();
87 }
88 pc2.onaddstream = function(obj) {
89 log("pc2 got remote stream from pc1 " + obj.type);
90 pc1video.mozSrcObject = obj.stream;
91 pc1video.play();
92 }
93
94 navigator.mozGetUserMedia({video:true}, function(video1) {
95 // Add stream obtained from gUM to <video> to start media flow.
96 localvideo.mozSrcObject = video1;
97 localvideo.play();
98 pc1.addStream(video1);
99
100 navigator.mozGetUserMedia({audio:true, fake:true}, function(audio1) {
101 pc1.addStream(audio1);
102 pc2.addStream(audio1);
103
104 navigator.mozGetUserMedia({video:true, fake:true}, function(video2) {
105 pc2.addStream(video2);
106 // Start the signaling.
107 pc1.createOffer(step1, failed, {
108 optional: [
109 {"OfferToReceiveAudio": true},
110 {"OfferToReceiveVideo": true}
111 ]
112 });
113 }, failed);
114 }, failed);
115 }, failed);
116 }
117
118 function stop() {
119 pc1.close();
120 pc2.close();
121
122 button.innerHTML = "Start!";
123 button.onclick = start;
124 }
125 </script>
126
127 </html>
Something went wrong with that request. Please try again.