forked from TheMorpheus407/TheCommunity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
5056 lines (4808 loc) · 195 KB
/
app.js
File metadata and controls
5056 lines (4808 loc) · 195 KB
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
/**
* Peer-to-peer WebRTC chat application bootstrap.
* Allows two browsers to exchange messages without a signaling server.
*/
(function () {
const { useState, useRef, useCallback, useEffect } = React;
const EXPECTED_CHANNEL_LABEL = 'chat';
const CONTROL_CHANNEL_LABEL = 'control';
const IMAGE_CHANNEL_LABEL = 'image';
const PONG_CHANNEL_LABEL = 'pong';
const TRIVIA_CHANNEL_LABEL = 'trivia';
const FLAPPYBIRD_CHANNEL_LABEL = 'flappybird';
const CHESS_CHANNEL_LABEL = 'chess';
const MAX_MESSAGE_LENGTH = 2000;
const MAX_MESSAGES_PER_INTERVAL = 30;
const MESSAGE_INTERVAL_MS = 5000;
const CONTROL_MAX_MESSAGES_PER_INTERVAL = 60;
const CONTROL_MESSAGE_INTERVAL_MS = 5000;
const CONTROL_MAX_PAYLOAD_LENGTH = 2048;
const CONTROL_TEXT_INSERT_LIMIT = 32;
const CONTROL_TOTAL_TEXT_BUDGET = 2048;
const IMAGE_MAX_SIZE_BYTES = 5 * 1024 * 1024;
const IMAGE_CHUNK_SIZE = 16 * 1024;
const IMAGE_MAX_PER_INTERVAL = 10;
const IMAGE_INTERVAL_MS = 60000;
const IMAGE_MAX_CONCURRENT = 3;
const ALLOWED_IMAGE_TYPES = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'];
const OPENAI_MODEL = 'gpt-4o-mini';
const OLLAMA_MODEL = 'llama3.2';
const OLLAMA_DEFAULT_ENDPOINT = 'http://localhost:11434';
const AI_PROVIDERS = {
OPENAI: 'openai',
OLLAMA: 'ollama'
};
const THEME_STORAGE_KEY = 'thecommunity.theme-preference';
const AI_PREFERENCE_STORAGE_KEY = 'thecommunity.ai-preference';
const AI_PROVIDER_STORAGE_KEY = 'thecommunity.ai-provider';
const COOKIE_CONSENT_STORAGE_KEY = 'thecommunity.cookie-consent';
const WHISPER_MODEL_STORAGE_KEY = 'thecommunity.whisper-model';
const FRANCONIA_INTRO_SEEN_KEY = 'thecommunity.franconia-intro-seen';
const THEME_OPTIONS = {
LIGHT: 'light',
DARK: 'dark',
RGB: 'rgb',
CAT: 'cat'
};
const THEME_SEQUENCE = [THEME_OPTIONS.DARK, THEME_OPTIONS.LIGHT, THEME_OPTIONS.RGB, THEME_OPTIONS.CAT];
const CAT_AUDIO_STORAGE_KEY = 'thecommunity.cat-audio-settings';
const DEFAULT_CAT_AUDIO_SETTINGS = {
enabled: false,
musicEnabled: false,
sfxEnabled: false,
volume: 50
};
const WHISPER_MODELS = {
TINY_EN: 'Xenova/whisper-tiny.en',
BASE: 'Xenova/whisper-base'
};
const DEFAULT_WHISPER_MODEL = WHISPER_MODELS.TINY_EN;
// Cookie consent categories
const CONSENT_CATEGORIES = {
ESSENTIAL: 'essential',
PREFERENCES: 'preferences',
STATISTICS: 'statistics',
EASTER_EGG: 'easterEgg',
AI_PREFERENCE: 'aiPreference'
};
/**
* Gets the current cookie consent state from localStorage
* @returns {Object} Consent state object with categories
*/
function getCookieConsent() {
try {
const stored = window.localStorage.getItem(COOKIE_CONSENT_STORAGE_KEY);
if (stored) {
return JSON.parse(stored);
}
} catch (error) {
console.warn('Could not read cookie consent from localStorage', error);
}
// Return null if no consent has been given yet
return null;
}
/**
* Saves cookie consent preferences to localStorage
* @param {Object} consent - Consent state object
*/
function saveCookieConsent(consent) {
try {
window.localStorage.setItem(COOKIE_CONSENT_STORAGE_KEY, JSON.stringify(consent));
} catch (error) {
console.warn('Could not save cookie consent to localStorage', error);
}
}
/**
* Checks if a specific consent category is allowed
* @param {string} category - Category to check
* @returns {boolean} True if category is consented or essential
*/
function hasConsentFor(category) {
// Essential is always allowed
if (category === CONSENT_CATEGORIES.ESSENTIAL) {
return true;
}
const consent = getCookieConsent();
// If no consent given yet, return false (show banner)
if (!consent) {
return false;
}
return consent[category] === true;
}
/**
* Creates a default consent object with all categories set to a value
* @param {boolean} value - Default value for all categories
* @returns {Object} Consent object
*/
function createConsentObject(value) {
return {
[CONSENT_CATEGORIES.ESSENTIAL]: true, // Always true
[CONSENT_CATEGORIES.PREFERENCES]: value,
[CONSENT_CATEGORIES.STATISTICS]: value,
[CONSENT_CATEGORIES.EASTER_EGG]: value,
[CONSENT_CATEGORIES.AI_PREFERENCE]: value,
timestamp: Date.now()
};
}
// Room system constants
const PUBLIC_ROOMS = [
'lobby',
'random-1',
'random-2',
'random-3',
'community',
'deutsch',
'gaming',
'tech-talk',
'casual'
];
function getNextThemeValue(currentTheme) {
const index = THEME_SEQUENCE.indexOf(currentTheme);
return THEME_SEQUENCE[(index + 1) % THEME_SEQUENCE.length];
}
/**
* Gets the current room ID from the URL hash
* @returns {string|null} Room ID or null if no room
*/
function getRoomFromHash() {
const hash = window.location.hash;
if (hash && hash.startsWith('#room/')) {
return hash.substring(6); // Remove '#room/'
}
return null;
}
/**
* Sets the room in the URL hash
* @param {string|null} roomId - Room ID to set, or null to clear
*/
function setRoomInHash(roomId) {
if (roomId) {
window.location.hash = `#room/${roomId}`;
} else {
window.location.hash = '';
}
}
/**
* Gets a random public room ID
* @returns {string} Random public room ID
*/
function getRandomPublicRoom() {
const randomIndex = Math.floor(Math.random() * PUBLIC_ROOMS.length);
return PUBLIC_ROOMS[randomIndex];
}
const CONTROL_MESSAGE_TYPES = {
POINTER: 'pointer',
POINTER_VISIBILITY: 'pointer-visibility',
KEYBOARD: 'keyboard',
PERMISSION: 'permission',
ACTION: 'action'
};
/**
* Renders the mascot that reacts angrily on hover.
* Pure SVG so it can be reused without additional assets.
* @param {Object} props
* @param {Object} props.t - Translation object
* @param {string|null} props.animation - Animation type ('flower' or 'diamond')
* @returns {React.ReactElement}
*/
function TuxMascot({ t, animation }) {
const svgChildren = [
React.createElement('ellipse', {
key: 'shadow',
className: 'tux-shadow',
cx: '60',
cy: '112',
rx: '24',
ry: '8'
}),
React.createElement('ellipse', {
key: 'body',
className: 'tux-body',
cx: '60',
cy: '60',
rx: '32',
ry: '46'
}),
React.createElement('ellipse', {
key: 'belly',
className: 'tux-belly',
cx: '60',
cy: '78',
rx: '22',
ry: '28'
}),
React.createElement('ellipse', {
key: 'head',
className: 'tux-head',
cx: '60',
cy: '38',
rx: '26',
ry: '24'
}),
React.createElement('ellipse', {
key: 'face',
className: 'tux-face',
cx: '60',
cy: '47',
rx: '20',
ry: '15'
}),
React.createElement('ellipse', {
key: 'wing-left',
className: 'tux-wing wing-left',
cx: '33',
cy: '70',
rx: '11',
ry: '24'
}),
React.createElement('ellipse', {
key: 'wing-right',
className: 'tux-wing wing-right',
cx: '87',
cy: '70',
rx: '11',
ry: '24'
}),
React.createElement('path', {
key: 'foot-left',
className: 'tux-foot foot-left',
d: 'M44 96 C40 104 44 110 52 110 L58 110 C64 110 66 104 62 96 L56 88 Z'
}),
React.createElement('path', {
key: 'foot-right',
className: 'tux-foot foot-right',
d: 'M76 96 C72 104 76 110 84 110 L90 110 C96 110 98 104 94 96 L88 88 Z'
}),
React.createElement('polygon', {
key: 'beak-upper',
className: 'tux-beak-upper',
points: '60,50 48,56 72,56'
}),
React.createElement('ellipse', {
key: 'beak-lower',
className: 'tux-beak-lower',
cx: '60',
cy: '60',
rx: '12',
ry: '5'
}),
React.createElement('circle', {
key: 'eye-left',
className: 'tux-eye eye-left',
cx: '50',
cy: '44',
r: '7'
}),
React.createElement('circle', {
key: 'eye-right',
className: 'tux-eye eye-right',
cx: '70',
cy: '44',
r: '7'
}),
React.createElement('circle', {
key: 'pupil-left',
className: 'tux-pupil pupil-left',
cx: '52',
cy: '46',
r: '3'
}),
React.createElement('circle', {
key: 'pupil-right',
className: 'tux-pupil pupil-right',
cx: '68',
cy: '46',
r: '3'
}),
React.createElement('circle', {
key: 'glow-left',
className: 'tux-eye-glow glow-left',
cx: '50',
cy: '44',
r: '7'
}),
React.createElement('circle', {
key: 'glow-right',
className: 'tux-eye-glow glow-right',
cx: '70',
cy: '44',
r: '7'
}),
React.createElement('rect', {
key: 'brow-left',
className: 'tux-brow brow-left',
x: '42',
y: '32',
width: '16',
height: '3',
rx: '1.5'
}),
React.createElement('rect', {
key: 'brow-right',
className: 'tux-brow brow-right',
x: '62',
y: '32',
width: '16',
height: '3',
rx: '1.5'
}),
React.createElement('path', {
key: 'steam-left',
className: 'tux-steam steam-left',
d: 'M32 20 C28 14 31 10 35 8 C39 6 40 4 38 2'
}),
React.createElement('path', {
key: 'steam-right',
className: 'tux-steam steam-right',
d: 'M88 20 C92 14 89 10 85 8 C81 6 80 4 82 2'
})
];
// Animation-specific elements
const animationElements = [];
if (animation === 'flower') {
// Flower bouquet (appears between male and female Tux)
animationElements.push(
React.createElement('g', {
key: 'flower-bouquet',
className: 'tux-flower-bouquet'
},
React.createElement('ellipse', { cx: '110', cy: '85', rx: '8', ry: '12', fill: '#ff69b4' }),
React.createElement('ellipse', { cx: '118', cy: '82', rx: '7', ry: '11', fill: '#ff1493' }),
React.createElement('ellipse', { cx: '102', cy: '82', rx: '7', ry: '11', fill: '#ff1493' }),
React.createElement('rect', { x: '108', y: '90', width: '4', height: '15', fill: '#228b22', rx: '2' })
)
);
// Heart (kiss effect)
animationElements.push(
React.createElement('path', {
key: 'kiss-heart',
className: 'tux-kiss-heart',
d: 'M150 50 C150 45 155 40 160 40 C163 40 165 42 166 45 C167 42 169 40 172 40 C177 40 182 45 182 50 C182 58 166 70 166 70 C166 70 150 58 150 50',
fill: '#ff69b4'
})
);
}
if (animation === 'diamond') {
// Diamond ring
animationElements.push(
React.createElement('g', {
key: 'diamond-ring',
className: 'tux-diamond-ring'
},
React.createElement('ellipse', { cx: '110', cy: '85', rx: '6', ry: '3', fill: '#ffd700' }),
React.createElement('path', { d: 'M110 75 L105 82 L115 82 Z', fill: '#b9f2ff' }),
React.createElement('circle', { cx: '110', cy: '78', r: '2', fill: '#ffffff', opacity: '0.8' })
)
);
// Wedding dress decoration
animationElements.push(
React.createElement('g', {
key: 'wedding-dress',
className: 'tux-wedding-dress'
},
React.createElement('path', { d: 'M180 95 C175 85 165 85 160 95 L160 110 C170 110 190 110 200 110 L200 95 C195 85 185 85 180 95', fill: '#ffffff', opacity: '0.9' }),
React.createElement('circle', { cx: '180', cy: '60', r: '8', fill: '#ffffff', opacity: '0.7' })
)
);
}
// Female Tux (rendered when animation is active)
const femaleTuxElements = animation ? [
React.createElement('g', {
key: 'female-tux',
className: 'tux-female',
transform: 'translate(120, 0)'
},
React.createElement('ellipse', { key: 'f-shadow', className: 'tux-shadow', cx: '60', cy: '112', rx: '24', ry: '8' }),
React.createElement('ellipse', { key: 'f-body', className: 'tux-body', cx: '60', cy: '60', rx: '32', ry: '46' }),
React.createElement('ellipse', { key: 'f-belly', className: 'tux-belly', cx: '60', cy: '78', rx: '22', ry: '28' }),
React.createElement('ellipse', { key: 'f-head', className: 'tux-head', cx: '60', cy: '38', rx: '26', ry: '24' }),
React.createElement('ellipse', { key: 'f-face', className: 'tux-face', cx: '60', cy: '47', rx: '20', ry: '15' }),
React.createElement('ellipse', { key: 'f-wing-left', className: 'tux-wing', cx: '33', cy: '70', rx: '11', ry: '24' }),
React.createElement('ellipse', { key: 'f-wing-right', className: 'tux-wing', cx: '87', cy: '70', rx: '11', ry: '24' }),
React.createElement('path', { key: 'f-foot-left', className: 'tux-foot', d: 'M44 96 C40 104 44 110 52 110 L58 110 C64 110 66 104 62 96 L56 88 Z' }),
React.createElement('path', { key: 'f-foot-right', className: 'tux-foot', d: 'M76 96 C72 104 76 110 84 110 L90 110 C96 110 98 104 94 96 L88 88 Z' }),
React.createElement('polygon', { key: 'f-beak-upper', className: 'tux-beak-upper', points: '60,50 48,56 72,56' }),
React.createElement('ellipse', { key: 'f-beak-lower', className: 'tux-beak-lower', cx: '60', cy: '60', rx: '12', ry: '5' }),
React.createElement('circle', { key: 'f-eye-left', className: 'tux-eye', cx: '50', cy: '44', r: '7' }),
React.createElement('circle', { key: 'f-eye-right', className: 'tux-eye', cx: '70', cy: '44', r: '7' }),
React.createElement('circle', { key: 'f-pupil-left', className: 'tux-pupil', cx: '52', cy: '46', r: '3' }),
React.createElement('circle', { key: 'f-pupil-right', className: 'tux-pupil', cx: '68', cy: '46', r: '3' }),
// Bow on head for female
React.createElement('path', { key: 'f-bow', d: 'M50 25 L45 30 L50 28 L55 30 Z M65 25 L70 30 L65 28 L60 30 Z', fill: '#ff69b4', className: 'tux-female-bow' })
)
] : [];
const containerClass = animation ? `tux-mascot tux-animation-${animation}` : 'tux-mascot';
const viewBoxWidth = animation ? '240' : '120';
return React.createElement(
'div',
{
className: containerClass,
role: 'img',
'aria-label': t.mascot.ariaLabel
},
React.createElement(
'svg',
{
className: 'tux-svg',
viewBox: `0 0 ${viewBoxWidth} 120`,
xmlns: 'http://www.w3.org/2000/svg',
'aria-hidden': 'true',
focusable: 'false'
},
[...svgChildren, ...femaleTuxElements, ...animationElements]
)
);
}
/**
* Dolphin mascot component - friendly dolphin for the dolphin-powered chat
* @param {Object} props
* @param {Object} props.t - Translation object
* @returns {React.ReactElement}
*/
function DolphinMascot({ t }) {
return React.createElement(
'div',
{
className: 'dolphin-mascot',
role: 'img',
'aria-label': t?.mascot?.ariaLabel || 'Friendly dolphin mascot'
},
React.createElement(
'svg',
{
className: 'dolphin-svg',
width: '120',
height: '120',
viewBox: '0 0 120 120',
fill: 'none',
xmlns: 'http://www.w3.org/2000/svg',
'aria-hidden': 'true',
focusable: 'false'
},
// Water ripples
React.createElement('ellipse', {
key: 'water-ripple-1',
className: 'dolphin-water-ripple',
cx: '60',
cy: '110',
rx: '40',
ry: '5',
fill: '#87CEEB',
opacity: '0.3'
}),
React.createElement('ellipse', {
key: 'water-ripple-2',
className: 'dolphin-water-ripple',
cx: '60',
cy: '112',
rx: '50',
ry: '4',
fill: '#87CEEB',
opacity: '0.2'
}),
// Tail
React.createElement('path', {
key: 'tail',
className: 'dolphin-tail',
d: 'M20 75 Q10 65 5 70 Q8 80 15 85 Q12 90 10 95 Q15 92 22 82 Z',
fill: '#4A9FD8',
stroke: '#2E7FB8',
strokeWidth: '1.5'
}),
// Body
React.createElement('ellipse', {
key: 'body',
className: 'dolphin-body',
cx: '55',
cy: '70',
rx: '35',
ry: '22',
fill: '#5AB4E8',
stroke: '#2E7FB8',
strokeWidth: '2'
}),
// Belly
React.createElement('ellipse', {
key: 'belly',
className: 'dolphin-belly',
cx: '60',
cy: '75',
rx: '25',
ry: '15',
fill: '#E8F4F8'
}),
// Dorsal fin
React.createElement('path', {
key: 'dorsal-fin',
className: 'dolphin-dorsal-fin',
d: 'M55 50 Q50 35 52 30 Q58 35 60 50 Z',
fill: '#4A9FD8',
stroke: '#2E7FB8',
strokeWidth: '1.5'
}),
// Head
React.createElement('ellipse', {
key: 'head',
className: 'dolphin-head',
cx: '75',
cy: '60',
rx: '20',
ry: '18',
fill: '#5AB4E8',
stroke: '#2E7FB8',
strokeWidth: '2'
}),
// Snout/beak
React.createElement('ellipse', {
key: 'snout',
className: 'dolphin-snout',
cx: '92',
cy: '62',
rx: '12',
ry: '8',
fill: '#5AB4E8',
stroke: '#2E7FB8',
strokeWidth: '2'
}),
React.createElement('ellipse', {
key: 'snout-bottom',
className: 'dolphin-snout-bottom',
cx: '93',
cy: '65',
rx: '10',
ry: '5',
fill: '#E8F4F8'
}),
// Pectoral fin (left)
React.createElement('path', {
key: 'pectoral-fin',
className: 'dolphin-pectoral-fin',
d: 'M50 72 Q35 75 30 80 Q38 82 50 78 Z',
fill: '#4A9FD8',
stroke: '#2E7FB8',
strokeWidth: '1.5'
}),
// Eye
React.createElement('circle', {
key: 'eye-white',
className: 'dolphin-eye-white',
cx: '78',
cy: '55',
r: '5',
fill: 'white'
}),
React.createElement('circle', {
key: 'eye-pupil',
className: 'dolphin-eye-pupil',
cx: '79',
cy: '56',
r: '2.5',
fill: '#1a1a1a'
}),
React.createElement('circle', {
key: 'eye-shine',
className: 'dolphin-eye-shine',
cx: '80',
cy: '54.5',
r: '1.5',
fill: 'white'
}),
// Smile
React.createElement('path', {
key: 'smile',
className: 'dolphin-smile',
d: 'M85 64 Q88 67 92 66',
stroke: '#2E7FB8',
strokeWidth: '1.5',
fill: 'none',
strokeLinecap: 'round'
}),
// Water splashes (animated)
React.createElement('path', {
key: 'splash-1',
className: 'dolphin-splash',
d: 'M95 50 Q98 45 100 48',
stroke: '#87CEEB',
strokeWidth: '2',
fill: 'none',
strokeLinecap: 'round',
opacity: '0.6'
}),
React.createElement('path', {
key: 'splash-2',
className: 'dolphin-splash',
d: 'M102 55 Q105 52 107 55',
stroke: '#87CEEB',
strokeWidth: '2',
fill: 'none',
strokeLinecap: 'round',
opacity: '0.5'
})
)
);
}
/**
* Random room button component showing Tux with a rotating dice
* @param {Object} props
* @param {Object} props.t - Translation object
* @param {Function} props.onClick - Click handler
* @returns {React.ReactElement}
*/
function RandomRoomButton({ t, onClick }) {
return React.createElement(
'button',
{
className: 'random-room-button',
onClick: onClick,
title: t.rooms.randomButtonTitle,
'aria-label': t.rooms.randomButtonAria
},
React.createElement(
'svg',
{
className: 'random-room-svg',
viewBox: '0 0 140 120',
xmlns: 'http://www.w3.org/2000/svg',
'aria-hidden': 'true',
focusable: 'false'
},
// Tux penguin (simplified, sitting pose)
React.createElement('ellipse', { className: 'tux-shadow', cx: '40', cy: '112', rx: '20', ry: '6' }),
React.createElement('ellipse', { className: 'tux-body', cx: '40', cy: '65', rx: '28', ry: '40' }),
React.createElement('ellipse', { className: 'tux-belly', cx: '40', cy: '80', rx: '18', ry: '24' }),
React.createElement('ellipse', { className: 'tux-head', cx: '40', cy: '42', rx: '22', ry: '20' }),
React.createElement('ellipse', { className: 'tux-face', cx: '40', cy: '50', rx: '16', ry: '12' }),
// Wings
React.createElement('ellipse', { className: 'tux-wing', cx: '18', cy: '72', rx: '9', ry: '20' }),
React.createElement('ellipse', { className: 'tux-wing', cx: '62', cy: '72', rx: '9', ry: '20' }),
// Feet
React.createElement('path', { className: 'tux-foot', d: 'M28 98 C25 104 28 108 34 108 L38 108 C42 108 44 104 41 98 Z' }),
React.createElement('path', { className: 'tux-foot', d: 'M52 98 C49 104 52 108 58 108 L62 108 C66 108 68 104 65 98 Z' }),
// Beak
React.createElement('polygon', { className: 'tux-beak-upper', points: '40,48 32,52 48,52' }),
React.createElement('ellipse', { className: 'tux-beak-lower', cx: '40', cy: '54', rx: '8', ry: '3' }),
// Eyes
React.createElement('circle', { className: 'tux-eye', cx: '34', cy: '42', r: '5' }),
React.createElement('circle', { className: 'tux-eye', cx: '46', cy: '42', r: '5' }),
React.createElement('circle', { className: 'tux-pupil', cx: '35', cy: '43', r: '2' }),
React.createElement('circle', { className: 'tux-pupil', cx: '47', cy: '43', r: '2' }),
// Dice (in front of Tux) - 3D cube representation
React.createElement('g', { className: 'dice-cube' },
// Top face
React.createElement('path', {
className: 'dice-face dice-top',
d: 'M85 50 L105 40 L125 50 L105 60 Z'
}),
// Left face
React.createElement('path', {
className: 'dice-face dice-left',
d: 'M85 50 L85 85 L105 95 L105 60 Z'
}),
// Right face
React.createElement('path', {
className: 'dice-face dice-right',
d: 'M105 60 L105 95 L125 85 L125 50 Z'
}),
// Dots on visible faces
React.createElement('circle', { className: 'dice-dot', cx: '105', cy: '50', r: '2' }), // Top center
React.createElement('circle', { className: 'dice-dot', cx: '95', cy: '68', r: '2' }), // Left
React.createElement('circle', { className: 'dice-dot', cx: '95', cy: '77', r: '2' }), // Left
React.createElement('circle', { className: 'dice-dot', cx: '115', cy: '68', r: '2' }), // Right
React.createElement('circle', { className: 'dice-dot', cx: '115', cy: '77', r: '2' }) // Right
)
)
);
}
/**
* World domination plans inspired by "Pinky and the Brain"
*/
const WORLD_DOMINATION_PLANS = [
"Today we shall create a global network of peer-to-peer connections, rendering all centralized servers obsolete!",
"Tonight, Pinky, we take over the world... one WebRTC connection at a time!",
"Are you pondering what I'm pondering? I think so, Brain, but how do we get everyone to use manual signaling?",
"Step 1: Build a chat app. Step 2: Add screen sharing. Step 3: WORLD DOMINATION!",
"The same thing we do every night, Pinky - try to convince people that P2P is the future!",
"Brilliant! We'll use data channels to bypass all traditional infrastructure!",
"They said it couldn't be done - a chat app with NO backend! But they underestimated THE BRAIN!",
"Soon, every connection will be peer-to-peer, and I shall control... NOTHING! Because there's no server! NARF!",
"Phase 1 complete: Manual signaling. Phase 2: Pong game. Phase 3: INEVITABLE VICTORY!",
"While others rely on centralized servers, we shall triumph through distributed architecture!",
"Today, chat messages. Tomorrow, the world! But first, let me fix this ICE candidate issue...",
"A WebRTC empire requires no servers, no backends, no infrastructure - only PURE GENIUS!",
];
/**
* Brain's World Domination Plan component
* Displays a rotating humorous plan inspired by "Pinky and the Brain"
* @param {Object} props
* @param {Object} props.t - Translation object
* @param {boolean} props.isVisible - Whether the plan is visible
* @param {Function} props.onToggle - Toggle visibility handler
* @returns {React.ReactElement}
*/
function BrainsPlan({ t, isVisible, onToggle }) {
const [currentPlanIndex, setCurrentPlanIndex] = React.useState(
Math.floor(Math.random() * WORLD_DOMINATION_PLANS.length)
);
const handleNewPlan = useCallback(() => {
setCurrentPlanIndex((prev) => (prev + 1) % WORLD_DOMINATION_PLANS.length);
}, []);
return React.createElement(
'div',
{ className: `brains-plan ${isVisible ? 'visible' : 'collapsed'}` },
React.createElement(
'div',
{ className: 'brains-plan-header', onClick: onToggle },
React.createElement('span', { className: 'brains-plan-icon' }, '🧠'),
React.createElement('h3', { className: 'brains-plan-title' }, t.brainsPlan?.title || "Brain's Plan for World Domination"),
React.createElement('button', {
className: 'brains-plan-toggle',
'aria-label': isVisible ? (t.brainsPlan?.collapse || 'Collapse') : (t.brainsPlan?.expand || 'Expand'),
'aria-expanded': isVisible
}, isVisible ? '▼' : '▶')
),
isVisible && React.createElement(
'div',
{ className: 'brains-plan-content' },
React.createElement('p', { className: 'brains-plan-text' }, WORLD_DOMINATION_PLANS[currentPlanIndex]),
React.createElement('div', { className: 'brains-plan-actions' },
React.createElement('button', {
className: 'brains-plan-button',
onClick: handleNewPlan
}, t.brainsPlan?.newPlan || 'New Plan')
),
React.createElement('p', { className: 'brains-plan-signature' }, '- The Brain')
)
);
}
/**
* Determines the initial theme, preferring stored settings, then system preference.
* @returns {{theme: 'light'|'dark'|'rgb', isStored: boolean}}
*/
function resolveInitialTheme() {
if (typeof window === 'undefined') {
return { theme: THEME_OPTIONS.DARK, isStored: false };
}
try {
const storedTheme = window.localStorage.getItem(THEME_STORAGE_KEY);
if (storedTheme === THEME_OPTIONS.LIGHT || storedTheme === THEME_OPTIONS.DARK || storedTheme === THEME_OPTIONS.RGB || storedTheme === THEME_OPTIONS.CAT) {
if (typeof document !== 'undefined') {
document.documentElement.dataset.theme = storedTheme;
}
return { theme: storedTheme, isStored: true };
}
} catch (error) {
console.warn('Theme preference could not be read from storage.', error);
}
const prefersDark = typeof window.matchMedia === 'function'
&& window.matchMedia('(prefers-color-scheme: dark)').matches;
const detectedTheme = prefersDark ? THEME_OPTIONS.DARK : THEME_OPTIONS.LIGHT;
if (typeof document !== 'undefined') {
document.documentElement.dataset.theme = detectedTheme;
}
return { theme: detectedTheme, isStored: false };
}
/**
* Checks if the AI modal should be shown based on stored user preference.
* @returns {boolean} true if modal should be shown, false if user previously dismissed it
*/
function shouldShowAiModal() {
if (typeof window === 'undefined') {
return true;
}
try {
const aiPreference = window.localStorage.getItem(AI_PREFERENCE_STORAGE_KEY);
// Don't show modal if user previously dismissed it
return aiPreference !== 'dismissed';
} catch (error) {
console.warn('AI preference could not be read from storage.', error);
// On error, show modal (fail-safe to allow user to interact)
return true;
}
}
/**
* Checks if the Franconia intro video has been seen.
* @returns {boolean} true if intro has been seen, false otherwise
*/
function hasFranconiaIntroBeenSeen() {
if (typeof window === 'undefined') {
return false;
}
try {
return window.localStorage.getItem(FRANCONIA_INTRO_SEEN_KEY) === 'true';
} catch (error) {
console.warn('Franconia intro preference could not be read from storage.', error);
return false;
}
}
/**
* Marks the Franconia intro video as seen.
*/
function markFranconiaIntroAsSeen() {
if (typeof window === 'undefined') {
return;
}
try {
window.localStorage.setItem(FRANCONIA_INTRO_SEEN_KEY, 'true');
} catch (error) {
console.warn('Franconia intro preference could not be saved.', error);
}
}
/**
* Gets the saved AI provider preference from localStorage.
* @returns {string} The saved provider or default (OpenAI)
*/
function getSavedAiProvider() {
if (typeof window === 'undefined') {
return AI_PROVIDERS.OPENAI;
}
try {
const savedProvider = window.localStorage.getItem(AI_PROVIDER_STORAGE_KEY);
if (savedProvider === AI_PROVIDERS.OLLAMA || savedProvider === AI_PROVIDERS.OPENAI) {
return savedProvider;
}
} catch (error) {
console.warn('AI provider preference could not be read from storage.', error);
}
return AI_PROVIDERS.OPENAI;
}
/**
* Root React component that coordinates WebRTC setup and the user interface.
* @returns {React.ReactElement}
*/
function App() {
const initialThemeRef = useRef(null);
if (!initialThemeRef.current) {
initialThemeRef.current = resolveInitialTheme();
}
const [theme, setTheme] = useState(initialThemeRef.current.theme);
const hasStoredThemeRef = useRef(initialThemeRef.current.isStored);
const [language, setLanguage] = useState(getCurrentLanguage());
const t = translations[language] || translations.de;
const [status, setStatus] = useState(t.status.waiting);
const [channelStatus, setChannelStatus] = useState(t.status.channelClosed);
const [localSignal, setLocalSignal] = useState('');
const [remoteSignal, setRemoteSignal] = useState('');
const [messages, setMessages] = useState([]);
const [inputText, setInputText] = useState('');
const [channelReady, setChannelReady] = useState(false);
const [isCreatingOffer, setIsCreatingOffer] = useState(false);
const [isCreatingAnswer, setIsCreatingAnswer] = useState(false);
const [isSignalingCollapsed, setIsSignalingCollapsed] = useState(false);
const [isAboutOpen, setIsAboutOpen] = useState(false);
const [isOffTopicOpen, setIsOffTopicOpen] = useState(false);
const [isHelpOpen, setIsHelpOpen] = useState(false);
const [isImpressumOpen, setIsImpressumOpen] = useState(false);
const [contributors, setContributors] = useState([]);
const [contributorsError, setContributorsError] = useState('');
const [isLoadingContributors, setIsLoadingContributors] = useState(false);
const [copyButtonText, setCopyButtonText] = useState(t.signaling.copyButton);
const [openAiKey, setOpenAiKey] = useState('');
const [isApiKeyModalOpen, setIsApiKeyModalOpen] = useState(shouldShowAiModal());
const [apiKeyInput, setApiKeyInput] = useState('');
const [apiKeyError, setApiKeyError] = useState('');
const [isAiBusy, setIsAiBusy] = useState(false);
const [aiStatus, setAiStatus] = useState('');
const [aiError, setAiError] = useState('');
const [aiProvider, setAiProvider] = useState(getSavedAiProvider());
const [ollamaEndpoint, setOllamaEndpoint] = useState('');
const [isScreenSharing, setIsScreenSharing] = useState(false);
const [shareSystemAudio, setShareSystemAudio] = useState(false);
const [isRemoteScreenActive, setIsRemoteScreenActive] = useState(false);
const [controlChannelReady, setControlChannelReady] = useState(false);
const [isRemoteControlAllowed, setIsRemoteControlAllowed] = useState(false);
const [canControlPeer, setCanControlPeer] = useState(false);
const [remoteControlStatus, setRemoteControlStatus] = useState(t.remoteControl.statusDisabled);
const [remotePointerState, setRemotePointerState] = useState({ visible: false, x: 50, y: 50 });
const [statisticsIssues, setStatisticsIssues] = useState([]);
const [isLoadingStatistics, setIsLoadingStatistics] = useState(false);
const [statisticsError, setStatisticsError] = useState('');
const [randomJoke, setRandomJoke] = useState('');
const [randomN8nExample, setRandomN8nExample] = useState('');
const [tuxAnimation, setTuxAnimation] = useState(null);
const [isPongActive, setIsPongActive] = useState(false);
const [pongScore, setPongScore] = useState({ left: 0, right: 0 });
const [pongLives, setPongLives] = useState({ left: 3, right: 3 });
const [isTriviaActive, setIsTriviaActive] = useState(false);
const [triviaGameState, setTriviaGameState] = useState(null);
const [triviaQuestionCount, setTriviaQuestionCount] = useState(5);
const [isFlappyBirdActive, setIsFlappyBirdActive] = useState(false);
const [flappyBirdScore, setFlappyBirdScore] = useState(0);
const [flappyBirdHighScore, setFlappyBirdHighScore] = useState(0);
const [isDangerZoneModalOpen, setIsDangerZoneModalOpen] = useState(false);
const [dangerZoneAction, setDangerZoneAction] = useState(null);
const [dangerZoneConfirmInput, setDangerZoneConfirmInput] = useState('');
const [isSoundboardOpen, setIsSoundboardOpen] = useState(false);
const [currentRoom, setCurrentRoom] = useState(getRoomFromHash());
const [showCookieBanner, setShowCookieBanner] = useState(getCookieConsent() === null);
const [isCookieSettingsOpen, setIsCookieSettingsOpen] = useState(false);
const [cookieConsent, setCookieConsent] = useState(getCookieConsent() || createConsentObject(false));
const [isRecording, setIsRecording] = useState(false);
const [isTranscribing, setIsTranscribing] = useState(false);
const [whisperModel, setWhisperModel] = useState(() => {
try {
return window.localStorage.getItem(WHISPER_MODEL_STORAGE_KEY) || DEFAULT_WHISPER_MODEL;
} catch {
return DEFAULT_WHISPER_MODEL;
}
});
const [isVoiceSettingsOpen, setIsVoiceSettingsOpen] = useState(false);
const [isBrainsPlanVisible, setIsBrainsPlanVisible] = useState(true);
const [isFranconiaIntroOpen, setIsFranconiaIntroOpen] = useState(false);
const [catAudioSettings, setCatAudioSettings] = useState(() => {
try {
const stored = window.localStorage.getItem(CAT_AUDIO_STORAGE_KEY);
return stored ? JSON.parse(stored) : { ...DEFAULT_CAT_AUDIO_SETTINGS };
} catch (error) {
return { ...DEFAULT_CAT_AUDIO_SETTINGS };
}
});
const pcRef = useRef(null);
const channelRef = useRef(null);
const controlChannelRef = useRef(null);
const imageChannelRef = useRef(null);
const pongChannelRef = useRef(null);
const triviaChannelRef = useRef(null);
const chessChannelRef = useRef(null);
const flappyBirdChannelRef = useRef(null);
const flappyBirdCanvasRef = useRef(null);
const flappyBirdGameRef = useRef(null);
const iceDoneRef = useRef(false);
const screenSenderRef = useRef(null);
const screenAudioSenderRef = useRef(null);
const screenStreamRef = useRef(null);
const remoteScreenStreamRef = useRef(null);
const incomingTimestampsRef = useRef([]);
const messageIdRef = useRef(0);
const messagesContainerRef = useRef(null);
const aboutButtonRef = useRef(null);
const closeAboutButtonRef = useRef(null);
const offTopicButtonRef = useRef(null);
const closeOffTopicButtonRef = useRef(null);
const contributorsLoadedRef = useRef(false);
const apiKeyButtonRef = useRef(null);
const apiKeyInputRef = useRef(null);
const localScreenVideoRef = useRef(null);
const remoteScreenVideoRef = useRef(null);
const remotePointerTimeoutRef = useRef(null);