-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathindex.js
1302 lines (1145 loc) · 45.6 KB
/
index.js
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
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Constants
const API_BASE_URL = "https://api.videosdk.live";
// Declaring variables
let videoContainer = document.getElementById("videoContainer");
let micButton = document.getElementById("micButton");
let camButton = document.getElementById("camButton");
let copy_meeting_id = document.getElementById("meetingid");
let contentRaiseHand = document.getElementById("contentRaiseHand");
let btnScreenShare = document.getElementById("btnScreenShare");
let videoScreenShare = document.getElementById("videoScreenShare");
let btnRaiseHand = document.getElementById("btnRaiseHand");
// let btnStopPresenting = document.getElementById("btnStopPresenting");
let btnSend = document.getElementById("btnSend");
let participantsList = document.getElementById("participantsList");
let videoCamOff = document.getElementById("main-pg-cam-off");
let videoCamOn = document.getElementById("main-pg-cam-on");
let micOn = document.getElementById("main-pg-unmute-mic");
let micOff = document.getElementById("main-pg-mute-mic");
//recording
let btnStartRecording = document.getElementById("btnStartRecording");
let btnStopRecording = document.getElementById("btnStopRecording");
//videoPlayback DIV
let videoPlayback = document.getElementById("videoPlayback");
// For PreCall
const cameraDeviceDropDown = document.getElementById('cameraDeviceDropDown');
const microphoneDeviceDropDown = document.getElementById('microphoneDeviceDropDown');
const playBackDeviceDropDown = document.getElementById('playBackDeviceDropDown');
const joinMeetingCode = document.getElementById("joinMeetingId");
const joiningName = document.getElementById("name");
const refreshButton = document.getElementById("refresh");
const networkErrorRefreshButton = document.querySelectorAll(".network-error-refresh");
const microphonePermission = document.getElementById("no-microphone-permission");
const cameraPermission = document.getElementById("no-camera-permission");
joinMeetingCode.addEventListener("input", handleInputChange);
joiningName.addEventListener("input", handleInputChange);
let joinMeetingCodeValue = "";
let joinNameValue = "";
let currentMic = null;
let currentCamera = null;
let currentPlayback = null;
let meeting = "";
// Local participants
let localParticipant;
let localParticipantAudio;
let createMeetingFlag = 0;
let joinMeetingFlag = 0;
let token = "";
let micEnable = false;
let webCamEnable = false;
let totalParticipants = 0;
let remoteParticipantId = "";
let participants = [];
// join page
let joinPageWebcam = document.getElementById("joinCam");
let meetingCode = "";
let screenShareOn = false;
let joinPageVideoStream = null;
let cameraPermissionAllowed = true;
let microphonePermissionAllowed = true;
let deviceChangeEventListener;
window.addEventListener("load", async function () {
/*
const audioPermission = await window.VideoSDK.requestPermission(
window.VideoSDK.Constants.permission.AUDIO,
);
console.log(
"request Audio Permissions",
audioPermission.get(window.VideoSDK.Constants.permission.AUDIO)
);
const videoPermission = await window.VideoSDK.requestPermission(
window.VideoSDK.Constants.permission.VIDEO,
);
console.log(
"request Video Permissions",
videoPermission.get(window.VideoSDK.Constants.permission.VIDEO)
);
const audiovideoPermission = await window.VideoSDK.requestPermission(
window.VideoSDK.Constants.permission.AUDIO_AND_VIDEO,
);
console.log(
"request Audio and Video Permissions",
audiovideoPermission.get(window.VideoSDK.Constants.permission.AUDIO),
audiovideoPermission.get(window.VideoSDK.Constants.permission.VIDEO)
);
*/
/*
try {
const checkAudioPermission = await window.VideoSDK.checkPermissions(
window.VideoSDK.Constants.permission.AUDIO,
);
console.log(
"Check Audio Permissions",
checkAudioPermission.get(window.VideoSDK.Constants.permission.AUDIO)
);
} catch (e) {
console.error(e.message);
}
try {
const checkVideoPermission = await window.VideoSDK.checkPermissions(
window.VideoSDK.Constants.permission.VIDEO,
);
console.log(
"Check Video Permissions",
checkVideoPermission.get(window.VideoSDK.Constants.permission.VIDEO)
);
} catch (e) {
console.error(e.message);
}
try {
const checkAudioVideoPermission = await window.VideoSDK.checkPermissions(
window.VideoSDK.Constants.permission.AUDIO_AND_VIDEO,
);
console.log(
"Check Audio Video Permissions",
checkAudioVideoPermission.get(window.VideoSDK.Constants.permission.VIDEO),
checkAudioVideoPermission.get(window.VideoSDK.Constants.permission.AUDIO)
);
} catch (e) {
console.error(e.message);
}
*/
let checkAudioVideoPermission;
try {
checkAudioVideoPermission = await VideoSDK.checkPermissions(
VideoSDK.Constants.permission.AUDIO_AND_VIDEO,
);
console.log(
"check Audio and Video Permissions",
checkAudioVideoPermission.get(VideoSDK.Constants.permission.AUDIO),
checkAudioVideoPermission.get(VideoSDK.Constants.permission.VIDEO)
);
} catch (ex) {
console.log("Error in checkPermissions ", ex);
}
if (checkAudioVideoPermission.get(window.VideoSDK.Constants.permission.VIDEO) === false || checkAudioVideoPermission.get(window.VideoSDK.Constants.permission.AUDIO) === false) {
checkAudioVideoPermission = await window.VideoSDK.requestPermission(
window.VideoSDK.Constants.permission.AUDIO_AND_VIDEO,
);
}
// if(requestPermission.get(window.VideoSDK.Constants.permission.AUDIO)){
// console.log("permission check called");
// var svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
// svg.setAttribute("width", "20");
// svg.setAttribute("height", "20");
// svg.setAttribute("viewBox", "0 0 20 20");
// svg.setAttribute("fill", "none");
// svg.innerHTML = `
// <g filter="url(#filter0_d_20_967)">
// <circle cx="10" cy="8" r="8" fill="#FF8A00"/>
// </g>
// <path d="M10.876 4.258V7.69C10.876 8.058 10.854 8.424 10.81 8.788C10.766 9.148 10.708 9.516 10.636 9.892H9.37605C9.30405 9.516 9.24605 9.148 9.20205 8.788C9.15805 8.424 9.13605 8.058 9.13605 7.69V4.258H10.876ZM8.93205 12.058C8.93205 11.914 8.95805 11.78 9.01005 11.656C9.06605 11.532 9.14005 11.424 9.23205 11.332C9.32805 11.24 9.44005 11.168 9.56805 11.116C9.69605 11.06 9.83605 11.032 9.98805 11.032C10.136 11.032 10.274 11.06 10.402 11.116C10.53 11.168 10.642 11.24 10.738 11.332C10.834 11.424 10.908 11.532 10.96 11.656C11.016 11.78 11.044 11.914 11.044 12.058C11.044 12.202 11.016 12.338 10.96 12.466C10.908 12.59 10.834 12.698 10.738 12.79C10.642 12.882 10.53 12.954 10.402 13.006C10.274 13.058 10.136 13.084 9.98805 13.084C9.83605 13.084 9.69605 13.058 9.56805 13.006C9.44005 12.954 9.32805 12.882 9.23205 12.79C9.14005 12.698 9.06605 12.59 9.01005 12.466C8.95805 12.338 8.93205 12.202 8.93205 12.058Z" fill="white"/>
// <defs>
// <filter id="filter0_d_20_967" x="0" y="0" width="20" height="20" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
// <feFlood flood-opacity="0" result="BackgroundImageFix"/>
// <feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" result="hardAlpha"/>
// <feOffset dy="2"/>
// <feGaussianBlur stdDeviation="1"/>
// <feComposite in2="hardAlpha" operator="out"/>
// <feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0"/>
// <feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow_20_967"/>
// <feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow_20_967" result="shape"/>
// </filter>
// </defs>
// `
// document.querySelector(".video-content").appendChild(svg);
// }
console.log(
"request Audio and Video Permissions",
checkAudioVideoPermission.get(window.VideoSDK.Constants.permission.AUDIO),
checkAudioVideoPermission.get(window.VideoSDK.Constants.permission.VIDEO)
);
if (checkAudioVideoPermission.get(window.VideoSDK.Constants.permission.AUDIO) === false) {
this.document.getElementById("micButton").style.display = "none";
this.document.getElementById("no-microphone-permission").style.display = "block";
}
if (checkAudioVideoPermission.get(window.VideoSDK.Constants.permission.VIDEO) === false) {
this.document.getElementById("camButton").style.display = "none";
this.document.getElementById("no-camera-permission").style.display = "block";
}
await updateDevices();
await enableCam();
await enableMic();
// microphonePermission.addEventListener('click', async () => {
// console.log("microphone permission request called");
// try{
// requestPermission = await window.VideoSDK.requestPermission(
// window.VideoSDK.Constants.permission.AUDIO,
// );
// console.log("permission taken")
// }catch(e){
// console.log("Error while requesting microphone permission", e);
// }
// })
// cameraPermission.addEventListener('click', async () => {
// try{
// requestPermission = await window.VideoSDK.requestPermission(
// window.VideoSDK.Constants.permission.VIDEO,
// );
// }catch(e){
// console.log("Error while requesting camera permission", e);
// }
// })
deviceChangeEventListener = async (devices) => { //
await updateDevices();
await enableCam();
}
window.VideoSDK.on("device-changed", deviceChangeEventListener);
refreshButton.addEventListener('click', async () => {
try {
const refreshElement = document.getElementById("refresh");
console.log(refreshElement);
this.document.getElementById("download-speed-div").style.display = "none";
this.document.getElementById("upload-speed-div").style.display = "none";
this.document.getElementById("check-speed-div").style.display = "unset";
this.document.getElementById("network-stats").style.marginLeft = "445px";
refreshElement.firstElementChild.classList.remove("bi-arrow-cloclwise");
refreshElement.firstElementChild.classList.add("bi-arrow-repeat");
refreshElement.classList.add("spin")
const result = await window.VideoSDK.getNetworkStats({ timeoutDuration: 120000 });
this.document.getElementById("download-speed-div").style.display = "flex";
this.document.getElementById("upload-speed-div").style.display = "flex";
this.document.getElementById("check-speed-div").style.display = "none";
this.document.getElementById("network-stats").style.marginLeft = "375px";
refreshElement.firstElementChild.classList.add("bi-arrow-cloclwise");
refreshElement.firstElementChild.classList.remove("bi-arrow-repeat");
refreshElement.classList.remove("spin");
document.getElementById("network-error-offline").style.display = "none";
document.getElementById("network-error-online").style.display = "none";
console.log("Network Stats : ", result);
document.getElementById("download-speed").innerHTML = result["downloadSpeed"] + " MBPS";
document.getElementById("upload-speed").innerHTML = result["uploadSpeed"] + " MBPS";
document.getElementById("network-stats").style.display = "flex";
} catch (error) {
this.document.getElementById("network-stats").style.display = "none";
console.log(error);
if (error == "Not able to get NetworkStats due to no Network") {
this.document.getElementById("network-error-offline").style.display = "flex"
console.log("Error in Network Stats : ", error);
} else if (error == "Not able to get NetworkStats due to timeout") {
this.document.getElementById("network-error-online").style.display = "flex"
console.log("Error in Network Stats : ", error);
}
}
});
networkErrorRefreshButton.forEach((refersh) => {
refersh.addEventListener("click", async () => {
try {
const refreshElement = document.getElementById("refresh");
console.log(refreshElement);
refreshElement.firstElementChild.classList.remove("bi-arrow-cloclwise");
refreshElement.firstElementChild.classList.add("bi-arrow-repeat");
refreshElement.classList.add("spin");
this.document.getElementById("download-speed-div").style.display = "none";
this.document.getElementById("upload-speed-div").style.display = "none";
this.document.getElementById("check-speed-div").style.display = "unset";
this.document.getElementById("network-stats").style.marginLeft = "445px";
const result = await window.VideoSDK.getNetworkStats({ timeoutDuration: 120000 });
// console.log("SUII");
this.document.getElementById("download-speed-div").style.display = "flex";
this.document.getElementById("upload-speed-div").style.display = "flex";
this.document.getElementById("check-speed-div").style.display = "none";
this.document.getElementById("network-stats").style.marginLeft = "375px";
refreshElement.firstElementChild.classList.remove("bi-arrow-repeat");
refreshElement.classList.remove("spin");
refreshElement.firstElementChild.classList.add("bi-arrow-cloclwise");
document.getElementById("network-error-offline").style.display = "none";
document.getElementById("network-error-online").style.display = "none";
console.log("Network Stats : ", result);
document.getElementById("download-speed").innerHTML = result["downloadSpeed"] + " MBPS";
document.getElementById("upload-speed").innerHTML = result["uploadSpeed"] + " MBPS";
document.getElementById("network-stats").style.display = "flex";
} catch (error) {
this.document.getElementById("network-stats").style.display = "none";
console.log(error);
if (error == "Not able to get NetworkStats due to no Network") {
this.document.getElementById("network-error-offline").style.display = "flex"
console.log("Error in Network Stats : ", error);
} else if (error == "Not able to get NetworkStats due to timeout") {
this.document.getElementById("network-error-online").style.display = "flex"
console.log("Error in Network Stats : ", error);
}
}
})
})
await window.VideoSDK.getNetworkStats({ timeoutDuration: 120000 })
.then((result) => {
const refreshElement = document.getElementById("refresh");
this.document.getElementById("download-speed-div").style.display = "flex";
this.document.getElementById("upload-speed-div").style.display = "flex";
this.document.getElementById("check-speed-div").style.display = "none";
this.document.getElementById("network-stats").style.marginLeft = "375px";
// console.log("repeat removed")
refreshElement.classList.remove("spin");
refreshElement.firstElementChild.classList.remove("bi-arrow-repeat");
refreshElement.firstElementChild.classList.add("bi-arrow-clockwise");
document.getElementById("network-error-offline").style.display = "none";
document.getElementById("network-error-online").style.display = "none";
console.log("Network Stats : ", result);
document.getElementById("download-speed").innerHTML = result["downloadSpeed"] + " MBPS"
document.getElementById("upload-speed").innerHTML = result["uploadSpeed"] + " MBPS"
document.getElementById("network-stats").style.display = "flex";
})
.catch((error) => {
console.log(error);
if (error == "Not able to get NetworkStats due to no Network") {
this.document.getElementById("network-error-offline").style.display = "flex"
console.log("Error in Network Stats : ", error);
} else if (error == "Not able to get NetworkStats due to timeout") {
this.document.getElementById("network-error-online").style.display = "flex"
console.log("Error in Network Stats : ", error);
}
});
});
async function updateDevices() {
try {
const checkAudioVideoPermission = await window.VideoSDK.checkPermissions();
cameraPermissionAllowed = checkAudioVideoPermission.get(window.VideoSDK.Constants.permission.VIDEO);
microphonePermissionAllowed = checkAudioVideoPermission.get(window.VideoSDK.Constants.permission.AUDIO);
if (cameraPermissionAllowed) {
const cameras = await window.VideoSDK.getCameras();
// console.log(cameraDeviceDropDown);
cameraDeviceDropDown.innerHTML = "";
cameras.forEach(item => {
const li = document.createElement('li');
// console.log(item)
li.id = item.deviceId;
li.textContent = item.label;
// console.log(li);
li.addEventListener("click", function () {
document.getElementById(currentCamera.deviceId).innerHTML = `
${currentCamera.label}
`
currentCamera = item;
console.log(currentCamera);
document.getElementById("select-camera").innerHTML = `
<i class="bi bi-camera-video" style="font-size: 16px;"></i>
${currentCamera.label}
`
document.getElementById(currentCamera.deviceId).innerHTML = `
<i class="bi bi-check2"></i>
${currentCamera.label}
`
toggleWebCam();
toggleWebCam();
})
// if(item.deviceId == "Default")
// console.log(item);
currentCamera = item;
document.getElementById("select-camera").innerHTML = `
<i class="bi bi-camera-video" style="font-size: 16px;"></i>
${currentCamera.label}
`
cameraDeviceDropDown.appendChild(li);
});
document.getElementById(currentCamera.deviceId).innerHTML = `
<i class="bi bi-check2"></i>
${currentCamera.label}
`
} else {
const option = document.createElement('option');
option.value = "Permission needed";
option.text = "Permission needed";
cameraDeviceDropDown.appendChild(option);
cameraDeviceDropDown.disabled = true;
cameraDeviceDropDown.setAttribute("style", "cursor:not-allowed")
}
if (microphonePermissionAllowed) {
const microphones = await window.VideoSDK.getMicrophones();
// console.log(microphones)
const playBackDevices = await window.VideoSDK.getPlaybackDevices();
// console.log(playBackDevices)
microphoneDeviceDropDown.innerHTML = "";
playBackDeviceDropDown.innerHTML = "";
// console.log("Before For Each",microphones)
microphones.forEach((item) => {
// const option = document.createElement('option');
// option.value = item.deviceId;
// option.text = item.label;
// console.log(item);
const li = document.createElement('li');
// li.classList.add("microphone-type");
li.id = item.deviceId;
li.textContent = item.label;
li.addEventListener("click", (e) => {
if (currentMic.deviceId == "communications" || currentMic.deviceId == "default") {
document.querySelector(`#microphoneDeviceDropDown #${currentMic.deviceId}`).innerHTML = `
${currentMic.label}
`
} else {
document.getElementById(currentMic.deviceId).innerHTML = `
${currentMic.label}
`
}
currentMic = item;
console.log(currentMic);
document.getElementById("select-microphone").innerHTML = `
<i class="bi bi-mic" style="font-size: 14px;"></i>
${currentMic.label}
`
if (currentMic.deviceId == "communications" || currentMic.deviceId == "default") {
document.querySelector(`#microphoneDeviceDropDown #${currentMic.deviceId}`).innerHTML = `
<i class="bi bi-check2"></i>
${currentMic.label}
`
} else {
document.getElementById(currentMic.deviceId).innerHTML = `
<i class="bi bi-check2"></i>
${currentMic.label}
`
}
enableMic();
})
if (item.deviceId == 'default') {
currentMic = item;
document.getElementById("select-microphone").innerHTML = `
<i class="bi bi-mic" style="font-size: 14px;"></i>
${currentMic.label}
`
}
// console.log(li);
microphoneDeviceDropDown.appendChild(li);
});
playBackDevices.forEach(item => {
const li = document.createElement('li');
li.classList.add("playback-type");
li.id = item.deviceId;
li.textContent = item.label;
li.addEventListener("click", () => {
if (currentPlayback.deviceId == "communications" || currentPlayback.deviceId == "default") {
document.querySelector(`#playBackDeviceDropDown #${currentPlayback.deviceId}`).innerHTML = `
${currentPlayback.label}
`
} else {
document.getElementById(currentPlayback.deviceId).innerHTML = `
${currentPlayback.label}
`
}
currentPlayback = item;
console.log(currentPlayback);
document.getElementById("select-speaker").innerHTML = `
<i class="bi bi-volume-up" style="font-size: 17px;"></i>
${currentPlayback.label}
`;
// console.log("before tick ")
// console.log(document.getElementById(currentPlayback.deviceId))
setAudioOutputDevice(currentPlayback.deviceId);
if (currentPlayback.deviceId == "communications" || currentPlayback.deviceId == "default") {
document.querySelector(`#playBackDeviceDropDown #${currentPlayback.deviceId}`).innerHTML = `
<i class="bi bi-check2"></i>
${currentPlayback.label}
`
} else {
document.getElementById(currentPlayback.deviceId).innerHTML = `
<i class="bi bi-check2"></i>
${currentPlayback.label}
`
}
})
if (item.deviceId == 'default') {
currentPlayback = item;
document.getElementById("select-speaker").innerHTML = `
<i class="bi bi-volume-up" style="font-size: 17px;"></i>
${currentPlayback.label}
`
}
playBackDeviceDropDown.appendChild(li);
});
document.querySelector(`#microphoneDeviceDropDown #${currentMic.deviceId}`).innerHTML = `
<i class="bi bi-check2"></i>
${currentMic.label}
`
document.querySelector(`#playBackDeviceDropDown #${currentPlayback.deviceId}`).innerHTML = `
<i class="bi bi-check2"></i>
${currentPlayback.label}
`
} else {
const microphoneDeviceOption = document.createElement('option');
microphoneDeviceOption.value = "Permission needed";
microphoneDeviceOption.text = "Permission needed";
microphoneDeviceDropDown.appendChild(microphoneDeviceOption);
const playBackDeviceOption = document.createElement('option');
playBackDeviceOption.value = "Permission needed";
playBackDeviceOption.text = "Permission needed";
playBackDeviceDropDown.appendChild(playBackDeviceOption);
microphoneDeviceDropDown.disabled = true;
playBackDeviceDropDown.disabled = true;
microphoneDeviceDropDown.setAttribute("style", "cursor:not-allowed")
playBackDeviceDropDown.setAttribute("style", "cursor:not-allowed")
}
} catch (Ex) {
console.log("Error in check permission" + Ex);
}
}
function handleInputChange(event) {
console.log("Event called")
var input = event.target;
var inputValue = input.value;
if (input.id === "joinMeetingId") {
joinMeetingCodeValue = inputValue;
} else if (input.id === "name") {
joinNameValue = inputValue;
}
if (joinMeetingCodeValue.length == 14 && joinNameValue.length >= 3) {
console.log("Changes are called")
console.log(document.querySelector(".inner-join-button"));
document.querySelector(".inner-join-button").style.backgroundColor = "#5A6BFF";
document.querySelector(".inner-join-button").style.border = "none";
} else {
document.querySelector(".inner-join-button").style.backgroundColor = "rgb(28, 28, 28)";
document.querySelector(".inner-join-button").style.border = "0.1px solid rgb(122, 122, 122)";
}
}
const setAudioOutputDevice = (deviceId) => {
// console.log(deviceId);
console.log(deviceId);
const audioTags = document.getElementsByTagName("audio");
for (let i = 0; i < audioTags.length; i++) {
console.log(audioTags[i])
audioTags.item(i).setSinkId(deviceId);
}
};
function showInputFields() {
const inputElement = document.querySelectorAll(".join-meeting-input");
inputElement.forEach((element) => {
element.style.display = "block"
})
document.querySelectorAll(".join-btn").forEach((btn => {
btn.style.display = 'none'
}))
}
async function tokenGeneration() {
if (TOKEN != "") {
token = TOKEN;
console.log(token);
} else if (AUTH_URL != "") {
token = await window
.fetch(AUTH_URL + "/generateJWTToken")
.then(async (response) => {
const { token } = await response.json();
console.log(token);
return token;
})
.catch(async (e) => {
console.log(await e);
return;
});
} else if (AUTH_URL == "" && TOKEN == "") {
alert("Set Your configuration details first ");
window.location.href = "/";
// window.location.reload();
} else {
alert("Check Your configuration once ");
window.location.href = "/";
// window.location.reload();
}
}
async function validateMeeting(meetingId, joinMeetingName) {
if (token != "") {
const url = `${API_BASE_URL}/v2/rooms/validate/${meetingId}`;
const options = {
method: "GET",
headers: { Authorization: token },
};
const result = await fetch(url, options)
.then((response) => response.json()) //result will have meeting id
.catch((error) => {
console.error("error", error);
alert("Invalid Meeting Id");
window.location.href = "/";
return;
});
if (result.roomId === meetingId) {
document.getElementById("meetingid").value = meetingId;
document.getElementById("joinPage").style.display = "none";
document.getElementById("gridPpage").style.display = "flex";
toggleControls();
startMeeting(token, meetingId, joinMeetingName);
}
} else {
await fetch(
AUTH_URL + "/validatemeeting/" + meetingId,
{
method: "POST",
headers: {
Authorization: token,
"Content-Type": "application/json",
},
}
)
.then(async (result) => {
const { meetingId } = await result.json();
console.log(meetingId);
if (meetingId == undefined) {
return alert("Invalid Meeting ID ");
} else {
document.getElementById("meetingid").value = meetingId;
document.getElementById("joinPage").style.display = "none";
document.getElementById("gridPpage").style.display = "flex";
toggleControls();
startMeeting(token, meetingId, joinMeetingName);
}
})
.catch(async (e) => {
alert("Meeting ID Invalid", await e);
window.location.href = "/";
return;
});
}
}
function addParticipantToList({ id, displayName }) {
let participantTemplate = document.createElement("div");
participantTemplate.className = "row";
participantTemplate.style.padding = "4px";
participantTemplate.style.marginTop = "1px";
participantTemplate.style.marginLeft = "7px";
participantTemplate.style.marginRight = "7px";
participantTemplate.style.borderRadius = "3px";
participantTemplate.style.border = "1px solid rgb(61, 60, 78)";
participantTemplate.style.backgroundColor = "rgb(0, 0, 0)";
//icon
let colIcon = document.createElement("div");
colIcon.className = "col-2";
colIcon.innerHTML = "Icon";
participantTemplate.appendChild(colIcon);
//name
let content = document.createElement("div");
colIcon.className = "col-3";
colIcon.innerHTML = `${displayName}`;
participantTemplate.appendChild(content);
// participants.push({ id, displayName });
console.log(participants);
participantsList.appendChild(participantTemplate);
participantsList.appendChild(document.createElement("br"));
}
function createLocalParticipant() {
totalParticipants++;
localParticipant = createVideoElement(meeting.localParticipant.id);
localParticipantAudio = createAudioElement(meeting.localParticipant.id);
// console.log("localPartcipant.id : ", localParticipant.className);
// console.log("meeting.localPartcipant.id : ", meeting.localParticipant.id);
videoContainer.appendChild(localParticipant);
}
async function startMeeting(token, meetingId, name) {
if (joinPageVideoStream !== null) {
const tracks = joinPageVideoStream.getTracks();
tracks.forEach((track) => {
track.stop();
});
joinPageVideoStream = null;
joinPageWebcam.srcObject = null;
}
window.VideoSDK.off("device-changed", deviceChangeEventListener);
// Meeting config
window.VideoSDK.config(token);
let customVideoTrack, customAudioTrack;
if (webCamEnable) {
// console.log(cameraDeviceDropDown.value);
customVideoTrack = await window.VideoSDK.createCameraVideoTrack({
cameraId: currentCamera.deviceId ? currentCamera.deviceId : undefined,
optimizationMode: "motion",
multiStream: false,
});
}
if (micEnable) {
console.log("Hello microphone called");
// console.log(microphoneDeviceDropDown.value);
console.log(currentMic.deviceId);
customAudioTrack = await window.VideoSDK.createMicrophoneAudioTrack({
microphoneId: currentMic.deviceId ? currentMic.deviceId : undefined,
encoderConfig: "high_quality",
noiseConfig: {
noiseSuppresion: true,
echoCancellation: true,
autoGainControl: true,
},
});
}
// Meeting Init
meeting = window.VideoSDK.initMeeting({
meetingId: meetingId, // required
name: name, // required
micEnabled: micEnable, // optional, default: true
webcamEnabled: webCamEnable, // optional, default: true
maxResolution: "hd", // optional, default: "hd"
customCameraVideoTrack: customVideoTrack,
customMicrophoneAudioTrack: customAudioTrack,
});
participants = meeting.participants;
console.log("meeting obj : ", meeting);
// Meeting Join
meeting.join();
//create Local Participant
createLocalParticipant();
//add yourself in participant list
if (totalParticipants != 0)
addParticipantToList({
id: meeting.localParticipant.id,
displayName: "You",
});
// Setting local participant stream
meeting.localParticipant.on("stream-enabled", (stream) => {
setTrack(
stream,
localParticipantAudio,
meeting.localParticipant,
(isLocal = true)
);
console.log("webcam used : ", meeting.selectedCameraDevice);
console.log("microphone used : ", meeting.selectedMicrophoneDevice);
});
meeting.localParticipant.on("stream-disabled", (stream) => {
if (stream.kind == "video") {
videoCamOn.style.display = "none";
videoCamOff.style.display = "inline-block";
}
if (stream.kind == "audio") {
micOn.style.display = "none";
micOff.style.display = "inline-block";
}
console.log("webcam used : ", meeting.selectedCameraDevice);
console.log("microphone used : ", meeting.selectedMicrophoneDevice);
});
meeting.on("meeting-joined", () => {
meeting.pubSub.subscribe("CHAT", (data) => {
let { message, senderId, senderName, timestamp } = data;
const chatBox = document.getElementById("chatArea");
const chatTemplate = `
<div style="margin-bottom: 10px; ${meeting.localParticipant.id == senderId && "text-align : right"
}">
<span style="font-size:12px;">${senderName}</span>
<div style="margin-top:5px">
<span style="background:${meeting.localParticipant.id == senderId ? "grey" : "crimson"
};color:white;padding:5px;border-radius:8px">${message}<span>
</div>
</div>
`;
chatBox.insertAdjacentHTML("beforeend", chatTemplate);
});
});
meeting.on("meeting-left", () => {
window.location.reload();
document.getElementById("join-page").style.display = "flex";
});
// Other participants
meeting.on("participant-joined", (participant) => {
totalParticipants++;
let videoElement = createVideoElement(participant.id);
console.log("Video Element Created");
let resizeObserver = new ResizeObserver(() => {
participant.setViewPort(
videoElement.offsetWidth,
videoElement.offsetHeight
);
});
resizeObserver.observe(videoElement);
let audioElement = createAudioElement(participant.id);
remoteParticipantId = participant.id;
participant.on("stream-enabled", (stream) => {
setTrack(stream, audioElement, participant, (isLocal = false));
});
videoContainer.appendChild(videoElement);
console.log("Video Element Appended");
videoContainer.appendChild(audioElement);
addParticipantToList(participant);
setAudioOutputDevice(currentPlayback.deviceId);
});
// participants left
meeting.on("participant-left", (participant) => {
totalParticipants--;
let vElement = document.getElementById(`v-${participant.id}`);
vElement.parentNode.removeChild(vElement);
let aElement = document.getElementById(`a-${participant.id}`);
aElement.parentNode.removeChild(aElement);
//remove it from participant list participantId;
document.getElementById(`p-${participant.id}`).remove();
});
//recording events
meeting.on("recording-started", () => {
console.log("RECORDING STARTED EVENT");
btnStartRecording.style.display = "none";
btnStopRecording.style.display = "inline-block";
});
meeting.on("recording-stopped", () => {
console.log("RECORDING STOPPED EVENT");
btnStartRecording.style.display = "inline-block";
btnStopRecording.style.display = "none";
});
meeting.on("presenter-changed", (presenterId) => {
if (presenterId) {
console.log(presenterId);
//videoScreenShare.style.display = "inline-block";
} else {
console.log(presenterId);
videoScreenShare.removeAttribute("src");
videoScreenShare.pause();
videoScreenShare.load();
videoScreenShare.style.display = "none";
btnScreenShare.style.color = "white";
screenShareOn = false;
console.log(`screen share on : ${screenShareOn}`);
}
});
//add DOM Events
addDomEvents();
}
// joinMeeting();
async function joinMeeting(newMeeting) {
// get Token
tokenGeneration();
let joinMeetingName = document.getElementById("name");
let meetingId = document.getElementById("joinMeetingId").value || "";
if (!newMeeting) {
if (validateMeeting(meetingId, joinNameValue)) {
console.log("meeting Validated");
}
else {
return alert("Please enter the Valid meetingId");
}
}
if (!joinMeetingCodeValue && !newMeeting) {
return alert("Please Provide a meetingId");
}
//create New Meeting
//get new meeting if new meeting requested;
if (newMeeting && TOKEN != "") {
const url = `${API_BASE_URL}/v2/rooms`;
const options = {
method: "POST",
headers: { Authorization: token, "Content-Type": "application/json" },
};
const { roomId } = await fetch(url, options)
.then((response) => response.json())
.catch((error) => alert("error", error));
if (roomId) {
document.getElementById("meetingid").value = roomId;
document.getElementById("joinPage").style.display = "none";
document.getElementById("gridPpage").style.display = "flex";
toggleControls();
startMeeting(token, roomId, 'Admin');
}
} else if (newMeeting && TOKEN == "") {
const options = {
method: "POST",
headers: {
Authorization: token,
"Content-Type": "application/json",
},
body: JSON.stringify({ token }),
};
meetingId = await fetch(AUTH_URL + "/createMeeting", options).then(
async (result) => {
console.log("result of create meeting : ", result);
const { meetingId } = await result.json();
console.log("NEW MEETING meetingId", meetingId);
return meetingId;
}
);
if (meetingId) {
document.getElementById("meetingid").value = meetingId;
document.getElementById("joinPage").style.display = "none";
document.getElementById("gridPpage").style.display = "flex";
toggleControls();
startMeeting(token, meetingId, joinMeetingName);
}
}
}
function validateMeetingId(meetingId) {
const regex = /^[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}$/;
return regex.test(meetingId);
}
// creating video element
function createVideoElement(pId) {
let division;