This repository has been archived by the owner on Jan 18, 2023. It is now read-only.
forked from steveseguin/vdo.ninja
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
5681 lines (4927 loc) · 184 KB
/
main.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
/*
* Copyright (c) 2020 Steve Seguin. All Rights Reserved.
*
* Use of this source code is governed by the APGLv3 open-source license
* that can be found in the LICENSE file in the root of the source
* tree. Alternative licencing options can be made available on request.
*
*/
/*jshint esversion: 6 */
var formSubmitting = true;
var activatedPreview = false;
function getById(id) {
var el = document.getElementById(id);
if (!el) {
warnlog(id + " is not defined; skipping.");
el = document.createElement("span"); // create a fake element
}
return el;
}
function changeParam(url,paramName,paramValue){
var qind = url.indexOf('?');
var params = url.substring(qind).split('&');
var query = '';
for(var i=0;i<params.length;i++) {
var tokens = params[i].split('=');
var name = tokens[0];
if (tokens.length > 1 && tokens[1] !== ''){
var value = tokens[1];
} else{
value = "";
}
if (name == paramName) {
value = paramValue;
}
if (value!==""){
value = '=' + value;
}
if(query == '') {
query = name + value;
} else {
query = query + '&' + name + value;
}
}
return url.substring(0,qind) + query;
}
function updateURL(param, force=false) {
var para = param.split('=');
if (!(urlParams.has(para[0]))){
if (history.pushState){
var arr = window.location.href.split('?');
var newurl;
if (arr.length > 1 && arr[1] !== '') {
newurl = window.location.href + '&' +param;
} else {
newurl = window.location.href + '?' +param;
}
window.history.pushState({path:newurl},'',newurl);
}
} else if (force){
if (history.pushState){
var href = new URL(window.location.href);
if (para.length==1){
href = changeParam(window.location.href,para[0],"")
} else {
href = changeParam(window.location.href,para[0],para[1]);
}
log(href.toString());
window.history.pushState({path:href.toString()},'',href.toString());
}
}
if (session.sticky){
setCookie("settings", encodeURI(window.location.href), 90);
}
}
(function (w) {
w.URLSearchParams = w.URLSearchParams || function (searchString) {
var self = this;
self.searchString = searchString;
self.get = function (name) {
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(self.searchString);
if (results == null) {
return null;
}
else {
return decodeURI(results[1]) || 0;
}
};
};
})(window);
var urlParams = new URLSearchParams(window.location.search);
sanitizeStreamID = function(streamID){
streamID = streamID.trim();
if (streamID.length < 1){
streamID = session.generateStreamID(8);
if (!(session.cleanOutput)){
alert("No streamID was provided; one will be generated randomily.\n\nStream ID: "+streamID);
}
}
var streamID_sanitized = streamID.replace(/[\W]+/g,"_");
if (streamID !== streamID_sanitized){
if (!(session.cleanOutput)){
alert("Info: Only AlphaNumeric characters should be used for the stream ID.\n\nThe offending characters have been replaced by an underscore");
}
}
if (streamID_sanitized.length > 24){
streamID_sanitized = streamID_sanitized.substring(0, 24);
if (!(session.cleanOutput)){
alert("The Stream ID should be less than 25 alPhaNuMeric characters long.\n\nWe will trim it to length.");
}
}
return streamID_sanitized;
};
sanitizeRoomName = function(roomid){
roomid = roomid.trim();
if (roomid===""){return roomid;}
else if (roomid===false){return roomid;}
var santized = roomid.replace(/[\W]+/g,"_");
if (santized!==roomid){
if (!(session.cleanOutput)){
alert("Info: Only AlphaNumeric characters should be used for the room name.\n\nThe offending characters have been replaced by an underscore");
}
}
if (santized.length > 30){
santized = santized.substring(0, 30);
if (!(session.cleanOutput)){
alert("The Room name should be less than 31 alPhaNuMeric characters long.\n\nWe will trim it to length.");
}
}
return santized;
};
sanitizePassword = function(passwrd){
if (passwrd===""){return passwrd;}
else if (passwrd===false){return passwrd;}
passwrd = passwrd.trim();
if (passwrd.length < 1){
if (!(session.cleanOutput)){
alert("The password provided was blank.");
}
}
var santized = passwrd.replace(/[\W]+/g,"_");
if (santized!==passwrd){
if (!(session.cleanOutput)){
alert("Info: Only AlphaNumeric characters should be used in the password.\n\nThe offending characters have been replaced by an underscore");
}
}
return santized;
};
if (window.obsstudio){
session.obsfix=15; // can be manually set via URL. ; VP8=15, VP9=30. (previous was 20.)
try{
log("OBS VERSION:"+window.obsstudio.pluginVersion);
log("macOS: "+navigator.userAgent.indexOf('Mac OS X') != -1);
log(window.obsstudio);
if (!(urlParams.has('streamlabs'))){
var ver1 = window.obsstudio.pluginVersion;
ver1 = ver1.split(".");
updateURL("streamlabs");
if (ver1.length == 3){ // Should be 3, but disabled3
if ((ver1.length == 3) && (parseInt(ver1[0])==2) && (parseInt(ver1[1])>4) && (navigator.userAgent.indexOf('Mac OS X') != -1)){
getById("main").innerHTML = "<div style='background-color:black;color:white;' data-translate='obs-macos-not-supported'><h1>On macOS, Please use the <a href='https://github.com/steveseguin/electroncapture'>Electron Capture app</a>, or OBS v23, as newer versions of OBS are not supported currently on macOS.</h1>\
<br /><h2> You can find details <u><a href='https://github.com/steveseguin/obsninja/wiki/FAQ#mac-os'>within our wiki guide - https://github.com/steveseguin/obsninja/wiki/FAQ#mac-os</a></u></h2>\
<br /> If using OBS v23 or Streamlabs, you can bypass this error message by refreshing, <a href='"+ window.location.href +"'> Clicking Here,</a> or by adding <i>&streamlabs</i> to the URL.\
<br /> Please report this problem to [email protected] if you feel it is an error.\
</div>";
}
}
}
} catch(e){errorlog(e);}
window.addEventListener('obsSceneChanged', function(event){
log("OBS EVENT");
log(event.detail.name);
window.obsstudio.getCurrentScene(function(scene) {
log("OBS SCENE");
log(scene);
});
window.obsstudio.getStatus(function (status) {
log("OBS STATUS:");
log(status);
});
});
}
window.onload = function() { // This just keeps people from killing the live stream accidentally. Also give me a headsup that the stream is ending
window.addEventListener("beforeunload", function (e) {
session.ws.close();
session.hangup();
return undefined; // ADDED OCT 29th; get rid of popup. Just close the socket connection if the user is refreshing the page. It's one or the other.
///
// if (formSubmitting) {
// return undefined;
// }
// var confirmationMessage = 'Leaving the page now will terminate your stream ';
// (e || window.event).returnValue = confirmationMessage; //Gecko + IE
// getById("main").innerHTML = "SFSDFSDF";
// return confirmationMessage; //Gecko + Webkit, Safari, Chrome etc.
});
};
getById("credits").innerHTML = "Version: "+session.version+" - "+getById("credits").innerHTML;
var lastTouchEnd = 0;
document.addEventListener('touchend', function (event) {
var now = (new Date()).getTime();
if (now - lastTouchEnd <= 300) {
event.preventDefault();
}
lastTouchEnd = now;
}, false);
var interacted=false;
document.addEventListener('click', function (event) {
if (interacted==false){
interacted=true;
history.pushState({}, '');
}
});
var Callbacks = [];
var CtrlPressed = false; // global
var AltPressed = false;
document.addEventListener("keydown", event => {
if ((event.ctrlKey) || (event.metaKey) ){ // detect if CTRL is pressed
CtrlPressed = true;
} else {
CtrlPressed = false;
}
if (event.altKey){
AltPressed = true;
} else {
AltPressed = false;
}
if (CtrlPressed && event.keyCode){
if (event.keyCode == 77) { // m
if (event.metaKey){
if (AltPressed){
toggleMute(); // macOS
}
} else {
toggleMute(); // Windows
}
// } else if (event.keyCode == 69) { // e
// hangup();
} else if (event.keyCode == 66) { // b
toggleVideoMute();
}
}
});
document.addEventListener("keyup", event => {
if (!((event.ctrlKey) || (event.metaKey))){
if (CtrlPressed){
CtrlPressed = false;
for (var i in Callbacks){
var cb = Callbacks[i];
log(cb.slice(1));
cb[0](...cb.slice(1)); // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax#A_better_apply
}
Callbacks=[];
}
}
if (!(event.altKey)){
AltPressed = false;
}
});
window.onpopstate = function() {
if (interacted){
window.location.reload(true);
}
};
if (typeof session === 'undefined') { // make sure to init the WebRTC if not exists.
var session = WebRTC.Media;
session.streamID = session.generateStreamID();
errorlog("Serious error: WebRTC session didn't load in time");
}
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
if (getCookie("redirect") == "yes"){
setCookie("redirect", "", 0);
session.sticky = true;
} else if (getCookie("settings") != ""){
session.sticky = confirm("Would you like you load your previous session's settings?");
if (!session.sticky){
setCookie("settings", "", 0);
log("deleting cookie as user said no");
} else {
var cookieSettings = decodeURI(getCookie("settings"));
setCookie("redirect", "yes", 1);
window.location.replace(cookieSettings);
}
}
if (urlParams.has('sticky')){
if (getCookie("permission")==""){
session.sticky = confirm("Would you allow us to store a cookie to keep your session settings persistent?");
} else {
session.sticky = true;
}
if (session.sticky){
setCookie("permission", "yes", 999);
setCookie("settings", encodeURI(window.location.href), 90);
}
}
if (urlParams.has('retrytimeout')){
session.retryTimeout = parseInt(urlParams.get('retrytimeout'));
}
if (urlParams.has('nosettings')){
session.showSettings = false;
}
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
//session.webcamonly = true;
getById("shareScreenGear").style.display="none";
getById("container-2").className = 'column columnfade advanced'; // Hide screen share on mobile
} else if ((iOS) || (iPad)){
getById("shareScreenGear").style.display="none";
getById("container-2").className = 'column columnfade advanced'; // Hide screen share on mobile
}
if (urlParams.has('webcam') || urlParams.has('wc')){
session.webcamonly = true;
} else if (urlParams.has('screenshare') || urlParams.has('ss')){
session.screenshare = true;
} else if (urlParams.has('fileshare') || urlParams.has('fs')){
getById("container-5").classList.remove('advanced');
getById("container-3").className = 'column columnfade advanced'; // Hide screen share on mobile
getById("container-2").className = 'column columnfade advanced'; // Hide screen share on mobile
getById("container-5").classList.add("skip-animation");
getById("container-5").classList.remove('pointer');
}
if (urlParams.has('mute') || urlParams.has('muted')){
session.muted = true;
}
if (session.screenshare==true){
getById("container-3").className = 'column columnfade advanced'; // Hide screen share on mobile
getById("container-2").classList.add("skip-animation");
getById("container-2").classList.remove('pointer');
}
if (session.webcamonly==true){
getById("container-2").className = 'column columnfade advanced'; // Hide screen share on mobile
//getById("shareScreenGear").style.display="none"; // removed based on fluffy's feedback
getById("container-3").classList.add("skip-animation");
getById("container-3").classList.remove('pointer');
setTimeout(function(){previewWebcam();},10);
}
getById("main").classList.remove('hidden');
if (urlParams.has('password')){
session.password = urlParams.get('password');
if (session.password.length==0){
session.password = prompt("Please enter the password below: \n\n(Note: Passwords are case-sensitive and you will not be alerted if it is incorrect.)");
} else if (session.password==="false"){
session.password=false;
session.defaultPassword=false;
} else if (session.password==="0"){
session.password=false;
session.defaultPassword=false;
} else if (session.password==="off"){
session.password=false;
session.defaultPassword=false;
}
}
if (session.password){
session.password = sanitizePassword(session.password);
getById("passwordRoom").value = session.password;
session.defaultPassword = false;
}
if (urlParams.has('hash') || urlParams.has('crc') || urlParams.has('check')){ // could be brute forced in theory, so not as safe as just not using a hash check.
var hash_input = urlParams.get('hash') || urlParams.get('crc') || urlParams.get('check');
if (session.password===false){
session.password = prompt("Please enter the password below: \n\n(Note: Passwords are case-sensitive and you will not be alerted if it is incorrect.)");
session.password = sanitizePassword(session.password);
getById("passwordRoom").value = session.password;
session.defaultPassword = false;
}
session.generateHash(session.password+session.salt,6).then(function(hash){ // million to one error.
log("hash is "+hash);
if (hash.substring(0, 4) !== hash_input){ // hash crc checks are just first 4 characters.
if (!(session.cleanOutput)){
alert("The password was incorrect.\n\nRefresh and try again.");
}
} else {
session.hash = hash;
}
});
}
if (session.defaultPassword!==false){
session.password = session.defaultPassword; // no user entered password; let's use the default password if its not disabled.
}
if (urlParams.has('label')){
session.label = decodeURIComponent(urlParams.get('label'));
if (session.label.length==0){
session.label = prompt("Please enter your display name:");
}
session.label = session.label.replace(/[\W]+/g,"_").replace(/_+/g, '_'); // but not what others might get.
document.title=session.label.replace(/_/g, ' '); // what the result is.
updateURL("label="+session.label, true);
}
if (urlParams.has('transparent')){ // sets the window to be transparent - useful for IFRAMES?
getById("main").style.backgroundColor = "rgba(0,0,0,0)";
}
if (urlParams.has('stereo') || urlParams.has('s') || urlParams.has('proaudio')){ // both peers need this enabled for HD stereo to be on. If just pub, you get no echo/noise cancellation. if just viewer, you get high bitrate mono
log("STEREO ENABLED");
session.stereo = urlParams.get('stereo') || urlParams.get('s') || urlParams.get('proaudio');
if (session.stereo){
session.stereo = session.stereo.toLowerCase();
}
if (session.stereo==="false"){
session.stereo = 0;
} else if (session.stereo==="0"){
session.stereo = 0;
} else if (session.stereo==="no"){
session.stereo = 0;
} else if (session.stereo==="off"){
session.stereo = 0;
} else if (session.stereo==="1"){
session.stereo = 1;
} else if (session.stereo==="both"){
session.stereo = 1;
} else if (session.stereo==="3"){
session.stereo = 3;
} else if (session.stereo==="out"){
session.stereo = 3;
} else if (session.stereo==="4"){
session.stereo = 4;
} else if (session.stereo==="2"){
session.stereo = 2;
} else if (session.stereo==="in"){
session.stereo = 2;
} else {
session.stereo = 5; // guests; no stereo in, no high bitrate in, but otherwise like stereo=1
}
}
if ((session.stereo==1) || (session.stereo==3) || (session.stereo==4) || (session.stereo==5)){
session.echoCancellation = false;
session.autoGainControl = false;
session.noiseSuppression = false;
}
if ((iOS) || (iPad)){
session.audiobitrate = false; // iOS devices seem to get distortion with custom audio bitrates. Disable for now.
session.maxiosbitrate = 10; // this is 10-kbps by default already.
}
if (urlParams.has("aec") || urlParams.has("ec")){
session.echoCancellation = urlParams.get('aec') || urlParams.get('ec');
if (session.echoCancellation){
session.echoCancellation = session.echoCancellation.toLowerCase();
}
if (session.echoCancellation=="false"){
session.echoCancellation = false;
} else if (session.echoCancellation=="0"){
session.echoCancellation = false;
} else if (session.echoCancellation=="no"){
session.echoCancellation = false;
} else if (session.echoCancellation=="off"){
session.echoCancellation = false;
} else {
session.echoCancellation = true;
}
}
if (urlParams.has("autogain") || urlParams.has("ag")){
session.autoGainControl = urlParams.get('autogain') || urlParams.get('ag');
if (session.autoGainControl){
session.autoGainControl = session.autoGainControl.toLowerCase();
}
if (session.autoGainControl=="false"){
session.autoGainControl = false;
} else if (session.autoGainControl=="0"){
session.autoGainControl = false;
} else if (session.autoGainControl=="no"){
session.autoGainControl = false;
} else if (session.autoGainControl=="off"){
session.autoGainControl = false;
} else {
session.autoGainControl = true;
}
}
if (urlParams.has("denoise") || urlParams.has("dn")){
session.noiseSuppression = urlParams.get('denoise') || urlParams.get('dn');
if (session.noiseSuppression){
session.noiseSuppression = session.noiseSuppression.toLowerCase();
}
if (session.noiseSuppression=="false"){
session.noiseSuppression = false;
} else if (session.noiseSuppression=="0"){
session.noiseSuppression = false;
} else if (session.noiseSuppression=="no"){
session.noiseSuppression = false;
} else if (session.noiseSuppression=="off"){
session.noiseSuppression = false;
} else {
session.noiseSuppression = true;
}
}
if (urlParams.has('roombitrate') || urlParams.has('roomvideobitrate') || urlParams.has('rbr')){
log("Room BITRATE SET");
session.roombitrate = urlParams.get('roombitrate') || urlParams.get('rbr') || urlParams.get('roomvideobitrate');
session.roombitrate = parseInt(session.roombitrate);
if (session.roombitrate<1){
session.roombitrate=0;
}
}
if (urlParams.has('audiobitrate') || urlParams.has('ab')){ // both peers need this enabled for HD stereo to be on. If just pub, you get no echo/noise cancellation. if just viewer, you get high bitrate mono
log("AUDIO BITRATE SET");
session.audiobitrate = urlParams.get('audiobitrate') || urlParams.get('ab');
session.audiobitrate = parseInt(session.audiobitrate);
if (session.audiobitrate<1){
session.audiobitrate=false;
} else if (session.audiobitrate>510){
session.audiobitrate=510;
} // this is to just prevent abuse
}
if ((iOS) || (iPad)){
session.audiobitrate = false; // iOS devices seem to get distortion with custom audio bitrates. Disable for now.
}
if (urlParams.has('streamid') || urlParams.has('view') || urlParams.has('v') || urlParams.has('pull')){ // the streams we want to view; if set, but let blank, we will request no streams to watch.
session.view = urlParams.get('streamid') || urlParams.get('view') || urlParams.get('v') || urlParams.get('pull'); // this value can be comma seperated for multiple streams to pull
getById("headphonesDiv2").style.display="inline-block";
getById("headphonesDiv").style.display="inline-block";
if (session.view==null){
session.view="";
}
if (session.view){
if (session.view.split(",").length>1){
session.view_set = session.view.split(",");
}
}
}
if (urlParams.has('nopreview')){
log("preview OFF");
session.nopreview = true;
}
if (urlParams.has('obsfix')){
session.obsfix = urlParams.get('obsfix');
if (session.obsfix){
session.obsfix = session.obsfix.toLowerCase();
}
if (session.obsfix=="false"){
session.obsfix = false;
} else if (session.obsfix=="0"){
session.obsfix = false;
} else if (session.obsfix=="no"){
session.obsfix = false;
} else if (session.obsfix=="off"){
session.obsfix = false;
} else if (parseInt(session.obsfix)>0){
session.obsfix = parseInt(session.obsfix);
} else {
session.obsfix = 1; // aggressive.
}
}
if (urlParams.has('remote') || urlParams.has('rem')){
log("remote ENABLED");
session.remote = urlParams.get('remote') || urlParams.get('rem');
session.remote = session.remote.trim();
}
if (urlParams.has('keyframeinterval') || urlParams.has('keyframerate') || urlParams.has('keyframe') ||urlParams.has('fki')){
log("keyframerate ENABLED");
session.keyframerate = parseInt(urlParams.get('keyframeinterval') || urlParams.get('keyframerate') || urlParams.get('keyframe') || urlParams.get('fki'));
}
if (urlParams.has('optimize')){
session.optimize = true;
}
if (urlParams.has('obsoff') || urlParams.has('oo')){
log("OBS feedback disabled");
session.disableOBS = true;
}
if (urlParams.has('chroma')){
log("Chroma ENABLED");
getById("main").style.backgroundColor = "#"+(urlParams.get('chroma') || "000");
}
if (urlParams.has("videodevice") || urlParams.has("vdevice") || urlParams.has("vd") || urlParams.has("device") || urlParams.has("d")){
session.videoDevice = urlParams.get("videodevice") || urlParams.get("vdevice") || urlParams.get("vd") || urlParams.get("device") || urlParams.get("d");
if (session.videoDevice){
session.videoDevice = session.videoDevice.toLowerCase().replace(/[\W]+/g,"_");
}
if (session.videoDevice=="false"){
session.videoDevice = 0;
} else if (session.videoDevice=="0"){
session.videoDevice = 0;
} else if (session.videoDevice=="no"){
session.videoDevice = 0;
} else if (session.videoDevice=="off"){
session.videoDevice = 0;
} else if (session.videoDevice=="snapcam"){
session.videoDevice = "snap_camera";
} else if (session.videoDevice=="canon"){
session.videoDevice = "eos";
} else if (session.videoDevice=="camlink"){
session.videoDevice = "cam_link";
} else if (session.videoDevice=="ndi"){
session.videoDevice = "newtek_ndi_video";
} else if (session.videoDevice==""){
session.videoDevice = 1;
} else if (session.videoDevice=="1"){
session.videoDevice = 1;
} else if (session.videoDevice=="default"){
session.videoDevice = 1;
} else {
// whatever the user entered I guess
}
if (session.videoDevice === 0){
getById("add_camera").innerHTML = "Share your Microphone";
}
getById("videoMenu").style.display="none";
log("session.videoDevice:"+session.videoDevice);
}
// audioDevice
if (urlParams.has("audiodevice") || urlParams.has("adevice") || urlParams.has("ad") || urlParams.has("device") || urlParams.has("d")){
session.audioDevice = urlParams.get("audiodevice") || urlParams.get("adevice") || urlParams.get("ad") || urlParams.get("device") || urlParams.get("d");
if (session.audioDevice){
session.audioDevice = session.audioDevice.toLowerCase().replace(/[\W]+/g,"_");
}
if (session.audioDevice=="false"){
session.audioDevice = 0;
} else if (session.audioDevice=="0"){
session.audioDevice = 0;
} else if (session.audioDevice=="no"){
session.audioDevice = 0;
} else if (session.audioDevice=="off"){
session.audioDevice = 0;
} else if (session.audioDevice==""){
session.audioDevice = 1;
} else if (session.audioDevice=="1"){
session.audioDevice = 1;
} else if (session.audioDevice=="default"){
session.audioDevice = 1;
} else if (session.audioDevice=="ndi"){
session.audioDevice="line_newtek_ndi_audio";
} else {
// whatever the user entered I guess
}
log("session.audioDevice:" + session.audioDevice);
getById("audioMenu").style.display="none";
getById("headphonesDiv").style.display="none";
getById("headphonesDiv2").style.display="none";
getById("audioScreenShare1").style.display="none";
}
if (urlParams.has("autojoin") || urlParams.has("autostart") || urlParams.has("aj") || urlParams.has("as")){
session.autostart = true;
}
if (urlParams.has('novideo') || urlParams.has('nv') || urlParams.has('hidevideo') || urlParams.has('showonly') ){
session.novideo = urlParams.get('novideo') || urlParams.get('nv') || urlParams.get('hidevideo') || urlParams.get('showonly');
if (!(session.novideo)){
session.novideo=[];
} else {
session.novideo = session.novideo.split(",");
}
log("disable video playback");
log(session.novideo);
}
if (urlParams.has('noaudio') || urlParams.has('na') || urlParams.has('hideaudio') ){
session.noaudio = urlParams.get('noaudio') || urlParams.get('na') || urlParams.get('hideaudio') ;
if (!(session.noaudio)){
session.noaudio=[];
} else {
session.noaudio = session.noaudio.split(",");
}
log("disable audio playback");
}
if (urlParams.has('forceios')){
log("allow iOS to work in video group chat; for this user at least");
session.forceios = true;
}
if (urlParams.has('nocursor')){
session.nocursor = true;
log("DISABLE CURSOR");
var style = document.createElement('style');
style.innerHTML = `
video {
margin: 0;
padding: 0;
overflow: hidden;
cursor: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=), none;
user-select: none;
}
`;
document.head.appendChild(style);
}
if (urlParams.has('vbr')){
session.cbr = 0;
}
if (urlParams.has('minptime')){
session.minptime = parseInt(urlParams.get('minptime')) || 10;
if (session.minptime<10){session.minptime=10;}
}
if (urlParams.has('maxptime')){
session.maxptime = parseInt(urlParams.get('maxptime')) || 30;
if (session.maxptime<session.minptime){session.maxptime=session.minptime;}
}
if (urlParams.has('codec')){
log("CODEC CHANGED");
session.codec = urlParams.get('codec').toLowerCase();
} //else if (window.obsstudio){
//if (session.obsfix===false){
// session.codec = "h264"; // H264 --- It's too laggy!!! FUCKEEEEEEE
//}
//}
if (urlParams.has('scale')){
log("Resolution scale requested");
session.scale = urlParams.get('scale');
}
var ConfigSettings = getById("main-js");
var ln_template = false;
try {
if (ConfigSettings){
ln_template = ConfigSettings.getAttribute('data-translation'); // Translations
if (typeof ln_template === "undefined" ) {
ln_template = false;
} else if (ln_template === null ) {
ln_template = false;
}
}
if (urlParams.has('ln')){
ln_template = urlParams.get('ln');
}
} catch (e){errorlog(e);}
if (ln_template){ // checking if manual lanuage override enabled
try {
log("Template: "+ln_template);
fetch("./translations/"+ln_template+'.json').then(function(response){
if (response.status !== 200) {
log('Looks like there was a problem. Status Code: ' +
response.status);
return;
}
response.json().then(function(data) {
log(data);
document.querySelectorAll('[data-translate]').forEach(function(ele){
//log(ele.dataset.translate);
//log(translations[ele.dataset.translate]);
if (ele.dataset.translate in data){
ele.innerHTML = data[ele.dataset.translate];
}
});
getById("mainmenu").style.opacity = 1;
}).catch(function(err){
errorlog(err);
getById("mainmenu").style.opacity = 1;
});
}).catch(function(err){
errorlog(err);
getById("mainmenu").style.opacity = 1;
});
} catch (error){
errorlog(error);
getById("mainmenu").style.opacity = 1;
}
if (location.hostname !== "obs.ninja"){
if (session.label===false){
document.title = location.hostname;
}
getById("qos").innerHTML = location.hostname;
getById("logoname").innerHTML = getById("qos").outerHTML;
getById("helpbutton").style.display = "none";
}
} else if (location.hostname === "rtc.ninja"){
try{
if (session.label===false){
document.title = "";
}
getById("qos").innerHTML = "";
getById("logoname").innerHTML = "";
getById("helpbutton").style.display = "none";
getById("helpbutton").style.opacity = 0;
getById("mainmenu").style.opacity = 1;
getById("mainmenu").style.margin = "30px 0";
getById("translateButton").style.display = "none";
getById("translateButton").style.opacity = 0;
getById("info").style.display = "none";
getById("info").style.opacity = 0;
getById("chatBody").innerHTML = "";
} catch(e){}
} else if (location.hostname !== "obs.ninja"){
try {
fetch("./translations/blank.json").then(function(response){
if (response.status !== 200) {
log('Looks like there was a problem. Status Code: ' +
response.status);
return;
}
response.json().then(function(data) {
log(data);
document.querySelectorAll('[data-translate]').forEach(function(ele){
//log(ele.dataset.translate);
//log(translations[ele.dataset.translate]);
if (ele.dataset.translate in data){
ele.innerHTML = data[ele.dataset.translate];
}
});
if (session.label===false){
document.title = location.hostname;
}
getById("qos").innerHTML = location.hostname;
getById("logoname").innerHTML = getById("qos").outerHTML ;
getById("helpbutton").style.display = "none";
getById("mainmenu").style.opacity = 1;
}).catch(function(err){
errorlog(err);
getById("mainmenu").style.opacity = 1;
});
}).catch(function(err){
errorlog(err);
getById("mainmenu").style.opacity = 1;
});
if (session.label===false){
document.title = location.hostname;
}
getById("qos").innerHTML = location.hostname;
getById("logoname").innerHTML = getById("qos").outerHTML;
getById("helpbutton").style.display = "none";
getById("chatBody").innerHTML = "";
} catch (error){
errorlog(error);
}
} else { // check if automatic language translation is available
getById("mainmenu").style.opacity = 1;
}
function changeLg(lang){
fetch("./translations/"+lang+'.json').then(function(response){
if (response.status !== 200) {
logerror('Language translation file not found.' + response.status);
return;
}
response.json().then(function(data) {
log(data);
document.querySelectorAll('[data-translate]').forEach(function(ele){
//log(ele.dataset.translate);
//log(translations[ele.dataset.translate]);
try {
if (ele.dataset.translate in data){
ele.innerHTML = data[ele.dataset.translate];
}
} catch (e){
errorlog(e);
}
});
});
}).catch(function(err){
errorlog(err);
});
}
if (urlParams.has('videobitrate') || urlParams.has('bitrate') || urlParams.has('vb')){
session.bitrate = urlParams.get('videobitrate') || urlParams.get('bitrate') || urlParams.get('vb');
if (session.bitrate){
if ((session.view_set) && (session.bitrate.split(",").length>1)){
session.bitrate_set = session.bitrate.split(",");
session.bitrate = parseInt(session.bitrate_set[0]);
} else {
session.bitrate = parseInt(session.bitrate);
}
if (session.bitrate<1){session.bitrate=false;}
log("BITRATE ENABLED");
log(session.bitrate);
}
}
if (urlParams.has('maxvideobitrate') || urlParams.has('maxbitrate') || urlParams.has('mvb')){