-
Notifications
You must be signed in to change notification settings - Fork 0
/
myWebRTChub.js
12755 lines (10599 loc) · 470 KB
/
myWebRTChub.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
'use-strict'
//localUsers (lu) send camera and microphone to peers
//peers (o) receive video and audio from peers
//MANY TRICKS TO SAVE BANDWIDTH AND RECEIVING PEERS PROCESSING
// draw all things in local canvas that is broadcast
// saves receivers object-fit for we just send the size needed
// saves receivers clipping to circle
// ...
//EXPORTS so that CLOSURE compiler in ADVANCED preserves function // https://developers.google.com/closure/compiler/docs/api-tutorial3
//window['myWebRTChub'] = myWebRTChub
//window['myWebRTChub.inviteToInstantTalk'] = myWebRTChub.inviteToInstantTalk
/*INTERFACES/Plugins
afterMyWebRTChubInitialisationDoThis()
getDefaultImageForWebRTChub(meetObj, index, canRollOver)
getTotalImagesForWebRTChub(meetObj)
adjustWidthHeightOfPeersInMyWebRTChub(width, height)
adjustWidthHeightOfMySelfInMyWebRTChub(width, height)
*/
//in Safari without ALL then initiator does not fire SIGNAL event
const onlyUseRelayInWebRTC = /* true && isInLocalhost// */ !isSafari && false //only works locally and good for testing if TURN server is working
const onlyUseSTUNservers = false //true does not use TURN servers
const newMediaStreamWithTracks = false
var DEBUGtrueToFalse = true
var show3DaccessWebRTChub = true || isInLocalhost || location.host.toLowerCase().indexOf("classes3d.") != -1
// || location.host.toLowerCase().indexOf("aratschool.") != -1
// || location.host.toLowerCase().indexOf("eupasseio.") != -1)
var speechRecognition
const webRTC_useCacheCanvas2 = false //CPU true: 12 % false: 11% do not detect flickering
//REPLICATED in WebRTChub.java
const SENTENCES_OF_MY_WEBRTC_HUB = [
"waiting for others" //0
, "request video and audio" //1
, "close this participant" //2
, "share screen" //3
, "page" //4
, "not enabled for current page" //5
, "make others fetch this screen (results depend on permissions)" //6
, "allow local access" //7
, "No" //8
, "Yes" //9
, "Never" //10
, "Always" //11
, "microphones off" //12
, "Camera and microphone access failed" //13
, "send to all" //14
, "apply settings" //15
, "share file with others" //16
, "show question" //17
, "question of" //18
, "close meetings" //19
, "screen capture failed" //20
, "screen sharing" //21
, "click image corners to select" //22
, "search" //23
, "choose color" //24
, "to close" //25
, "question" //26
, "answering" //27
, "answer" //28
, "solution" //29
, "name" //30
, "me" //31
, "yes" //32
, "no" //33
, "to return to video conference" //34
, "meeting link" //35
, "edit" //36
, "shows" //37
, "nothing to see" //38
, "please wait" //39
, "manage local users and cameras" //40
, "end all" //41
, "participants" //42
, "create" //43
, "please wait for the answer type" //44
, "student" //45
, "detected emotion" //46
, "add user or camera" //47
, "face detection technology is being loaded" //48
, "image" //49
, "add automatically" //50
, "Can not remove first user" //51
, "Manage meetings and peers" //52
, "all" //53
, "add to meeting" //54
, "send to others" //55
, "no one to send to" //56
, "login as" //57
, "attendant (not host)" //58
, "accept" //59
, "waiting for host" //60
, "eject" //61
, "refuse" //62
, "wait" //63
, "standby" //64
, "Guests" //65
, "Chat center" //66
, "rename" //67
, "remove" //68
, "add user" //69
, "choose initial camera" //70
, "share" //71
, "filter" //72
, "Already present." //73
, "Merge both?" //74
, "choose initial microphone" //75
, "show or select" //76
]
const useThisCheckforConnections = true //true to activate
const ALG_ENCRYPTDECRYPT = "A256CTR"
const openMojis =
["1F44B"
,"1F44C"
,"1F44D"
,"1F44E"
,"1F44F"
,"1F468-200D-1F3EB"
,"1F469-200D-1F393"
,"1F469-200D-1F3EB"
,"1F4AA"
,"1F590"
,"1F596"
,"1F90F"
,"1F919"
,"1F91D"
,"1F91E"
,"1F932"
,"1F9D1-200D-1F393"
,"261D"
,"270A"
,"270B"
,"270C"
]
const trianglesCircleColor_hex = [
"#fff", // white
"#000", // black
"#f00", // red
"#0f0", // green
"#00f", // blue
"#FFB300", // # Vivid Yellow
"#803E75", //# Strong Purple
"#FF6800", //# Vivid Orange
"#A6BDD7", //# Very Light Blue
"#C10020", //# Vivid Red
"#CEA262", //# Grayish Yellow
"#817066", //# Medium Gray
// The following don't work well for people with defective color vision
"#007D34", //# Vivid Green
"#F6768E", //# Strong Purplish Pink
"#00538A", //# Strong Blue
"#FF7A5C", //# Strong Yellowish Pink
"#53377A", //# Strong Violet
"#FF8E00", //# Vivid Orange Yellow
"#B32851", //# Strong Purplish Red
"#F4C800", //# Vivid Greenish Yellow
"#7F180D", //# Strong Reddish Brown
"#93AA00", //# Vivid Yellowish Green
"#593315", //# Deep Yellowish Brown
"#F13A13", //# Vivid Reddish Orange
"#232C16", //# Dark Olive Green
]
var expresionToEmotionIcon = []
expresionToEmotionIcon["angry"] = 7
expresionToEmotionIcon["disgusted"] = 4
expresionToEmotionIcon["fearful"] = 8
expresionToEmotionIcon["happy"] = 3
expresionToEmotionIcon["neutral"] = 5
expresionToEmotionIcon["sad"] = 6
expresionToEmotionIcon["surprised"] = 2
const UseFirebaseToShareObjectsNotMessages = true
var encodedUniqueTokenForTurnServers
var umniverseTurnAssistantsResponses = new Map()
var umniverseTurnAssistantsPhase = new Map()
const umniverseTurnAssistantsPhase_warmup = 0
const umniverseTurnAssistantsPhase_turnserver443 = 1
const umniverseTurnAssistantsPhase_turnserver8443 = 2
const umniverseTurnAssistantsPhase_error = 3
const umniverseTurnAssistantsPhase_umniverseServerData = 4
const umniverseTurnAssistantsPhase_end = 5
var meetingUUIDtoLocalUserInvited = new Map()
var toggleManageLocalUsersToSendTOP = false //do not reset
var manageLocalUsersIsShown
var toggleShowMeetingLinksAndPeersTOP = false //do not reset
let COMMAND_SYMBOL = "#COM@$#"
// variables that do not reset
var closeMyWebRTCdivIfZero = 0
var lastDeviceInfos
var previousWebRTChubIdToDevices
var myWebRTChubEnumerateDevices_previous
var lastMeetingUUIDinMenuMoveMeetingToPlace
var countLocalUserMicrophoneMuteNotUnmute = 0
var alreadyInitializedInUpdateBottomBar
var maxWidthOfVerticalSidePanel = 224
var globalSidePanelDirectionVALUE = undefined
var widthOfVerticalSidePanel = maxWidthOfVerticalSidePanel
var heightOfVerticalSidePanel = "100px"
var webrtchub_numSideSize = 1
var webrtchub_numSideElements = 1
var waitingForResponseGetUserMedia = 0
var lastInitialVideoSelector
var lastAutoSelectFirst
var lastMeetingUUIDwaitingForOthers
var allTheStatusErrors = ""
var allTheUrlsOfErrors = ""
var numberOfUrlsOfErrors = 0
// other vars that never reset please place them in tapalife_fast next to var registerChannelForUUIDpeers !!!
var allPrivateMeetingUUID = []
var allPrivateMeetingUUIDimage = []
var numMeetingsGlobal
var numMeetingsGlobalHidden
var meetingIDselectedWebRTChub
var meetObjActive
var divWithWebRTChub
var mapMeetingToNumPlace3D
var nextNumberForMeeting = 1
var afterGotDevicesForPeers
var initialVideoID = windowLocalStorageRead("webRTChub_initialVideoID")
var initialAudioID = windowLocalStorageRead("webRTChub_initialAudioID")
var setInitial_addGlobalAudioVideoStream
var showingOrHidingTRspecificLocalUserAndObjectPeer = []
var localUserButtonToUpdateInputDevicesUUID
var numLocalUsersGlobal
const maxLocalUsersGlobalPerMeeting = 10
var enteredInitiateHTML = 0
var afterChangeToEmotionExecuteThis
var userChangedWhenNoSpaceBottomBar
var showingWhenNoSpaceBottomBar = true
var localUsersUUIDtoObject
var nextLocalUsersN
var resizeMadeInMyWebRTChubUUID
var manual_slideSwitchVerticalHorizontal = false
var afterSlideSwitchVerticalHorizontal
var adjustWidthHeightOfMySelfInMyWebRTChubUUID
var adjustWidthHeightOfPeersInMyWebRTChubUUID
var adjustNewLocalUserInMyWebRTChubUUID
var timerResizeElementsWithPeersParticipant
var extraPeersToShowInBottomTD
var receiversMessagesStartingWith
var addSettingsToSendAndReceive //receiving gets informed that a new user showed up
var informPluginsThatPeerHasClosed
var questionsControlCenterPOINTER
var tempFunctionToCall //must be global so that the compiler does not minify it
var lastTouchStart
var alreadyEnumeratedDevices
var videoIDsWebRTChub
var lastPrivateMeetingUUID
var firstTimeSendScreenToPeers
var isDebuggingWebRTCpeers
var nextFullLinkGlobal
var simplePeersObjects
var peersSelectorsToUUID
var peersUUIDtoSelectors
var peersUUIDtoUserNames
var peersUUIDtoUserSubjects
var meetingWithUUIDtoPeersObjects
var myMeetingRegisteredInFirebaseChannels
var authorisationsForRequestScreen
var meetingUuid_later = []
var localUserOverdraw
var lastActivateCorner
var beforeLeavingCorner
var alreadyCreatedPeersTopBar
var lastMenuUserCaptionLocaluserID
var showingPeersMyVideo
var showingPeersMyAudio
var videoStreamToCopyToCanvas
var lastVideoStreamToCopyToCanvas
var nextVideoStreamToCopyToCanvasLETTER
var lastVideoStreamLETTERandNUMBER
var screenStreamToCopyToCanvas
var myCanvasToSendIsInMainScreen
var myCanvasInMainScreenSameSizeThanThePeersVideo
var canvasToSendSizeBeforeScreenSharing
var showMyVideoInScreenSharing3x3pos
var zoomVideoCameraProjectingOverScreenSharing
var peersCameraActive
var peersMicrophoneActive
var peersVideoActive = true
var peersSpeakersActive
var mapVideoIDtoOrigStream = new Map() //map of videoID to {stream, uses = 0}
var onNewGetUserMediaChooseThisAudioInputDeviceID
var globalIsMutedBecauseOfSeveralReasons = 0 //subcontrols like youtube players
var mapUsePopupToChoosePeersForAction
var beforeDivEmcopassingAll_INSIDE_BGcolor
var lastObjectsMovedToSidePanel= new Set()
var objectsMovedToSidePanelBeforeAutomaticallyGoingTo3D = new Set()
var lastIDofVideoDevicePeers
var lastIDofAudioDevicePeers
var lastIDofAudioOutputPeers
var retriesToReachUmniverseTurnAssistants = 0
//when FALSE no need to stop coherent with audio that we can not SEE stoping and it is handy to see before enabling
var dxdyToSendToPeers
var lowerFrameRate
var audioRate
var jsonQUESTIONtoSendToOthers = ""
var oWhoseQuestionIsBeingShown
var currentMyQuestionUUID
var imagesOfEmotions
var emotionsRawData
var iconsRawData
var imagesOfIcons
var questionRawData
var URLlinkRawData
var numTransfersLateParticipants
var lastSelectorChosenInShowTopBar
var audioInputSelectPeers
var audioOutputSelectPeers
var videoSelectPeers
var selectorsPeers
var lastSelectorPeersTopBar
var lastTimePlayedNewUserSoundPeers
var redButtonToReturnToVideoConference
var firstTimeLeavingDIVwithPeersWebRTChub
var rectForWetbRTChubFaceDetection
var nextRectOfHeadForAvatarWebRTChub
var lastDetectionAll
var deltaTimeForNextRectForAvatarWebRTChub
var objectsForFaceTrackingJS
var intervalFaceDetectionWebRTChub
var lastEmotionThatWasDetected
var augmentAutomaticallyNextHeadsDetection
var optionsWebRTChubHigh
var optionsWebRTChubMedium
var optionsWebRTChubLow
var optionsWebRTChubDONOTCHANGE
var peersMainVideoWidth
var peersMainVideoHeight
var peersSmallVideoWidth
var peersSmallVideoHeight
var currentWidthHeightPeersGlobalVideoSendDIV
var currentWidthToHeightRatioForCanvasVideoSend
var dxdyIconCornersReceive
var dxdyBigReceiving
functionsToCallWhenToogle3D.add(toCallWhenToogle3DmyWebRTChub)
if(numMeetingsGlobal === undefined)
initiateVarsMyWebRTChub()
//-----------------------------------------------------------
function resizeElementsWithPeersParticipant()
{
myWebRTChub.resizeElementsWithPeersParticipant(undefined, undefined, undefined, undefined, true)
}
//-------------------------------------------------------
function toCallWhenToogle3DmyWebRTChub(to3D)
{
if(to3D)
{
for(let elem of objectsMovedToSidePanelBeforeAutomaticallyGoingTo3D)
if(elem)
myWebRTChub.addOrRemoveFromMainScreen(undefined, elem.meetingUUID, "#" +elem.getId(), true)
objectsMovedToSidePanelBeforeAutomaticallyGoingTo3D.clear()
}
}
//-------------------------------------------------------
function meetObjEmcompassingElement(elem)
{
let encompassingDiv = $(elem).closest(".divEmcopassing_meetings")[0]
if(encompassingDiv)
return meetingsUUIDtoObject.get(encompassingDiv.getId())
}
//-------------------------------------------------------
function initiateVarsMyWebRTChub()
{
numMeetingsGlobal = 0
numMeetingsGlobalHidden = 0
meetingIDselectedWebRTChub = undefined
nextNumberForMeeting = 1
mapMeetingToNumPlace3D = new Map()
numLocalUsersGlobal = 0
localUsersUUIDtoObject = new Map()
activeLocalUser = {} //to be used when no video conf
nextLocalUsersN = 1
activeOtherUserSELECTOR = undefined
resizeMadeInMyWebRTChubUUID = []
afterSlideSwitchVerticalHorizontal = []
adjustWidthHeightOfMySelfInMyWebRTChubUUID = []
adjustWidthHeightOfPeersInMyWebRTChubUUID = []
adjustNewLocalUserInMyWebRTChubUUID = []
extraPeersToShowInBottomTD = []
receiversMessagesStartingWith = []
addSettingsToSendAndReceive = [] //receiving gets informed that a new user showed up
informPluginsThatPeerHasClosed = []
questionsControlCenterPOINTER = undefined
tempFunctionToCall //must be global so that the compiler does not minify it
lastTouchStart = undefined
alreadyEnumeratedDevices = undefined
videoIDsWebRTChub = []
firstTimeSendScreenToPeers = true
isDebuggingWebRTCpeers = true && isInLocalhost
nextFullLinkGlobal = undefined
simplePeersObjects = new Map() //selectorsToObjects
peersSelectorsToUUID = []
peersUUIDtoSelectors = []
peersUUIDtoUserNames = [] //local usernames
peersUUIDtoUserSubjects = [] //local subject
meetingWithUUIDtoPeersObjects = new Map()
myMeetingRegisteredInFirebaseChannels = []
authorisationsForRequestScreen = []
meetingUuid_later = []
lastActivateCorner = ""
alreadyCreatedPeersTopBar
showingPeersMyVideo = true
showingPeersMyAudio = false
videoStreamToCopyToCanvas = new Map()
lastVideoStreamToCopyToCanvas = undefined
nextVideoStreamToCopyToCanvasLETTER = "A" //always increment letter
lastVideoStreamLETTERandNUMBER = "A1"
screenStreamToCopyToCanvas = undefined
myCanvasToSendIsInMainScreen = true
myCanvasInMainScreenSameSizeThanThePeersVideo = false
canvasToSendSizeBeforeScreenSharing = undefined
showMyVideoInScreenSharing3x3pos = undefined
zoomVideoCameraProjectingOverScreenSharing = 1
peersCameraActive = showingPeersMyVideo
peersMicrophoneActive = showingPeersMyAudio
peersSpeakersActive = true
mapUsePopupToChoosePeersForAction = []
beforeDivEmcopassingAll_INSIDE_BGcolor = undefined
//when FALSE no need to stop coherent with audio that we can not SEE stoping and it is handy to see before enabling
const testingWithManyUsers = isInLocalhost && false
dxdyToSendToPeers = testingWithManyUsers ? 80 : 480
lowerFrameRate = 15
audioRate = 16
jsonQUESTIONtoSendToOthers = ""
oWhoseQuestionIsBeingShown
currentMyQuestionUUID
imagesOfEmotions = []
emotionsRawData = []
iconsRawData = []
imagesOfIcons = []
questionRawData = undefined
URLlinkRawData = undefined
numTransfersLateParticipants = 0
lastSelectorChosenInShowTopBar = undefined
selectorsPeers = []
lastSelectorPeersTopBar = undefined
lastTimePlayedNewUserSoundPeers = 0
redButtonToReturnToVideoConference = undefined
firstTimeLeavingDIVwithPeersWebRTChub = true
rectForWetbRTChubFaceDetection = undefined
nextRectOfHeadForAvatarWebRTChub = []
lastDetectionAll = undefined
deltaTimeForNextRectForAvatarWebRTChub = 333;
objectsForFaceTrackingJS = undefined
intervalFaceDetectionWebRTChub = undefined
lastEmotionThatWasDetected = undefined
augmentAutomaticallyNextHeadsDetection = false
const optionsWebRTChubHighX = testingWithManyUsers ? 640 : 1280
const optionsWebRTChubHighY = testingWithManyUsers ? 480 : 720
optionsWebRTChubHigh =
{ video:
{
width: { ideal:optionsWebRTChubHighX },
height: { ideal:optionsWebRTChubHighY },
facingMode: { ideal:'user' },
frameRate: {ideal: lowerFrameRate}
}
,
audio:
{
sampleSize: {ideal: 16},
echoCancellation: {ideal: true},
noiseSuppression: {ideal: true},
sampleRate: {ideal:16000},
channelCount: {ideal:1}
}
}
if(false)
optionsWebRTChubHigh =
{ video: {} ,
audio: {}
}
optionsWebRTChubMedium =
{ video:
{
width: { ideal:320 },
height: { ideal:240 },
facingMode: { ideal:'user' },
frameRate: {ideal: lowerFrameRate}
}
,
audio:
{
sampleSize: {ideal: audioRate},
echoCancellation: {ideal: true},
noiseSuppression: {ideal: true},
sampleRate: {ideal:16000},
channelCount: {ideal:1}
}
}
optionsWebRTChubLow =
{ video:
{
width: { ideal:160 },
height: { ideal:120 },
facingMode: { ideal:'user' },
frameRate: {ideal: lowerFrameRate}
}
,
audio:
{
sampleSize: {ideal: audioRate},
echoCancellation: {ideal: true},
noiseSuppression: {ideal: true},
sampleRate: {ideal:16000},
channelCount: {ideal:1}
}
}
optionsWebRTChubDONOTCHANGE = optionsWebRTChubHigh
peersMainVideoWidth = dxdyToSendToPeers + "px"
peersMainVideoHeight = dxdyToSendToPeers + "px"
peersSmallVideoWidth = "72px"
peersSmallVideoHeight = "72px"
currentWidthHeightPeersGlobalVideoSendDIV = 72
currentWidthToHeightRatioForCanvasVideoSend = 1
dxdyIconCornersReceive = 44
dxdyBigReceiving = dxdyToSendToPeers
}
//----------------------------------------------------
async function myWebRTChub_showEffects(localUser, effectParam)
{
const player = await Banuba_constructors.Player.create({ clientToken: "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" })
//const camera = await navigator.mediaDevices.getUserMedia({ audio: false, video: {deviceId:localUser.videoStream.deviceID} })
player.use(new Banuba_constructors.MediaStream(localUser.videoStream.video.srcObject))
let moduleURL
let effectURL
switch(effectParam)
{
case "Background 1":
moduleURL = "https://cdn.jsdelivr.net/npm/@banuba/webar/dist/modules/background.zip"
effectURL = "https://storage.googleapis.com/cdniverse/banuba-quickstart-web/effects/BackgroundPicture.zip"
break
case "Hat+Glasses":
moduleURL = "https://cdn.jsdelivr.net/npm/@banuba/webar/dist/modules/face_tracker.zip"
effectURL = "https://storage.googleapis.com/cdniverse/banuba-quickstart-web/effects/BigPinkGlasses.zip"
break
}
let module = banubaModules.get(moduleURL)
if(!module)
{
module = await new Banuba_constructors.Module(moduleURL)
banubaModules.set(moduleURL, module)
}
await player.addModule(module)
let effect = banubaEffects.get(effectURL)
if(!effect)
{
effect = await new Banuba_constructors.Effect(effectURL)
banubaEffects.set(effectURL, effect)
}
await player.applyEffect(effect)
Banuba_constructors.Dom.render(player, "#webar")
}
//-------------------------------------------------------
//HERE AND NOT IN tapalife_youte.js because of loading
function tapalifeYouTube_addToSettingsToSendToOther(sendingNotReceiving, settings, o)
{
let meetingUUID = o.meetingUUID
let meetObj = meetingsUUIDtoObject.get(meetingUUID)
if(sendingNotReceiving)
{
if(!tapalifeYouTube)
return
let s = ""
for(let [uuid, player] of youtubePlayers)
{
if(!player.sharedAmongAll || player.myLastTime == 0)
if(player.meetingWithUUID || !player.shared)
continue
if(player.myLastTime > 0)
player.sharedAmongAllAlreadySynced = true
let h = tapalifeYouTube.stringToSharePlayer(player)
s += h.length + " " + h
}
if(s != "")
settings.tapalifeYouTube_settings = s
}
else if(!settings.tapalifeYouTube_settings)
return
else if(!tapalifeYouTube)
loadScripts([compiledOrNotPathJS + "/static/tapalife_youtube"+ compiledOrNotJS +".js", "https://www.youtube.com/iframe_api"], undefined, undefined, undefined, function(){tapalifeYouTube_addToSettingsToSendToOther(sendingNotReceiving, settings, o)})
else
{
let s = settings.tapalifeYouTube_settings
let lastPos = 0
while(lastPos < s.length)
{
let pos = s.indexOf(' ', lastPos)
let numberW = parseInt(s.slice(lastPos, pos))
lastPos = pos + 1 + numberW
let parameters = s.slice(pos + 1, lastPos)
tapalifeYouTube.processReceivedFromPeer(meetingUUID, o, parameters)
}
}
}
//------------------------------------------
function createAudioMeter(meetObj, clipLevel, averaging, clipLag)
{
let audioContext = meetObj.audioContext
const processor = audioContext.createScriptProcessor(256, 1, 1)
processor.meetObj = meetObj
processor.onaudioprocess = volumeAudioProcess
processor.clipping = false
processor.lastClip = 0
processor.volume = 0
processor.clipLevel = clipLevel || 0.98
processor.averaging = averaging || 0.95
processor.clipLag = clipLag || 750
// this will have no effect, since we don't copy the input to the output,
// but works around a current Chrome bug.
processor.connect(audioContext.destination)
processor.checkClipping = function () {
if (!this.clipping) {
return false
}
if ((this.lastClip + this.clipLag) < window.performance.now()) {
this.clipping = false
}
return this.clipping
}
return processor
}
//---------------------------------
function webrtcDivName(meetingUUID)
{
return meetingUUID ? webrtc_div_name + meetingUUID.replaceAll("-", "") : undefined
}
//---------------------------------------------------
const observer_webrtchub = new ResizeObserver(function()
{
myWebRTChub.resizeElementsWithPeersParticipant(undefined, undefined, undefined, undefined, true)
})
//---------------------------------
function volumeAudioProcess(event)
{
let processor = event.srcElement
let meetObj = processor.meetObj
if(!meetObj.audioLocalUser)
return
const buf = event.inputBuffer.getChannelData(0)
const bufLength = buf.length
let sum = 0
let x
// Do a root-mean-square on the samples: sum up the squares...
for (let i = 0; i < bufLength; i++) {
x = buf[i]
if (Math.abs(x) >= this.clipLevel) {
this.clipping = true
this.lastClip = window.performance.now()
}
sum += x * x
}
// ... then take the square root of the sum.
const rms = Math.sqrt(sum / bufLength)
// Now smooth this out with the averaging factor applied
// to the previous sample - take the max here because we
// want "fast attack, slow release."
this.volume = Math.max(rms, this.volume * this.averaging)
// document.getElementById('webrtc_audio_volume').innerHTML = Math.min(10, Math.round(this.volume * 20))
let vol80 = peersMicrophoneActive && !meetObj.disabled && meetObj.microphoneActive && !meetObj.activeLocalUser.microphoneMuted ? Math.round(this.volume * 250) : 0
let speaking = (vol80 > 20)
let localUser = meetObj.audioLocalUser
if(localUser.isSpeaking != speaking)
{
localUser.isSpeaking = speaking
if(speaking)
{
if(localUser.timerOffSpeaking)
clearTimeout(localUser.timerOffSpeaking)
myWebRTChub.sendMyMicInfoToOthers(localUser, true)
}
else
localUser.timerOffSpeaking = setTimeout(function(){localUser.timerOffSpeaking = undefined; myWebRTChub.sendMyMicInfoToOthers(localUser, true)}, 1500)
}
$("#rowOfLocalUser_"+meetObj.audioLocalUser.uuid).css("background-color", "rgb(" + (100 + vol80 * 2) + ", "+(100 - vol80)+","+ (100 - vol80) + ")")
}
//---------------------------------
function updateTrackCount(event)
{
let stream = event.srcElement
//alert("1 type="+ event.track.kind + " count=" + stream.getVideoTracks().length)
}
//---------------------------------
function updateTrackCount2(event)
{
let stream = event.srcElement
//alert("2 type="+ event.track.kind + " count=" + stream.getVideoTracks().length)
}
//----------------------------------------------------------------------------
function globalSidePanelDirection()
{
const panel = $("#globalSidePanel_" + globalSidePanelDirectionVALUE)[0]
if(globalSidePanelDirectionVALUE === undefined
|| (!manual_slideSwitchVerticalHorizontal && (panel.offsetWidth === 0 || panel.offsetHeight === 0)))
globalSidePanelDirectionVALUE = windowWidth() >= windowHeight() ? "vertical" : "horizontal"
return globalSidePanelDirectionVALUE
}
//---------------------------------
function meetingSelectedWebRTC()
{
let meetObj = meetingsUUIDtoObject.get(meetingIDselectedWebRTChub)
if(!meetObj)
for([meetingIDselectedWebRTChub, meetObj] of meetingsUUIDtoObject)
if(!meetObj.notYetUsable)
break //selects first
return meetObj
}
//---------------------------------------
function SVG_XML_cleanAndComplete(svgxml)
{
let pos = svgxml.indexOf("<svg ")
if(pos > 0)
svgxml = svgxml.slice(pos)
return svgxml
}
//---------------------------------------
function changeToColorTrianglesCircle(color)
{
let changed = false
let appliable= false
if(activeLocalUser.circledGlobalVideoForPeers != 0)
{
appliable= true
if(activeLocalUser.circledAndTrianglesColors[0] != color)
{
changed = true
activeLocalUser.circledAndTrianglesColors[0] = color
}
}
else
for(let i = 1; i <= 4; i++)
if(activeLocalUser.showNotHideCornersOfVideoToSend[i])
{
appliable= true
if(activeLocalUser.circledAndTrianglesColors[i] != color)
{
changed = true
activeLocalUser.circledAndTrianglesColors[i] = color
}
}
if(changed)
myWebRTChub.toggleCornersVisibility()
else if(!appliable) //changes all colors!!! (hidden but can be shown later)
for(let i = 0; i <= 4; i++)
activeLocalUser.circledAndTrianglesColors[i] = color
$("#buttonsPeersTrianglesCircleColors").css("backgroundColor",color)
myWebRTChub.putValueAndSendToPeersAllSiblingsEqual(activeLocalUser, "circledAndTrianglesColors", activeLocalUser.circledAndTrianglesColors, undefined)
return changed
}
//---------------------------------------
function chooseColorTrianglesCircle()
{
if(dismissPopup1("chooseColorTrianglesCircle"))
return
let element = getPopup1("chooseColorTrianglesCircle")
element.style.color = "#000"
element.style.width = ""
element.style.height = ""
element.style.backgroundColor = "#fff"
let s = "<div onClick='dismissPopup1(\"chooseColorTrianglesCircle\")'><br><b>     " + TLtranslateFromTo(SENTENCES_OF_MY_WEBRTC_HUB[24])+"</b>"
+ "   <b style='cursor:pointer; color:#800'>   X   </b><br><br><table border='1' >"
for(let r = 0; r < 5; r++)
{
s += "<tr>"
for(let c = 0; c < 5; c++)
{
let color = trianglesCircleColor_hex[r*5 + c];
s += "<td onClick='if(changeToColorTrianglesCircle(\""+color+"\")) event.stopPropagation()' style='cursor:pointer;width:3em;height:3em;background-color:"+color+"'> </td>"
}
s += "</tr>"
}
s += "</table>"
+ "</nobr><br></div>"
$(element).html(s).show()
}
//---------------------------------------
function CTXtriangle(c, bkColor, color, x1, y1, x2, y2, x3, y3)
{
c.beginPath();
c.moveTo(x1, y1);
c.lineTo(x2, y2);
c.lineTo(x3, y3);
c.closePath();
if(bkColor !== undefined)
{
c.fillStyle = bkColor;
c.fill();
}
if(color !== undefined)
{
c.lineWidth = 2;
c.strokeStyle = color;
c.stroke();
}
}
//---------------------------------------------
function addTextToReceiveBox(selector, html, selectorColorYellow)
{
if(selectorColorYellow)
$(selectorColorYellow).css("backgroundColor","#e75480")
let arr = $(selector)
arr[0].insertAdjacentHTML("beforeend", html)
arr.stop().animate(({scrollTop: arr[0].scrollHeight}))
}
//------------------------------------------------
function handleErrorForPeers(error)
{
console.log('navigator.MediaDevices.getUserMedia error: ', error.message, error.name);
}
//-------------------------------------------
function showThisSelectorTopBar(selector)
{
if(lastSelectorPeersTopBar == "#topMenuChoicesPeers" && selector != "#topMenuChoicesPeers")
$("#topMenuChoicesPeers").slideUp(500)
else if(lastSelectorPeersTopBar == "#selectorPeersTD" && selector != "#selectorPeersTD")
$("#selectorPeersTD").slideUp(500)
else if(lastSelectorPeersTopBar == "#topMenuQuestionsPeers" && selector != "#topMenuQuestionsPeers")
$("#topMenuQuestionsPeers").slideUp(500)
else if(lastSelectorPeersTopBar == "#topMenuQuestionsForOthers" && selector != "#topMenuQuestionsForOthers")
$("#topMenuQuestionsForOthers").slideUp(500)
else if(lastSelectorPeersTopBar == "#topMenuGeneralUseMyWebRTChub" && selector != "#topMenuGeneralUseMyWebRTChub")