forked from mozilla/webrtc-landing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pc_test.html
602 lines (544 loc) · 21.4 KB
/
pc_test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>Simple RTCPeerConnection Video Test</title>
<style>
#player1 {
position:relative;
width:640px;
height:480px;
float:right;
}
#player2 {
position:relative;
width:640px;
height:480px;
float:left;
}
#mainvideo {
position:absolute;
top:0;
left:0;
z-index:0;
}
#localvideo1, #localvideo2 {
position:absolute;
top:0;
left:0;
z-index:1;
}
.hidden
{
display: none;
}
</style>
</head>
<body>
<h1>Simple RTCPeerConnection Video Test</h1>
<div>
<div id="pc_warn" class="hidden">
<font color="red">
<h4>RTCPeerConnection is missing!</h4>
This page only works when loaded loaded <a href="https://mozilla.github.io/webrtc-landing/pc_test.html">via HTTPS</a> as RTCPeerConnectio() is only available via HTTPS.<br><br>
</font>
</div>
<button id="tehbutton" onclick="start();">Start!</button>
<input type="checkbox" id="fake" value="Use Fake Video/Audio for one stream">
<label for="fake">Use Fake Audio/Video for one stream</label>
<input type="checkbox" id="oneway" value="one-way call">
<label for="oneway">One-way call</label>
<input type="checkbox" id="audio_only" value="Audio-only call">
<label for="audio_only">Audio-only call</label>
<input type="checkbox" id="video_only" value="Video-only call">
<label for="video_only">Video-only call</label>
<br>
<input type="checkbox" id="disable_video" value="Disable video" onclick="disable_media(pc1, 1, 0);">
<label for="disable_video">Disable video</label>
<input type="checkbox" id="disable_audio" value="Disable audio" onclick="disable_media(pc1, 0, 0);">
<label for="disable_audio">Disable audio</label>
<input type="checkbox" id="requireh264" value="Require H.264" onclick="h264StateChange(this);">
<label for="requireh264">Require H.264 video</label>
<input type="checkbox" id="requirevp9" value="Require VP9">
<label for="requirevp9">Require VP9 video</label>
<input type="checkbox" id="requirevp8" value="Require VP8">
<label for="requirevp8">Require VP8 video</label>
<input type="checkbox" id="requireg722" value="Require G.722">
<label for="requireg722">Require G.722 audio</label>
<br>
<input type="number" id="tias" value="TIAS setting">
<label for="tias">TIAS for video</label>
<input type="text" id="video_constraints" value="">
<label for="video_constraints">Video Constraints in JSON (use quotes!)</label>
<div id="divH264" class="hidden">
<br>
<input type="checkbox" id="prefermode0" value="Prefer Mode 0">
<label for="prefermode0">Prefer H.264 Mode 0</label>
</div>
<div id="idpDetails">
<input type="checkbox" id="idp" value="IDP enable">
<label for="idp">Enable Identity Provider</label>:
<label for="idpdomain">Domain</label>
<input type="text" id="idpdomain" value="martinthomson.github.io">
<label for="idpprotocol">Protocol</label>
<input type="text" id="idpprotocol" value="idp.js">
<label for="idpusera">User A Name</label>
<input type="text" id="idpusera" value="">
<label for="idpuserb">User B Name</label>
<input type="text" id="idpuserb" value="">
</div>
</div><br>
<div>
<div id="player1">
<video tabindex="0" id="pc1video" class="mainvideo" controls="controls" height="480" width="640" muted></video>
<video tabindex="0" id="localvideo1" controls="controls" height="120" width="160" muted></video></div>
<div id="player2">
<video tabindex="0" id="pc2video" class="mainvideo" controls="controls" height="480" width="640" muted></video>
<video tabindex="0" id="localvideo2" controls="controls" height="120" width="160" muted></video></div><br>
<br style="clear: left;" />
</div>
<div id="log"></div>
<script type="application/javascript">
if (!window.RTCPeerConnection) {
document.getElementById("pc_warn").style.display = "block";
}
// Lame clone function. Not efficient but we don't have jQuery.
function copy_dictionary (obj) {
return JSON.parse(JSON.stringify(obj));
}
function log(msg) {
let div = document.getElementById("log");
div.innerHTML = div.innerHTML + "<p>" + msg + "</p>";
}
let pc1video = document.getElementById("pc1video");
let pc2video = document.getElementById("pc2video");
pc1video.onplay = function() {log("Play for pc1");};
pc2video.onplay = function() {log("Play for pc2");};
let button = document.getElementById("tehbutton");
let localvideo1 = document.getElementById("localvideo1");
let localvideo2 = document.getElementById("localvideo2");
let fake = document.getElementById("fake");
fake.checked = true;
let oneway = document.getElementById("oneway");
oneway.checked = false;
let audio_only = document.getElementById("audio_only");
audio_only.checked = false;
let video_only = document.getElementById("video_only");
video_only.checked = false;
let video_disable = document.getElementById("disable_video");
let audio_disable = document.getElementById("disable_audio");
let requireh264 = document.getElementById("requireh264");
requireh264.checked = false;
let requirevp9 = document.getElementById("requirevp9");
requirevp9.checked = false;
let requirevp8 = document.getElementById("requirevp8");
requirevp8.checked = false;
let prefermode0 = document.getElementById("prefermode0");
prefermode0.checked = false;
let requireg722 = document.getElementById("requireg722");
requireg722.checked = false;
let idpenabled = document.getElementById("idp");
idpenabled.checked = false;
let video_constraints = document.getElementById("video_constraints");
let tias = document.getElementById("tias");
tias.value = 0;
let pc1;
let pc2;
let pc1_offer;
let pc2_answer;
let offer_constraints;
let answer_constraints;
function disable_media(pc, type, array_index) {
log("disable_media");
var stream;
if (pc == pc1)
stream = localvideo1.srcObject;
else if (pc == pc2)
stream = localvideo2.srcObject;
else log("bad pc " + pc);
if (stream) {
log("track[" + array_index + "] = " + stream.getVideoTracks()[array_index]);
if (type == 1)
stream.getVideoTracks()[array_index].enabled = !video_disable.checked;
else if (type == 0)
stream.getAudioTracks()[array_index].enabled = !audio_disable.checked;
else
log("bad type");
}
else
log("no stream");
}
function failed(code) {
var err = code.message || code;
console.log(err);
log("Failure callback: " + JSON.stringify(err));
}
// replace CR NL with HTML breaks
function sdpPrettyPrint(sdp) {
return sdp.replace(/[\r\n]+/g, '<br>');
}
function h264StateChange(cb)
{
var h264opts = document.getElementById('divH264');
if(cb.checked){
h264opts.style.display = 'block';
} else {
h264opts.style.display = 'none';
}
}
// XXX write function removeAllBut(sdp, payload) and delete these
// Also remove mode 0 if it's offered
// Note, we don't bother removing the fmtp lines, which makes a good test
// for some SDP parsing issues.
function removeAllButH264(sdp) {
updated_sdp = sdp.replace("a=rtpmap:120 VP8/90000\r\n","");
updated_sdp = updated_sdp.replace("a=rtpmap:121 VP9/90000\r\n","");
updated_sdp = updated_sdp.replace(/m=video ([0-9]+) UDP\/TLS\/RTP\/SAVPF ([0-9 ]*) 120/g, "m=video $1 UDP\/TLS\/RTP\/SAVPF $2");
updated_sdp = updated_sdp.replace(/m=video ([0-9]+) UDP\/TLS\/RTP\/SAVPF 120([0-9 ]*)/g, "m=video $1 UDP\/TLS\/RTP\/SAVPF$2");
updated_sdp = updated_sdp.replace(/m=video ([0-9]+) UDP\/TLS\/RTP\/SAVPF ([0-9 ]*) 121/g, "m=video $1 UDP\/TLS\/RTP\/SAVPF $2");
updated_sdp = updated_sdp.replace(/m=video ([0-9]+) UDP\/TLS\/RTP\/SAVPF 121([0-9 ]*)/g, "m=video $1 UDP\/TLS\/RTP\/SAVPF$2");
updated_sdp = updated_sdp.replace("a=rtcp-fb:120 goog-remb\r\n","");
updated_sdp = updated_sdp.replace("a=rtcp-fb:120 nack\r\n","");
updated_sdp = updated_sdp.replace("a=rtcp-fb:120 nack pli\r\n","");
updated_sdp = updated_sdp.replace("a=rtcp-fb:120 ccm fir\r\n","");
updated_sdp = updated_sdp.replace("a=rtcp-fb:121 goog-remb\r\n","");
updated_sdp = updated_sdp.replace("a=rtcp-fb:121 nack\r\n","");
updated_sdp = updated_sdp.replace("a=rtcp-fb:121 nack pli\r\n","");
updated_sdp = updated_sdp.replace("a=rtcp-fb:121 ccm fir\r\n","");
return updated_sdp;
}
function removeAllButVP9(sdp) {
updated_sdp = sdp.replace("a=rtpmap:120 VP8/90000\r\n","");
updated_sdp = updated_sdp.replace("a=rtpmap:126 H264/90000\r\n","");
updated_sdp = updated_sdp.replace("a=rtpmap:97 H264/90000\r\n","");
updated_sdp = updated_sdp.replace(/m=video ([0-9]+) UDP\/TLS\/RTP\/SAVPF ([0-9 ]*) 120/g, "m=video $1 UDP\/TLS\/RTP\/SAVPF $2");
updated_sdp = updated_sdp.replace(/m=video ([0-9]+) UDP\/TLS\/RTP\/SAVPF 120([0-9 ]*)/g, "m=video $1 UDP\/TLS\/RTP\/SAVPF$2");
updated_sdp = updated_sdp.replace(/m=video ([0-9]+) UDP\/TLS\/RTP\/SAVPF ([0-9 ]*) 126/g, "m=video $1 UDP\/TLS\/RTP\/SAVPF $2");
updated_sdp = updated_sdp.replace(/m=video ([0-9]+) UDP\/TLS\/RTP\/SAVPF 126([0-9 ]*)/g, "m=video $1 UDP\/TLS\/RTP\/SAVPF$2");
updated_sdp = updated_sdp.replace(/m=video ([0-9]+) UDP\/TLS\/RTP\/SAVPF ([0-9 ]*) 97/g, "m=video $1 UDP\/TLS\/RTP\/SAVPF $2");
updated_sdp = updated_sdp.replace(/m=video ([0-9]+) UDP\/TLS\/RTP\/SAVPF 97([0-9 ]*)/g, "m=video $1 UDP\/TLS\/RTP\/SAVPF$2");
updated_sdp = updated_sdp.replace("a=rtcp-fb:120 goog-remb\r\n","");
updated_sdp = updated_sdp.replace("a=rtcp-fb:120 nack\r\n","");
updated_sdp = updated_sdp.replace("a=rtcp-fb:120 nack pli\r\n","");
updated_sdp = updated_sdp.replace("a=rtcp-fb:120 ccm fir\r\n","");
updated_sdp = updated_sdp.replace("a=rtcp-fb:126 goog-remb\r\n","");
updated_sdp = updated_sdp.replace("a=rtcp-fb:126 nack\r\n","");
updated_sdp = updated_sdp.replace("a=rtcp-fb:126 nack pli\r\n","");
updated_sdp = updated_sdp.replace("a=rtcp-fb:126 ccm fir\r\n","");
updated_sdp = updated_sdp.replace("a=rtcp-fb:97 goog-remb\r\n","");
updated_sdp = updated_sdp.replace("a=rtcp-fb:97 nack\r\n","");
updated_sdp = updated_sdp.replace("a=rtcp-fb:97 nack pli\r\n","");
updated_sdp = updated_sdp.replace("a=rtcp-fb:97 ccm fir\r\n","");
return updated_sdp;
}
function removeAllButVP8(sdp) {
updated_sdp = sdp.replace("a=rtpmap:121 VP9/90000\r\n","");
updated_sdp = updated_sdp.replace("a=rtpmap:126 H264/90000\r\n","");
updated_sdp = updated_sdp.replace("a=rtpmap:97 H264/90000\r\n","");
updated_sdp = updated_sdp.replace(/m=video ([0-9]+) UDP\/TLS\/RTP\/SAVPF ([0-9 ]*) 121/g, "m=video $1 UDP\/TLS\/RTP\/SAVPF $2");
updated_sdp = updated_sdp.replace(/m=video ([0-9]+) UDP\/TLS\/RTP\/SAVPF 120([0-9 ]*)/g, "m=video $1 UDP\/TLS\/RTP\/SAVPF$2");
updated_sdp = updated_sdp.replace(/m=video ([0-9]+) UDP\/TLS\/RTP\/SAVPF ([0-9 ]*) 126/g, "m=video $1 UDP\/TLS\/RTP\/SAVPF $2");
updated_sdp = updated_sdp.replace(/m=video ([0-9]+) UDP\/TLS\/RTP\/SAVPF 126([0-9 ]*)/g, "m=video $1 UDP\/TLS\/RTP\/SAVPF$2");
updated_sdp = updated_sdp.replace(/m=video ([0-9]+) UDP\/TLS\/RTP\/SAVPF ([0-9 ]*) 97/g, "m=video $1 UDP\/TLS\/RTP\/SAVPF $2");
updated_sdp = updated_sdp.replace(/m=video ([0-9]+) UDP\/TLS\/RTP\/SAVPF 97([0-9 ]*)/g, "m=video $1 UDP\/TLS\/RTP\/SAVPF$2");
updated_sdp = updated_sdp.replace("a=rtcp-fb:121 goog-remb\r\n","");
updated_sdp = updated_sdp.replace("a=rtcp-fb:121 nack\r\n","");
updated_sdp = updated_sdp.replace("a=rtcp-fb:121 nack pli\r\n","");
updated_sdp = updated_sdp.replace("a=rtcp-fb:121 ccm fir\r\n","");
updated_sdp = updated_sdp.replace("a=rtcp-fb:126 goog-remb\r\n","");
updated_sdp = updated_sdp.replace("a=rtcp-fb:126 nack\r\n","");
updated_sdp = updated_sdp.replace("a=rtcp-fb:126 nack pli\r\n","");
updated_sdp = updated_sdp.replace("a=rtcp-fb:126 ccm fir\r\n","");
updated_sdp = updated_sdp.replace("a=rtcp-fb:97 goog-remb\r\n","");
updated_sdp = updated_sdp.replace("a=rtcp-fb:97 nack\r\n","");
updated_sdp = updated_sdp.replace("a=rtcp-fb:97 nack pli\r\n","");
updated_sdp = updated_sdp.replace("a=rtcp-fb:97 ccm fir\r\n","");
return updated_sdp;
}
// Remove anything that's not G.722 from the m=audio line
function removeNonG722(sdp) {
updated_sdp = sdp.replace(/m=audio ([0-9]+) RTP\/SAVPF ([0-9 ]*)/g, "m=audio $1 RTP\/SAVPF 9");
updated_sdp = updated_sdp.replace(/m=audio ([0-9]+) UDP\/TLS\/RTP\/SAVPF ([0-9 ]*)/g, "m=audio $1 UDP\/TLS\/RTP\/SAVPF 9");
return updated_sdp;
}
function preferMode0(sdp) {
updated_sdp = updated_sdp.replace("126 97", "97 126");
return updated_sdp;
}
function addTIAS(sdp, value) {
updated_sdp = sdp.replace(/m=video (.*)\r\n/g,
"m=video $1\r\nb=TIAS:" + value + "\r\n");
return updated_sdp;
}
// pc1.createOffer finished, call pc1.setLocal
function offerSetLocal(offer) {
log("Offer: " + sdpPrettyPrint(offer.sdp));
pc1_offer = offer;
if (requirevp9.checked) {
// to enforce the usage of vp9 we remove the VP8 & H264 codecs from the offer
offer.sdp = removeAllButVP9(offer.sdp);
pc1_offer = offer;
if (!offer.sdp.match(/a=rtpmap:[0-9]+ VP9/g)) {
log("No VP9 found in the offer!!!");
return Promise.reject();
}
} else if (requirevp8.checked) {
// to enforce the usage of vp8 we remove the VP9 & H264 codecs from the offer
offer.sdp = removeAllButVP8(offer.sdp);
pc1_offer = offer;
if (!offer.sdp.match(/a=rtpmap:[0-9]+ VP8/g)) {
log("No VP8 found in the offer!!!");
return Promise.reject();
}
} else if (requireh264.checked) {
// to enforce the usage of H264 we remove the VP8 & VP9 codecs from the offer
offer.sdp = removeAllButH264(offer.sdp);
if (prefermode0.checked) {
offer.sdp = preferMode0(offer.sdp);
}
pc1_offer = offer;
if (!offer.sdp.match(/a=rtpmap:[0-9]+ H264/g)) {
log("No H264 found in the offer!!!");
return Promise.reject();
}
}
if (requireg722.checked) {
// to enforce the usage of G.722 we remove other codecs from the offer
offer.sdp = removeNonG722(offer.sdp);
pc1_offer = offer;
if (!offer.sdp.match(/a=rtpmap:[0-9]+ G722/g)) {
log("No G722 found in the offer!!!");
return Promise.reject();
}
}
if (tias.value != 0) {
offer.sdp = addTIAS(offer.sdp, tias.value)
pc1_offer = offer;
}
log("Final Offer: " + sdpPrettyPrint(offer.sdp));
return pc1.setLocalDescription(offer);
}
// pc1.setLocal finished, call pc2.setRemote
function offerSetRemote() {
pc1.onicecandidate = function(obj) {
if (obj.candidate) {
log("pc1 found ICE candidate: " + JSON.stringify(obj.candidate));
pc2.addIceCandidate(obj.candidate);
} else {
log("pc1 got end-of-candidates signal");
}
}
return pc2.setRemoteDescription(pc1_offer);
};
// pc2.setRemote finished, call pc2.createAnswer
function createAnswer() {
pc2.didSetRemote = true;
while (pc2.ice_queued.length > 0) {
pc2.addIceCandidate(pc2.ice_queued.shift());
}
return pc2.createAnswer(answer_constraints);
}
// pc2.createAnswer finished, call pc2.setLocal
function answerSetLocal(answer) {
log("Answer: " + sdpPrettyPrint(answer.sdp));
pc2_answer = answer;
if ((requireh264.checked) && (!answer.sdp.match(/a=rtpmap:[0-9]+ H264/g))) {
log("No H264 found in the answer!!!");
return Promise.reject();
}
if ((requireg722.checked) && (!answer.sdp.match(/a=rtpmap:[0-9]+ G722/g))) {
log("No G722 found in the answer!!!");
return Promise.reject();
}
return pc2.setLocalDescription(answer);
}
// pc2.setLocal finished, call pc1.setRemote
function answerSetRemote() {
pc2.onicecandidate = function(obj) {
if (obj.candidate) {
log("pc2 found ICE candidate: " + JSON.stringify(obj.candidate));
pc1.addIceCandidate(obj.candidate);
} else {
log("pc2 got end-of-candidates signal");
}
}
return pc1.setRemoteDescription(pc2_answer);
}
// pc1.setRemote finished, media should be running!
function finished() {
pc1.didSetRemote = true;
while (pc1.ice_queued.length > 0) {
pc1.addIceCandidate(pc1.ice_queued.shift());
}
log("Signaling done");
}
function start() {
button.innerHTML = "Stop!";
button.onclick = stop;
var pc1config = {};
var pc2config = {};
let idp;
var myrequest = {};
if (audio_only.checked) {
myrequest.video = false;
} else {
myrequest.video = true;
}
if (video_only.checked) {
myrequest.audio = false;
} else {
myrequest.audio = true;
}
log("Parsing JSON:" + video_constraints.value);
if (myrequest.video && video_constraints.value) {
try {
myrequest.video = JSON.parse(video_constraints.value);
} catch(e) {
log("Couldn't parse JSON (" + e + ") value: " + video_constraints.value);
myrequest.video = true;
}
log("Using contraints: " + JSON.stringify(myrequest));
}
myrequest_reverse = copy_dictionary(myrequest);
if (fake.checked) {
myrequest_reverse.fake = true;
}
if (oneway.checked) {
offer_constraints = { offerToReceiveVideo: false,
offerToReceiveAudio: false };
answer_constraints = { offerToReceiveVideo: true,
offerToReceiveAudio: true };
} else {
offer_constraints = null;
answer_constraints = null;
}
if (idpenabled.checked) {
idp = {
domain: document.getElementById('idpdomain').value,
protocol: document.getElementById('idpprotocol').value,
usera: document.getElementById('idpusera').value,
userb: document.getElementById('idpuserb').value
};
if (idp.usera) {
// Note that the peer identity constraints are applied on the *other*
// end of the connection.
myrequest_reverse.peerIdentity = idp.usera + '@' + idp.domain;
pc2config.peerIdentity = idp.usera + '@' + idp.domain;
}
if (idp.userb) {
myrequest.peerIdentity = idp.userb + '@' + idp.domain;
pc1config.peerIdentity = idp.userb + '@' + idp.domain;
}
}
pc1 = new RTCPeerConnection(pc1config);
pc2 = new RTCPeerConnection(pc2config);
pc1.didSetRemote = false;
pc2.didSetRemote = false;
pc1.ice_queued = [];
pc2.ice_queued = [];
pc2.onicecandidate = function(obj) {
if (obj.candidate) {
log("pc2 found ICE candidate: " + JSON.stringify(obj.candidate));
if (pc1.didSetRemote) {
pc1.addIceCandidate(obj.candidate);
} else {
pc1.ice_queued.push(obj.candidate);
}
} else {
log("pc2 got end-of-candidates signal");
}
}
pc1.onicecandidate = function(obj) {
if (obj.candidate) {
log("pc1 found ICE candidate: " + JSON.stringify(obj.candidate));
if (pc2.didSetRemote) {
pc2.addIceCandidate(obj.candidate);
} else {
pc2.ice_queued.push(obj.candidate);
}
} else {
log("pc1 got end-of-candidates signal");
}
}
pc1.oniceconnectionstatechange = function(obj) {
log("pc1 ICE connection state: " + pc1.iceConnectionState);
if (pc1.iceConnectionState == 'connected') {
log('PC1: HIP HIP HOORAY');
}
}
pc2.oniceconnectionstatechange = function(obj) {
log("pc2 ICE connection state: " + pc2.iceConnectionState);
if (pc2.iceConnectionState == 'connected') {
log('PC2: HIP HIP HOORAY');
}
}
pc1.ontrack = function(obj) {
log("pc1 got remote tracks from pc2 " + obj.type);
pc1video.srcObject = obj.streams[0];
pc1video.play();
}
pc2.ontrack = function(obj) {
log("pc2 got remote tracks from pc1 " + obj.type);
pc2video.srcObject = obj.streams[0];
pc2video.play();
}
if (idp) {
pc1.setIdentityProvider(idp.domain, { idp: idp.protocol, name: idp.usera });
pc1.peerIdentity.then(id => log('pc1 connected to "' + id.name + '"'));
pc2.setIdentityProvider(idp.domain, { idp: idp.protocol, name: idp.userb });
pc2.peerIdentity.then(id => log('pc2 connected to "' + id.name + '"'));
}
navigator.mediaDevices.getUserMedia(myrequest).then(function(video1) {
// Add stream obtained from gUM to <video> to start media flow.
localvideo1.srcObject = video1;
if (video_disable.checked)
localvideo1.srcObject.getVideoTracks()[0].enabled = false;
if (audio_disable.checked)
localvideo1.srcObject.getAudioTracks()[0].enabled = false;
localvideo1.play();
pc1.addStream(video1);
return Promise.resolve();
})
.then(() => {
if (!oneway.checked) {
return navigator.mediaDevices.getUserMedia(myrequest_reverse).then(function(video2) {
localvideo2.srcObject = video2;
localvideo2.play();
pc2.addStream(video2);
return Promise.resolve();
});
} else {
return Promise.resolve();
}
})
.then(() => {
return pc1.createOffer(offer_constraints);
})
.then((offer) => {
return offerSetLocal(offer);
})
.then(() => {
return offerSetRemote();
})
.then(() => {
return createAnswer();
})
.then((answer) => {
return answerSetLocal(answer);
})
.then(() => {
return answerSetRemote();
})
.then(() => {
finished();
})
.catch((e) => {
failed(e);
});
}
function stop() {
pc1.close();
pc2.close();
button.innerHTML = "Start!";
button.onclick = start;
}
</script>
</body></html>