-
Notifications
You must be signed in to change notification settings - Fork 11
/
ios-plus-new-layout.html
856 lines (739 loc) · 30.2 KB
/
ios-plus-new-layout.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
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
<!doctype html>
<html lang="en">
<head>
<title>Unrupt calls</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<style>
#chooseAction, #chosenAction, #audioInfo, #videoRow{
display:none;
}
#unrupturl{position:absolute;left:-9999px;}
#in {
transform: rotateY(180deg);
}
video {
width: 100%;
}
.buffer-label{font-size:14px;}
#otherUser, #thisUser {
position: relative;
width: 100%;
}
.playpause {
display: none;
width:25%;
position:absolute;
left:0;
right:0;
bottom:0;
margin:auto;
background-size:contain;
background-position: center;
z-index: 99999;
}
#message_holder{display:none;}
#message_holder.flash-message{display:block};
</style>
</head>
<body>
<h1 id="title" class="text-center">Unrupt Calls</h1>
<h3 id="useragent"></h3>
<div class="alert alert-info" id="message_holder">
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" crossorigin="anonymous"></script>
<div id="audioInfo" class="card">
<div>
<div class="card">
<!-- <h4 class="card-header">Media</h4> -->
<div class="card-body">
<div class="container">
<div class="row" id="videoRow">
<div class="col-4 card">
<div class="card-header">Far Camera</div>
<div class="card-body">
<div id="otherUser">
<div id="pauseOther" class="playpause">
<object data="pause.svg"></object>
</div>
</div>
</div>
</div>
<div class="col-4 card"></div>
<div class="card">
<div class="card-header">This Camera</div>
<div class="card-body">
<div id="thisUser"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-4 card">
<div class="card-header buffer-label">Far <span id="farscope-badge" class="badge badge-secondary">Silent</span></div>
<div class="card-body">
<canvas id="farscope" style="height:40px;width:60px;">Scope</canvas>
</div>
</div>
<div class="col-4 card">
<div class="card-header buffer-label">Play <span id="earscope-badge" class="badge badge-secondary">Silent</span>
</div>
<div class="card-body">
<canvas id="earscope" style="height:40px;width:60px;">Scope</canvas>
</div>
</div>
<div class="col-4 card">
<div class="card-header buffer-label">Near <span id="nearscope-badge" class="badge badge-secondary">Silent</span></div>
<div class="card-body">
<canvas id="nearscope" style="height:40px;width:60px;">Scope</canvas>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<h4 class="card-header">Buffered audio</h4>
<div class="card-body">
<div class="progress">
<div id="unruptbuffer_spk" class="progress-bar progress-bar-striped bg-warning" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"></div>
<div id="unruptbuffer_sil" class="progress-bar " role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<span id="unruptbuffer_len" class="badge pull-right"></span>
<span id="version" class="badge badge-secondary">default</span>
</div>
</div>
<div class="card">
<!-- <h4 class="card-header">Call</h4> -->
<div class="card-body">
<div id="chooseAction">
<h5>Make Shareable Page</h5>
<button id="chooseActionAudio" type="button" class="btn btn-primary btn-lg">Audio</button>
<button id="chooseActionVideo" type="button" class="btn btn-primary btn-lg">Audio & Video</button>
</div>
<div id="chosenAction">
<button class="unrupt-action-btn btn btn-primary btn-lg" data-clipboard-target="#unrupturl">copy url</button>
<button id="action" type="button" class="btn btn-primary btn-lg></button>
<button id="pause" type="button" class="btn btn-primary btn-lg">pause</button>
<button id="mute" type="button" class="btn btn-primary btn-lg">mute</button>
<button id="unruptToggle" type="button" class="btn btn-primary btn-lg">Pause-while-speaking on</button>
<span id="mode" class="badge badge-primary">Direct</span>
</div>
</div>
</div>
<script src="properties.js"></script>
<script>
var webRTCconfiguration = {
"iceServers": [
{urls: "stun:146.148.121.175:3478"},
{urls: "turn:146.148.121.175:3478?transport=udp", 'credential': 'nexus5x', 'username': 'smartphone'},
],
"bundlePolicy":"max-bundle","iceCandidatePoolSize":1
};
var pc; // actual peer connection to our friend
var socket; // used to set up connection with our peer.
var mid;
var fid;
var myac;
var yourac;
var yourBuffer;
var myBuffer;
var initiator;
var lcandyStash = [];
var rcandyStash = [];
var localStream;
var remoteStream;
var scopes= [];
var procs = [];
var backlog = 0;
var backlog_sil = 0;
var backlog_spk = 0;
var tick;
var iamspeaking = false;
var mute = false;
var paused = false;
var videoEnabled = false;
var peerConnectionOfferAnswerCriteria = {offerToReceiveAudio: true, offerToReceiveVideo: false };
var unruptEnabled = true;
var toggleUnrupt;
var AudioContext = window.AudioContext || window.webkitAudioContext;
// message stuff - used to create direct connection to peer over WEBRTC
function messageDeal(event){
//console.log("message is ", event.data);
var data = JSON.parse(event.data);
console.log("message data is ", data);
if (data.to != mid){
alert("message mixup");
}
switch (data.type) {
case "cheatUnruptToggle":
toggleUnrupt();
break;
case "offer":
if (fid == null) {
fid = data.from;
}
pc.setRemoteDescription(data).then( _ =>
pc.createAnswer(peerConnectionOfferAnswerCriteria).then(ans =>
pc.setLocalDescription(ans).then( _ =>
sendMessage(fid, mid, "answer", ans.sdp)
)
)
)
.catch((e) => console.log("set Remote offer error", e));
break;
case "answer":
pc.setRemoteDescription(data)
.then( _ => {
$("#action").text("hangup");
})
.catch(e => console.log("set Remote answer error", e) );
break;
case "candidate":
var jc = {
sdpMLineIndex: 0,
candidate: data.sdp
};
console.log("adding candidate ", jc);
var nc = new RTCIceCandidate(jc);
pc.addIceCandidate(nc)
.then( _ => console.log("added remote candidate"))
.catch((e) => console.log("couldn't add candidate ", e));
break;
}
}
function sendMessage(to,from,type,data){
var messageJ = {
to:to,
from:from,
type:type,
sdp:data
};
var message = JSON.stringify(messageJ);
console.log("sending ", messageJ);
socket.send(message);
}
// button actions
function startCall(cid){
lcandyStash = [];
rcandyStash = [];
fid = cid;
pc.createOffer(peerConnectionOfferAnswerCriteria)
.then(desc => {
console.log("offer created",);
pc.setLocalDescription(desc).then( d => sendMessage(fid, mid, desc.type, desc.sdp));
})
.catch(e => console.log("offer not created due to ", e) );
}
function stopCall(){
window.location.href = window.location.href;
}
// webaudio processing
// display waveform for diagnostics
function doScopeNode(ac, node, scopename) {
console.log("making scope node ", scopename);
var analyser = ac.createAnalyser();
analyser.fftSize = properties.scopeFftSize;
node.connect(analyser);
makeDraw(scopename, analyser);
scopes.push(analyser);
return analyser;
}
// processing incoming audio
function yourProc(node){
var buffer = yourBuffer;
console.log("made unrupt buffer of size ", buffer.bufferSize, buffer);
var silentcount = 0;
var audiostash = [];
var ub = $('#unruptToggle');
var pb = $("#pause");
console.log('PauseButton!!!', pb);
var oldmute = false;
toggleUnrupt = () => {
if (unruptEnabled) {
unruptEnabled = false;
console.log('disconnecting the buffer');
node.disconnect(buffer);
document.getElementById('out').muted = false;
document.getElementById('out').play();
$('#pauseOther').hide();
ub.text('Pause-while-speaking off');
} else {
unruptEnabled = true;
console.log('connecting the buffer');
node.connect(buffer);
document.getElementById('out').muted = true;
ub.text('Pause-while-speaking on');
}
}
ub.off('click').on('click', (e) => {
e.stopImmediatePropagation();
toggleUnrupt();
sendMessage(fid, mid, "cheatUnruptToggle", true);
});
pb.off('click').on('click', (e) => {
e.stopImmediatePropagation();
console.log('clicked on pause!');
console.log('paused variable is', paused);
if (!paused){
paused = true;
pb.text("unpause");
oldmute = mute;
setMute(true);
} else {
paused = false;
pb.text("pause");
setMute(oldmute);
}
});
buffer.onaudioprocess = (ape) => {
console.log('ARE WE STILL PROCESSING AUDIO!?!');
if (!unruptEnabled) {
console.log('unrupt isnt enabled so clearing the backlog numbers');
backlog_sil = backlog_spk = 0;
return;
}
var inputBuffer = ape.inputBuffer;
// The output buffer contains the samples that will be modified and played
var outputBuffer = ape.outputBuffer;
// Loop through the output channels (in this case there is only one)
if (inputBuffer.numberOfChannels == 1){
var inputData = inputBuffer.getChannelData(0);
var outputData = outputBuffer.getChannelData(0);
// we (almost) always stash the inbound data
if (audiostash.length < properties.maxStashFrames) {
var buff = new Float32Array(inputBuffer.length);
var avg = 0.0;
for (var sample = 0; sample < inputBuffer.length; sample++) {
buff[sample] = inputData[sample]; // copy
avg += Math.abs(buff[sample]); // sample
}
avg = avg / inputBuffer.length;
var silent = (avg < properties.farSilenceThreshold);
if (silent){
silentcount++;
backlog_sil++;
} else {
silentcount =0;
backlog_spk++;
}
audiostash.unshift({silent: silent, buff:buff, silentcount: silentcount});
// store annotated version
}
backlog = audiostash.length /10;
if (paused || iamspeaking) {
for (var sample = 0; sample < inputBuffer.length; sample++) {
outputData[sample] = 0.0; // silence
}
} else {
var stash = audiostash.pop();
if (stash.silent){
backlog_sil--;
} else {
backlog_spk--;
}
var deleteme = (stash.silent);
while ((audiostash.length > 0) && (deleteme)){
console.log("have backlog", audiostash.length);
deleteme = false;
if (audiostash[0].silent){
console.log("next one is silent too");
if (stash.silentcount > properties.minFramesSilenceForPlay){
console.log("silentcount = ", stash.silentcount);
deleteme = true;
stash = audiostash.pop();
if (stash.silent){
backlog_sil--;
} else {
backlog_spk--;
}
}
}
}
var buff = stash.buff;
for (var sample = 0; sample < inputBuffer.length; sample++) {
outputData[sample] = buff[sample];
}
}
}
};
node.connect(buffer);
procs.push(buffer)
return buffer;
}
// mute management
function setMute(m){
var mb = $("#mute");
mute = m;
if (m){
mb.text("unmute");
} else {
mb.text("mute");
}
var audioTracks = localStream.getAudioTracks();
if (audioTracks[0]) {
audioTracks[0].enabled = !m;
}
}
// processing audio from the local microphone
function myProc(node){
var mb = $("#mute");
mb.click( () => {
setMute(!mute);
});
var buffer = myBuffer;
console.log("made unrupt buffer of size ", buffer.bufferSize);
var silentcount = 0;
buffer.onaudioprocess = ape => {
var inputBuffer = ape.inputBuffer;
var outputBuffer = ape.outputBuffer;
// Loop through the output channels (in this case there is only one)
if (inputBuffer.numberOfChannels == 1){
var inputData = inputBuffer.getChannelData(0);
var outputData = outputBuffer.getChannelData(0);
// Loop through the 4096 samples
var avg = 0.0;
for (var sample = 0; sample < inputBuffer.length; sample++) {
// make output equal to the same as the input
outputData[sample] = inputData[sample];
avg += Math.abs(outputData[sample]); // sample
}
avg = avg / inputBuffer.length;
var silent = (avg < properties.micSilenceThreshold);
if (iamspeaking){
if (silent){
silentcount++;
}
if (silentcount > properties.minFramesSilenceForPause){
iamspeaking = false;
}
} else {
if (!silent) {
iamspeaking = true;
silentcount =0;
}
}
}
};
node.connect(buffer);
procs.push(buffer)
return buffer;
}
// called when webRTC presents us with a fresh remote audio stream
function addStream(stream) {
console.log("got new stream", stream);
remoteStream = stream;
var mediaElement = document.getElementById('out');
mediaElement.srcObject = stream;
//mediaElement.muted = true;
mediaElement.onloadedmetadata = function(e) {
mediaElement.play();
//mediaElement.muted = true;
};
var peer = yourac.createMediaStreamSource(stream);
console.log('Sample Rate is', yourac.sampleRate);
var scope = doScopeNode(yourac, peer, "farscope");
var buffproc = yourProc(scope);
var scope2 = doScopeNode(yourac, buffproc, "earscope");
scope2.connect(yourac.destination);
}
// configure local peerconnection and handlers
function setupRTC(){
pc = new RTCPeerConnection(webRTCconfiguration, null);
console.log("created peer connection");
pc.onicecandidate = (e) => {
console.log("local ice candidate", e.candidate);
if (e.candidate != null) {
if (pc.signalingState == 'stable') {
sendMessage(fid, mid, "candidate", e.candidate.candidate);
} else {
console.log("stashing ice candidate");
lcandyStash.push(e.candidate);
}
}
};
pc.oniceconnectionstatechange = (e) => {
console.log("ice state is changed", pc.iceConnectionState);
if (pc.iceConnectionState === "failed"){
stopCall();
}
};
// specification of WEBRTC is in flux - so we test to see if ontrack callback exists
if ('ontrack' in pc) {
// if so we use it
pc.ontrack = (event) => {
var stream = event.streams[0];
console.log("got remote track ", stream.kind);
addStream(stream);
};
} else {
// if not we use add stream instead
pc.onaddstream = (event) => {
var stream = event.stream;
console.log("got remote stream ", stream.kind);
addStream(stream);
}
}
// use this to determine the state of the 'hangup' button and send any candidates we found quickly
pc.onsignalingstatechange = (evt) => {
console.log("signalling state is ", pc.signalingState);
if (pc.signalingState == 'stable') {
var can;
while (can = lcandyStash.pop()) {
console.log("popping candidate off stash")
sendMessage(fid, mid, "candidate", can.candidate);
}
var act = $("#action");
act.text("hangup call");
act.click( _ => stopCall() );
}
};
}
// plumb the local audio together.
function setupAudio() {
myac = new AudioContext();
yourac = new AudioContext();
yourBuffer = yourac.createScriptProcessor(properties.procFramesize, 1, 1);
myBuffer = myac.createScriptProcessor(properties.procFramesize, 1, 1);
navigator.mediaDevices.getUserMedia({audio: true, video: videoEnabled})
.then((stream) => {
if (videoEnabled) {
var ourMediaElement = document.getElementById('in');
ourMediaElement.srcObject = stream;
ourMediaElement.onloadedmetadata = function(e) {
ourMediaElement.play();
};
}
localStream = stream; // in case we need it
var node = myac.createMediaStreamSource(stream);
var detect = myProc(node);
var manl = doScopeNode(myac, detect, "nearscope");
var dest = myac.createMediaStreamDestination();
manl.connect(dest);
var lstream = dest.stream;
if (pc.addTrack) {
stream.getTracks().forEach(track => {
pc.addTrack(track, lstream);
console.log("added local track ", track.id, track.kind);
});
} else {
stream.getTracks().forEach(track => {
if (track.kind === 'video') {
lstream.addTrack(track);
}
});
pc.addStream(lstream);
console.log("added local stream");
}
})
.catch((e) => console.log('getUserMedia() error:', e.name));
}
// decide who we are initiator or recpient.
// notice that the actual call goes in the reverse direction
// the recipient of the invite actually creates the audiobearing peerconnection
// the initiator then accepts this audio - This allows the initiator the chance to
// change their mind, if their circumstances have changed since the invite was sent.
function setRole() {
var cid = $.getUrlVar("unruptId");
mid = localStorage['unruptId'];
var chooseAction = $("#chooseAction");
var chosenAction = $("#chosenAction");
var chooseActionAudio = $("#chooseActionAudio");
var chooseActionVideo = $("#chooseActionVideo");
var act = $("#action");
if (!mid) {
var array = new Uint32Array(8);
window.crypto.getRandomValues(array);
var hexCodes = [];
for (var i = 0; i < array.length; i ++ ){
// Using getUint32 reduces the number of iterations needed (we process 4 bytes each time)
var value = array[i];
// toString(16) will give the hex representation of the number without padding
var stringValue = value.toString(16)
// We use concatenation and slice for padding
var padding = '00000000'
var paddedValue = (padding + stringValue).slice(-padding.length)
hexCodes.push(paddedValue);
}
mid = hexCodes.join("").toLowerCase();
console.log("mid =", mid);
localStorage['unruptId'] = mid;
}
if (cid == null){
chooseAction.show();
chooseActionAudio.click( _ => {
document.location = location.pathname + "?" + "unruptId=" + mid;
});
chooseActionVideo.click( _ => {
document.location = location.pathname + "?" + "unruptId=" + mid + "&video=1";
});
} else {
chosenAction.show();
$('#audioInfo').show();
if (videoEnabled) {
$('#videoRow').css('display', 'flex');
}
socket = new WebSocket( properties.websocketURL + mid);
socket.onmessage = messageDeal;
socket.onopen = (_) => {
act.text("to continue, press here");
act.on('click', () => {
act.off('click');
console.log("connected as", mid);
setupRTC();
setupAudio();
initiator = (mid === cid);
if (initiator) {
act.text("please share this page as a link");
} else {
act.text("accept call");
act.click( () => startCall(cid));
}
})
};
socket.onerror = (e) => {
console.log("can't open websocket", e);
};
socket.onclose = (e) => {
console.log(" websocket closed", e);
};
}
}
// thing that draws the scopes...
function makeDraw(canvName, anode) {
var analyser = anode;
var speaking = false;
var bufferLength = analyser.frequencyBinCount;
var dataArray = new Uint8Array(bufferLength);
var canvas = document.getElementById(canvName);
var badge = document.getElementById(canvName + "-badge");
var canvasCtx = canvas.getContext("2d");
// oscilloscope - for debug.
var draw = _ => {
// Get a canvas defined with ID "oscilloscope"
var drawVisual = requestAnimationFrame(draw);
analyser.getByteTimeDomainData(dataArray);
canvasCtx.fillStyle = 'rgb(200, 200, 200)';
//canvasCtx.fillStyle = 'rgb(0,0,0,0)';
canvasCtx.fillRect(0, 0, canvas.width, canvas.height);
canvasCtx.lineWidth = 2;
canvasCtx.strokeStyle = 'rgb(0, 0, 0)';
canvasCtx.beginPath();
var sliceWidth = canvas.width * 1.0 / bufferLength;
var x = 0;
var tot = 0.0;
for (var i = 0; i < bufferLength; i++) {
var v = dataArray[i] / 128.0;
tot += Math.abs(dataArray[i]-128);
var y = v * canvas.height / 2;
if (i === 0) {
canvasCtx.moveTo(x, y);
} else {
canvasCtx.lineTo(x, y);
}
x += sliceWidth;
}
var mean = tot / bufferLength;
var newspeak = (mean > 2.0);
if (newspeak != speaking) {
speaking = newspeak;
//console.log("newspeak "+newspeak+" mean "+mean);
badge.innerText = speaking ? "Speaking" : "Silent";
}
canvasCtx.lineTo(canvas.width, canvas.height / 2);
canvasCtx.stroke();
};
draw();
}
// some housekeeping
$.extend({
getUrlVars: function(){
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
},
getUrlVar: function(name){
return $.getUrlVars()[name];
}
});
$( document ).ready( _ => {
videoEnabled = $.getUrlVar("video") == '1';
if(videoEnabled) {
peerConnectionOfferAnswerCriteria = {};
var otherUserMediaElement = document.createElement('video');
otherUserMediaElement.id = 'out';
otherUserMediaElement.muted = true;
document.getElementById('otherUser').appendChild(otherUserMediaElement);
var thisUserMediaElement = document.createElement('video');
thisUserMediaElement.id = 'in';
thisUserMediaElement.muted = true;
document.getElementById('thisUser').appendChild(thisUserMediaElement);
} else {
var mediaElement = document.createElement('audio');
mediaElement.id = 'out';
mediaElement.muted = true;
document.body.appendChild(mediaElement);
}
setRole();
$('#version').text(properties.versionname);
tick = window.setInterval( t => {
var scale = properties.maxStashFrames / 100.0;
var spk = backlog_spk / scale;
var sil = backlog_sil / scale;
var timeline = Math.floor((backlog_spk + backlog_sil) * properties.procFramesize / 44100.0);
$('#unruptbuffer_len').text(timeline + " seconds");
$('#unruptbuffer_sil').css('width', sil + "%").attr('aria-valuenow', sil);
$('#unruptbuffer_spk').css('width', spk + "%").attr('aria-valuenow', spk);
var playout = backlog > 1 ? "playing" : "direct";
var mode = (iamspeaking || paused) ? "paused" : playout;
$('#mode').text(mode);
if (remoteStream && videoEnabled && unruptEnabled) {
var pauseIcon = $('#pauseOther');
if (mode === "paused") {
otherUserMediaElement.pause();
pauseIcon.show();
} else {
otherUserMediaElement.play();
pauseIcon.hide();
}
}
}, 250);
});
</script>
<!-- hidden unrupturl holder -->
<input id="unrupturl" />
<!-- Include clipboardjs -->
<script src="clipboard.min.js"></script>
<!-- Instantiate clipboard -->
<script>
$(document).ready(function(){
var unrupturltag = $("#unrupturl");
unrupturltag.val(window.location.href)
var clipboard = new Clipboard('.unrupt-action-btn');
clipboard.on('success', function(e) {
//
var message_holder = $("#message_holder");
var message = "copied to clipboard";
message_holder.html('<strong>' + message + '</strong>');
message_holder.addClass("flash-message");
setTimeout(function(){ message_holder.removeClass("flash-message"); }, 3000);
});
clipboard.on('error', function(e) {
// console.log(e);
});
});
</script>
</body>
</html>