-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcodec_voice.html
More file actions
931 lines (859 loc) · 50.4 KB
/
codec_voice.html
File metadata and controls
931 lines (859 loc) · 50.4 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title>CODEC — Voice Call</title>
<link rel="icon" href="https://i.imgur.com/jD1X5W8.png">
<link rel="apple-touch-icon" href="https://i.imgur.com/jD1X5W8.png">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap" rel="stylesheet">
<style>
* { margin:0; padding:0; box-sizing:border-box; }
:root {
--bg: #121215; --surface: #1a1a1d; --surface-2: #212125; --surface-3: #2a2a2e;
--border: #303035; --border-hover: #424248;
--text: #ececec; --text-muted: #9a9aa0; --text-dim: #6a6a70;
--accent: #E8711A; --accent-hover: #f07d2a; --accent-dim: rgba(232,113,26,0.10);
--danger: #ef4444; --success: #22c55e; --info: #3b82f6;
--font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
--mono: 'JetBrains Mono', 'SF Mono', monospace;
--radius: 10px; --radius-sm: 6px;
--bg2: #1a1a1d; --bg3: #212125; --bg4: #2a2a2e;
--fg: #ececec; --fg2: #9a9aa0; --fg3: #6a6a70;
--ac: #E8711A; --bd: #303035;
--tx: #ececec; --tx2: #9a9aa0;
--ft: 'Inter', -apple-system, sans-serif;
--mn: 'JetBrains Mono', monospace;
--dn: #ef4444;
--accent2: #ff9a4d; --accent-bg: rgba(232,113,26,0.10);
--safe-top: env(safe-area-inset-top, 0px);
--safe-bottom: env(safe-area-inset-bottom, 0px);
/* Voice-specific */
--green: #66bb6a;
--blue: #40c4ff;
}
/* ── Light mode ── */
[data-theme="light"] {
--bg: #f7f5f2; --surface: #fff; --surface-2: #f0ece6; --surface-3: #e8e4de;
--border: #d5d0ca; --border-hover: #bbb;
--text: #1a1a1a; --text-muted: #555; --text-dim: #777;
/* Override voice-specific vars */
--bg2: #fff; --bd: #d5d0ca; --tx: #1a1a1a; --tx2: #555;
}
[data-theme="light"] .header { background: rgba(247,245,242,0.95); }
[data-theme="light"] .page-nav { background: var(--surface-2); }
[data-theme="light"] .nav-link { color: var(--text-muted); }
[data-theme="light"] .nav-link:hover { color: var(--text); }
[data-theme="light"] .nav-link.active { color: var(--accent); background: var(--accent-dim); }
[data-theme="light"] .icon-btn { border-color: #bbb; color: #444; }
[data-theme="light"] .icon-btn:hover { border-color: #999; color: #1a1a1a; background: #e8e4de; }
[data-theme="light"] body::before { background: radial-gradient(ellipse 60% 60% at 50% 50%, rgba(232,113,26,0.06) 0%, transparent 70%); }
[data-theme="light"] .avatar-core { background: #f0ece6; border-color: #d5d0ca; }
[data-theme="light"] .transcript { background: #fff; border-color: #d5d0ca; }
[data-theme="light"] .transcript-header { border-color: #d5d0ca; }
body {
font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, sans-serif;
background: var(--bg);
color: var(--tx);
height: 100dvh;
display: flex;
flex-direction: column;
overflow: hidden;
position: relative;
padding-top: 0;
}
/* Ambient background glow — reacts to state */
body::before {
content: '';
position: fixed;
inset: 0;
background: radial-gradient(ellipse 60% 60% at 50% 50%, rgba(232,113,26,0.04) 0%, transparent 70%);
transition: all 1s ease;
pointer-events: none;
}
body.state-listening::before { background: radial-gradient(ellipse 60% 60% at 50% 50%, rgba(0,230,118,0.05) 0%, transparent 70%); }
body.state-speaking::before { background: radial-gradient(ellipse 70% 70% at 50% 50%, rgba(232,113,26,0.08) 0%, transparent 70%); }
body.state-processing::before { background: radial-gradient(ellipse 60% 60% at 50% 50%, rgba(64,196,255,0.06) 0%, transparent 70%); }
/* ── Unified Header ── */
.header {
display: flex; align-items: center; justify-content: space-between;
padding: 10px 16px; border-bottom: 1px solid var(--border);
background: rgba(18,18,21,0.9); backdrop-filter: blur(8px);
flex-shrink: 0; position: relative; z-index: 10;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.logo-link { display: flex; align-items: center; text-decoration: none; }
.header img { width: 34px; height: 34px; border-radius: 8px; }
.header h1 { font-family: var(--mono); font-size: 16px; font-weight: 700; letter-spacing: 2px; color: var(--accent); }
.header-right { display: flex; align-items: center; gap: 6px; }
.icon-btn { background: none; border: 1px solid var(--border); color: var(--text-muted); width: 30px; height: 30px; border-radius: 6px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.15s; text-decoration: none; }
.icon-btn:hover { border-color: var(--border-hover); color: var(--text); background: var(--surface-2); }
.icon-btn:active { transform: scale(0.93); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--danger); flex-shrink: 0; transition: all 0.3s; }
.status-dot.on { background: var(--success); box-shadow: 0 0 6px rgba(34,197,94,0.5); }
.ico { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ico-sm { width: 16px; height: 16px; }
/* ── Page Nav ── */
.page-nav { display: flex; align-items: center; gap: 1px; position: absolute; left: 50%; transform: translateX(-50%); background: var(--surface-2); border-radius: var(--radius-sm); padding: 2px; }
.nav-link {
padding: 5px 14px; color: var(--text-muted); text-decoration: none;
font-size: 12px; font-weight: 500; border-radius: 4px;
transition: all 0.15s ease; white-space: nowrap; text-align: center;
}
.nav-link:hover { color: var(--text); }
.nav-link.active { color: var(--accent); background: var(--accent-dim); }
/* ── Scrollbar ── */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
/* Main layout */
.call-container {
flex: 1; display: flex; flex-direction: column;
align-items: center; justify-content: center;
gap: 36px;
max-width: 600px; width: 100%; padding: 32px;
margin: 0 auto;
}
/* ── Avatar ring ── */
.avatar-wrap {
position: relative;
width: 240px; height: 240px;
}
.ring-outer {
position: absolute; inset: 0;
border-radius: 50%;
border: 1.5px solid rgba(232,113,26,0.25);
animation: spin-slow 8s linear infinite;
}
.ring-outer::after {
content: '';
position: absolute;
top: -2px; left: 50%;
width: 6px; height: 6px;
margin-left: -3px;
border-radius: 50%;
background: var(--ac);
box-shadow: 0 0 8px 2px var(--ac);
}
@keyframes spin-slow { 100% { transform: rotate(360deg); } }
.ring-inner {
position: absolute; inset: 16px;
border-radius: 50%;
border: 1px solid var(--bd);
transition: border-color 0.4s, box-shadow 0.4s;
}
.state-listening .ring-inner {
border-color: rgba(0,230,118,0.5);
box-shadow: 0 0 20px rgba(0,230,118,0.15);
animation: pulse-green 1.5s ease-in-out infinite;
}
.state-speaking .ring-inner {
border-color: rgba(232,113,26,0.7);
box-shadow: 0 0 24px rgba(232,113,26,0.25);
animation: pulse-orange 0.6s ease-in-out infinite;
}
.state-processing .ring-inner {
border-color: rgba(64,196,255,0.6);
box-shadow: 0 0 20px rgba(64,196,255,0.15);
}
@keyframes pulse-green {
0%,100% { transform: scale(1); opacity:0.7; }
50% { transform: scale(1.04); opacity:1; }
}
@keyframes pulse-orange {
0%,100% { transform: scale(1); opacity:0.8; }
50% { transform: scale(1.06); opacity:1; }
}
/* ── Live mic energy ring — driven by JS in onaudioprocess ── */
.ring-energy {
position: absolute; inset: 4px;
border-radius: 50%;
border: 2px solid transparent;
pointer-events: none;
transition: transform 0.06s ease-out, box-shadow 0.06s ease-out, border-color 0.06s ease-out;
will-change: transform, box-shadow;
}
.state-listening .ring-energy {
border-color: rgba(0,230,118,0.35);
}
.avatar-core {
position: absolute; inset: 32px;
border-radius: 50%;
background: var(--bg2);
border: 1px solid var(--bd);
display: flex; align-items: center; justify-content: center;
user-select: none;
overflow: hidden;
}
.avatar-core img {
width: 60%; height: 60%; object-fit: contain;
filter: drop-shadow(0 0 12px rgba(232,113,26,0.4));
transition: filter 0.4s;
}
.state-listening .avatar-core img { filter: drop-shadow(0 0 16px rgba(0,230,118,0.5)); }
.state-speaking .avatar-core img { filter: drop-shadow(0 0 20px rgba(232,113,26,0.6)); }
.state-processing .avatar-core img { filter: drop-shadow(0 0 16px rgba(64,196,255,0.5)); }
/* Waveform bars (shown while Q is speaking) */
.waveform {
position: absolute; bottom: 24px;
left: 50%; transform: translateX(-50%);
display: flex; gap: 3px; align-items: flex-end;
height: 20px; opacity: 0;
transition: opacity 0.3s;
}
.state-speaking .waveform { opacity: 1; }
.waveform .bar {
width: 3px; background: var(--ac); border-radius: 2px;
animation: wave 0.8s ease-in-out infinite;
}
.waveform .bar:nth-child(1) { animation-delay: 0s; height: 10px; }
.waveform .bar:nth-child(2) { animation-delay: 0.1s; height: 18px; }
.waveform .bar:nth-child(3) { animation-delay: 0.2s; height: 26px; }
.waveform .bar:nth-child(4) { animation-delay: 0.15s; height: 18px; }
.waveform .bar:nth-child(5) { animation-delay: 0.05s; height: 10px; }
@keyframes wave {
0%,100% { transform: scaleY(1); }
50% { transform: scaleY(1.8); }
}
/* Timer */
.timer {
font-size: 28px; font-weight: 300;
color: var(--tx2); letter-spacing: 0.08em;
font-variant-numeric: tabular-nums;
min-height: 28px;
font-family: 'SF Mono', 'Menlo', monospace;
}
/* Status label */
.status {
font-size: 16px; color: var(--tx2);
text-align: center; letter-spacing: 0.04em;
min-height: 18px; transition: color 0.3s;
}
.state-listening .status { color: var(--green); }
.state-speaking .status { color: var(--ac); }
.state-processing .status { color: var(--blue); }
/* Speak-to-interrupt hint */
.interrupt-hint {
font-size: 11px; color: var(--text-dim); text-align: center;
letter-spacing: 0.05em; min-height: 14px; opacity: 0;
transition: opacity 0.3s; margin-top: 2px;
}
.state-speaking .interrupt-hint,
.state-processing .interrupt-hint { opacity: 1; }
/* Call button */
.call-btn {
width: 72px; height: 72px; border-radius: 50%;
border: none; cursor: pointer; font-size: 22px;
display: flex; align-items: center; justify-content: center;
transition: transform 0.15s, box-shadow 0.2s;
position: relative; z-index: 1;
}
.call-btn::after {
content: ''; position: absolute; inset: -3px;
border-radius: 50%; border: 1px solid transparent;
transition: border-color 0.2s;
}
.call-btn.start {
background: linear-gradient(135deg, #00aa55, #00cc66);
box-shadow: 0 4px 20px rgba(0,170,85,0.35);
}
.call-btn.start:hover { transform: scale(1.07); box-shadow: 0 6px 28px rgba(0,170,85,0.5); }
.call-btn.end {
background: linear-gradient(135deg, #cc2222, #ff3b3b);
box-shadow: 0 4px 20px rgba(255,59,59,0.35);
}
.call-btn.end:hover { transform: scale(1.07); box-shadow: 0 6px 28px rgba(255,59,59,0.5); }
.call-btn:active { transform: scale(0.95); }
/* ── Action buttons row ── */
.action-row {
display: flex; gap: 12px; align-items: center;
opacity: 0; pointer-events: none; transition: opacity 0.3s;
}
body.state-listening .action-row,
body.state-processing .action-row,
body.state-speaking .action-row { opacity: 1; pointer-events: auto; }
.action-btn {
display: flex; align-items: center; gap: 6px;
padding: 8px 18px; border-radius: 20px;
border: 1px solid var(--border); background: var(--surface-2);
color: var(--text-muted); font-size: 13px; font-weight: 500;
cursor: pointer; transition: all 0.15s; font-family: var(--font);
-webkit-tap-highlight-color: transparent;
}
.action-btn:hover { border-color: var(--border-hover); color: var(--text); background: var(--surface-3); }
.action-btn:active { transform: scale(0.95); }
.action-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.action-btn.your-turn { border-color: var(--green); color: var(--green); }
.action-btn.your-turn:hover { background: rgba(102,187,106,0.1); }
body.state-speaking .action-btn.your-turn,
body.state-processing .action-btn.your-turn { opacity: 0.3; pointer-events: none; }
.action-btn.nudge { display: none; }
body.state-processing .action-btn.nudge { display: flex; border-color: var(--blue); color: var(--blue); }
.action-btn.nudge:hover { background: rgba(64,196,255,0.1); }
/* Hold-to-talk indicator */
.hold-indicator {
position: absolute; inset: 0; border-radius: 50%;
background: rgba(102,187,106,0.08);
border: 2px solid var(--green);
opacity: 0; transform: scale(0.95);
transition: opacity 0.2s, transform 0.2s;
pointer-events: none;
}
.hold-indicator.active { opacity: 1; transform: scale(1); }
/* Transcript */
.transcript-wrap {
width: 100%; background: var(--bg2);
border: 1px solid var(--bd); border-radius: 14px;
overflow: hidden; display: flex; flex-direction: column;
box-shadow: 0 2px 8px rgba(0,0,0,0.3);
max-width: 540px;
}
.transcript-header {
padding: 12px 16px;
border-bottom: 1px solid var(--bd);
font-size: 11px; font-weight: 600;
letter-spacing: 0.1em; color: var(--tx2);
font-family: 'SF Mono', monospace;
display: flex; justify-content: space-between; align-items: center;
}
.tx-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--bd); }
.state-listening .tx-dot { background: var(--green); box-shadow: 0 0 6px var(--green); }
.state-speaking .tx-dot { background: var(--ac); box-shadow: 0 0 6px var(--ac); }
.state-processing .tx-dot { background: var(--blue); box-shadow: 0 0 6px var(--blue); }
.transcript {
max-height: 300px; overflow-y: auto;
padding: 16px 20px; font-size: 15px; line-height: 1.7;
scrollbar-width: thin; scrollbar-color: var(--bd) transparent;
}
.transcript::-webkit-scrollbar { width: 4px; }
.transcript::-webkit-scrollbar-track { background: transparent; }
.transcript::-webkit-scrollbar-thumb { background: var(--bd); border-radius: 2px; }
.tx-line { margin-bottom: 8px; animation: fadeIn 0.2s ease; }
.tx-line:last-child { margin-bottom: 0; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }
.tx-line.user { color: var(--ac); }
.tx-line.assistant { color: var(--green); }
.tx-line.system { color: var(--tx2); font-style: italic; font-size: 13px; }
.tx-label { font-weight: 700; margin-right: 6px; font-size: 12px; letter-spacing: 0.05em; }
/* Streaming cursor */
.cursor { display: inline-block; width: 2px; height: 12px;
background: var(--green); margin-left: 2px;
animation: blink 0.7s step-end infinite; vertical-align: middle; }
@keyframes blink { 50% { opacity: 0; } }
/* ── Mobile Responsive ── */
@media (max-width: 768px) {
.page-nav{position:fixed;bottom:0;left:0;right:0;z-index:9998;transform:none;border-radius:0;padding:6px 0;justify-content:center;background:var(--surface);border-top:1px solid var(--border);gap:0}
.nav-link{padding:8px 12px;font-size:11px}
.header { padding: 10px 14px; }
.avatar-wrap { width: 180px; height: 180px; }
.avatar-core { inset: 26px; }
.call-container { gap: 24px; padding: 20px; }
.transcript-wrap { width: 100%; }
.transcript { max-height: 220px; }
.call-btn { width: 64px; height: 64px; }
.timer { font-size: 24px; }
}
@media (max-width: 480px) {
.avatar-wrap { width: 150px; height: 150px; }
.avatar-core { inset: 22px; }
.ring-inner { inset: 12px; }
.timer { font-size: 20px; }
.call-container { gap: 20px; }
.call-btn { width: 56px; height: 56px; }
}
.notif-bell{position:relative}.notif-badge{position:absolute;top:-4px;right:-4px;min-width:16px;height:16px;background:var(--accent);color:#fff;font-size:10px;font-weight:700;border-radius:8px;display:flex;align-items:center;justify-content:center;padding:0 4px;line-height:1;pointer-events:none}.notif-badge.hidden{display:none}
.webcam-pip{position:fixed;bottom:80px;right:20px;width:240px;border-radius:14px;overflow:hidden;border:2px solid var(--accent);box-shadow:0 4px 24px rgba(0,0,0,.5);z-index:9999;display:none;background:#000;transition:width .3s,height .3s,border-radius .3s}
.webcam-pip img,.webcam-pip video{width:100%;display:block}
.webcam-pip.expanded{width:640px;max-width:90vw;border-radius:10px}
.pip-bar{display:flex;justify-content:center;gap:10px;padding:6px;background:rgba(0,0,0,.6)}
.pip-btn{background:rgba(255,255,255,.15);border:none;color:#fff;width:34px;height:34px;border-radius:50%;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:background .15s}
.pip-btn:hover{background:var(--accent)}
.pip-btn.snap-btn{background:rgba(255,80,80,.7)}
.pip-btn.snap-btn:hover{background:#e33}
</style>
</head>
<body id="body">
<header class="header">
<div class="header-left">
<a href="/" class="logo-link"><img src="https://i.imgur.com/jD1X5W8.png" alt="CODEC"></a>
<h1><a href="/" style="color:inherit;text-decoration:none">CODEC</a></h1>
</div>
<nav class="page-nav">
<a href="/chat" class="nav-link">Chat</a>
<a href="/voice" class="nav-link active">Voice</a>
<a href="/vibe" class="nav-link">Vibe</a>
<a href="/tasks" class="nav-link">Tasks</a>
</nav>
<div class="header-right">
<div class="status-dot" id="statusDot" title="CODEC status"></div>
<a href="/" class="icon-btn" title="Dashboard"><svg class="ico" viewBox="0 0 24 24"><path d="M3 9l9-7 9 7v11a2 2 0 01-2 2H5a2 2 0 01-2-2z"/><polyline points="9 22 9 12 15 12 15 22"/></svg></a>
<button class="icon-btn" id="voiceBtn" onclick="toggleVoiceReply()" title="Toggle voice replies"><svg class="ico" viewBox="0 0 24 24"><path d="M11 5L6 9H2v6h4l5 4V5z"/><line x1="23" y1="9" x2="17" y2="15" id="muteX1"/><line x1="17" y1="9" x2="23" y2="15" id="muteX2"/></svg></button>
<button class="icon-btn" onclick="takeScreenshot()" title="Take screenshot"><svg class="ico" viewBox="0 0 24 24"><rect x="2" y="3" width="20" height="14" rx="2"/><line x1="8" y1="21" x2="16" y2="21"/><line x1="12" y1="17" x2="12" y2="21"/></svg></button>
<button class="icon-btn" id="photoBtn" onclick="takeServerPhoto()" title="Photo (Mac webcam)"><svg class="ico" viewBox="0 0 24 24"><path d="M23 19a2 2 0 01-2 2H3a2 2 0 01-2-2V8a2 2 0 012-2h4l2-3h6l2 3h4a2 2 0 012 2z"/><circle cx="12" cy="13" r="4"/></svg></button>
<button class="icon-btn" id="camBtn" onclick="toggleWebcamPip()" title="Live video (Mac webcam)"><svg class="ico" viewBox="0 0 24 24"><polygon points="23 7 16 12 23 17 23 7"/><rect x="1" y="5" width="15" height="14" rx="2"/></svg></button>
<a href="/tasks#reports" class="icon-btn notif-bell" id="notifBellBtn" title="Task reports"><svg class="ico" viewBox="0 0 24 24"><path d="M18 8A6 6 0 006 8c0 7-3 9-3 9h18s-3-2-3-9"/><path d="M13.73 21a2 2 0 01-3.46 0"/></svg><span class="notif-badge hidden" id="notifBadge">0</span></a>
<button class="icon-btn" id="themeBtn" onclick="toggleTheme()" title="Toggle theme"><svg class="ico" viewBox="0 0 24 24" id="themeIco"><circle cx="12" cy="12" r="5"/><line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/><line x1="1" y1="12" x2="3" y2="12"/><line x1="21" y1="12" x2="23" y2="12"/><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/></svg></button>
<button class="icon-btn" onclick="window.location.href='/#settings'" title="Settings"><svg class="ico" viewBox="0 0 24 24"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 00.33 1.82l.06.06a2 2 0 010 2.83 2 2 0 01-2.83 0l-.06-.06a1.65 1.65 0 00-1.82-.33 1.65 1.65 0 00-1 1.51V21a2 2 0 01-4 0v-.09A1.65 1.65 0 009 19.4a1.65 1.65 0 00-1.82.33l-.06.06a2 2 0 01-2.83-2.83l.06-.06A1.65 1.65 0 004.68 15a1.65 1.65 0 00-1.51-1H3a2 2 0 010-4h.09A1.65 1.65 0 004.6 9a1.65 1.65 0 00-.33-1.82l-.06-.06a2 2 0 012.83-2.83l.06.06A1.65 1.65 0 009 4.68a1.65 1.65 0 001-1.51V3a2 2 0 014 0v.09a1.65 1.65 0 001 1.51 1.65 1.65 0 001.82-.33l.06-.06a2 2 0 012.83 2.83l-.06.06A1.65 1.65 0 0019.4 9a1.65 1.65 0 001.51 1H21a2 2 0 010 4h-.09a1.65 1.65 0 00-1.51 1z"/></svg></button>
<button class="icon-btn" onclick="lockSession()" title="Lock session"><svg class="ico" viewBox="0 0 24 24"><rect x="3" y="11" width="18" height="11" rx="2"/><path d="M7 11V7a5 5 0 0110 0v4"/></svg></button>
</div>
</header>
<div class="call-container">
<!-- Avatar (tap-and-hold for push-to-talk) -->
<div class="avatar-wrap" id="avatarWrap">
<div class="ring-outer"></div>
<div class="ring-inner"></div>
<div class="ring-energy" id="ringEnergy"></div>
<div class="hold-indicator" id="holdIndicator"></div>
<div class="avatar-core"><img src="https://i.imgur.com/jD1X5W8.png" alt="CODEC"></div>
<div class="waveform">
<div class="bar"></div><div class="bar"></div><div class="bar"></div>
<div class="bar"></div><div class="bar"></div>
</div>
</div>
<div class="timer" id="timer"></div>
<div class="status" id="statusLabel">Tap to start voice call</div>
<div class="interrupt-hint" id="interruptHint"></div>
<!-- Action row: your turn + nudge -->
<div class="action-row" id="actionRow">
<button class="action-btn your-turn" id="yourTurnBtn" onclick="sendYourTurn()">
<svg viewBox="0 0 24 24"><path d="M5 12h14"/><path d="M12 5l7 7-7 7"/></svg>
Your Turn
</button>
<button class="action-btn nudge" id="nudgeBtn" onclick="sendNudge()">
<svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg>
Still there?
</button>
</div>
<button class="call-btn start" id="callBtn" onclick="toggleCall()"><svg width="34" height="34" viewBox="0 0 24 24" fill="white"><path d="M6.6 10.8c1.4 2.8 3.8 5.1 6.6 6.6l2.2-2.2c.3-.3.7-.4 1-.2 1.1.4 2.3.6 3.6.6.6 0 1 .4 1 1V20c0 .6-.4 1-1 1-9.4 0-17-7.6-17-17 0-.6.4-1 1-1h3.5c.6 0 1 .4 1 1 0 1.3.2 2.5.6 3.6.1.3 0 .7-.2 1L6.6 10.8z"/></svg></button>
<!-- Transcript -->
<div class="transcript-wrap">
<div class="transcript-header">
<span>TRANSCRIPT</span>
<div class="tx-dot" id="txDot"></div>
</div>
<div class="transcript" id="transcript">
<div class="tx-line system"><span class="tx-label">SYS</span>CODEC Voice — Ready</div>
</div>
</div>
</div>
<script>
// CSRF: auto-inject token header on state-changing requests
(function(){var _f=window.fetch;window.fetch=function(u,o){o=o||{};if(o.method&&o.method!=='GET'){var c=document.cookie.match(/codec_csrf=([^;]+)/);if(c){o.headers=o.headers||{};if(o.headers instanceof Headers){o.headers.set('x-csrf-token',c[1])}else{o.headers['x-csrf-token']=c[1]}}}return _f.call(this,u,o)}})();
// E2E encryption layer — AES-256-GCM via ECDH key exchange
var _e2eKey=null;
(function(){var _f2=window.fetch;function _b64(buf){return btoa(String.fromCharCode.apply(null,new Uint8Array(buf)))}function _unb64(s){var b=atob(s),a=new Uint8Array(b.length);for(var i=0;i<b.length;i++)a[i]=b.charCodeAt(i);return a}
window._e2eNegotiate=function(){return crypto.subtle.generateKey({name:'ECDH',namedCurve:'P-256'},true,['deriveBits']).then(function(kp){return crypto.subtle.exportKey('raw',kp.publicKey).then(function(pub){return _f2('/api/auth/keyexchange',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({pub:_b64(pub)})}).then(function(r){return r.json()}).then(function(d){var srvPub=_unb64(d.pub);return crypto.subtle.importKey('raw',srvPub,{name:'ECDH',namedCurve:'P-256'},false,[]).then(function(srvKey){return crypto.subtle.deriveBits({name:'ECDH',public:srvKey},kp.privateKey,256)}).then(function(bits){return crypto.subtle.importKey('raw',bits,{name:'HKDF'},false,['deriveKey'])}).then(function(hkdfKey){return crypto.subtle.deriveKey({name:'HKDF',hash:'SHA-256',salt:new Uint8Array(0),info:new TextEncoder().encode('codec-e2e')},hkdfKey,{name:'AES-GCM',length:256},false,['encrypt','decrypt'])}).then(function(k){_e2eKey=k;sessionStorage.setItem('_e2eReady','1')})})})}).catch(function(e){console.warn('E2E negotiation failed:',e)})};
window.fetch=function(u,o){o=o||{};if(!_e2eKey)return _f2.call(this,u,o);var method=(o.method||'GET').toUpperCase();if(method!=='GET'&&o.body){var iv=crypto.getRandomValues(new Uint8Array(12));return crypto.subtle.encrypt({name:'AES-GCM',iv:iv},_e2eKey,new TextEncoder().encode(o.body)).then(function(ct){o.body=JSON.stringify({iv:_b64(iv),ct:_b64(ct)});o.headers=o.headers||{};if(o.headers instanceof Headers){o.headers.set('x-e2e','1');o.headers.set('Content-Type','application/json')}else{o.headers['x-e2e']='1';o.headers['Content-Type']='application/json'}return _f2.call(this,u,o)}.bind(this)).then(_decResp)}return _f2.call(this,u,o).then(_decResp)};
function _decResp(r){if(!_e2eKey||r.headers.get('x-e2e')!=='1')return r;return r.clone().json().then(function(d){if(!d.iv||!d.ct)return r;var iv=_unb64(d.iv),ct=_unb64(d.ct);return crypto.subtle.decrypt({name:'AES-GCM',iv:iv},_e2eKey,ct).then(function(pt){var txt=new TextDecoder().decode(pt);return new Response(txt,{status:r.status,headers:r.headers})})}).catch(function(){return r})}
if(sessionStorage.getItem('_e2eReady'))window._e2eNegotiate();
})();
/* ── Theme support ── */
function toggleTheme(){var t=document.documentElement.getAttribute('data-theme')==='light'?'dark':'light';document.documentElement.setAttribute('data-theme',t);localStorage.setItem('codec-theme',t);updateThemeIcon(t)}
function updateThemeIcon(t){var ico=document.getElementById('themeIco');if(t==='light'){ico.innerHTML='<path d="M21 12.79A9 9 0 1111.21 3 7 7 0 0021 12.79z"/>'}else{ico.innerHTML='<circle cx="12" cy="12" r="5"/><line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/><line x1="1" y1="12" x2="3" y2="12"/><line x1="21" y1="12" x2="23" y2="12"/><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/>'}}
function lockSession(){fetch('/api/auth/logout',{method:'POST'}).then(function(){document.cookie='codec_session=;path=/;max-age=0;SameSite=Strict'+(location.protocol==='https:'?';Secure':'');window.location.href='/auth'})}
var _voiceOn=false;
function toggleVoiceReply(){_voiceOn=!_voiceOn;updateVoiceIcon()}
function updateVoiceIcon(){var b=document.getElementById('voiceBtn');if(!b)return;var m1=document.getElementById('muteX1'),m2=document.getElementById('muteX2');if(m1)m1.style.display=_voiceOn?'none':'';if(m2)m2.style.display=_voiceOn?'none':'';b.style.borderColor=_voiceOn?'var(--accent)':''}
function takeScreenshot(){fetch('/api/screenshot',{method:'POST'}).then(function(r){return r.json()}).then(function(d){if(d.path)alert('Screenshot saved: '+d.path)}).catch(function(){})}
// ── Server Photo (Mac webcam) ──
function takeServerPhoto() {
var btn = document.getElementById('photoBtn');
btn.style.borderColor = 'var(--accent)';
addTranscript('system', 'Capturing from Mac webcam...');
fetch('/api/webcam/snapshot').then(function(r) { return r.json(); }).then(function(d) {
btn.style.borderColor = '';
if (d.error) { addTranscript('system', 'Error: ' + d.error); return; }
addTranscript('system', 'Photo saved: ' + d.filename);
fetch('/api/webcam', { method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ image: d.image, analyze: true, prompt: 'Describe what you see in this photo. Be concise.' })
}).then(function(r2) { return r2.json(); }).then(function(d2) {
if (d2.analysis) addTranscript('assistant', d2.analysis);
});
}).catch(function(e) { btn.style.borderColor = ''; addTranscript('system', 'Camera error: ' + e.message); });
}
// ── Live Webcam PIP (Mac MJPEG stream) ──
var _pipDrag = { active: false, x: 0, y: 0 };
function toggleWebcamPip() {
var pip = document.getElementById('webcamPip');
if (pip.style.display === 'block') { closeWebcamPip(); return; }
var img = document.getElementById('pipVideo');
img.src = '/api/webcam/stream?' + Date.now();
pip.style.display = 'block';
document.getElementById('camBtn').style.borderColor = 'var(--accent)';
}
function closeWebcamPip() {
var img = document.getElementById('pipVideo');
img.src = '';
document.getElementById('webcamPip').style.display = 'none';
document.getElementById('webcamPip').classList.remove('expanded');
var btn = document.getElementById('camBtn'); if (btn) btn.style.borderColor = '';
}
function expandPip() {
document.getElementById('webcamPip').classList.toggle('expanded');
}
function snapFromPip() {
addTranscript('system', 'Snapshot from Mac webcam...');
fetch('/api/webcam/snapshot').then(function(r) { return r.json(); }).then(function(d) {
if (d.error) { addTranscript('system', 'Error: ' + d.error); return; }
addTranscript('system', 'Photo saved: ' + d.filename);
fetch('/api/webcam', { method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ image: d.image, analyze: true, prompt: 'Describe what you see in this photo. Be concise.' })
}).then(function(r2) { return r2.json(); }).then(function(d2) {
if (d2.analysis) addTranscript('assistant', d2.analysis);
});
}).catch(function(e) { addTranscript('system', 'Snap error: ' + e.message); });
}
function savePipFrame() {
fetch('/api/webcam/snapshot').then(function(r) { return r.json(); }).then(function(d) {
if (d.filename) addTranscript('system', 'Saved: ' + d.filename);
else addTranscript('system', 'Error saving');
}).catch(function(e) { addTranscript('system', 'Save error: ' + e.message); });
}
(function() {
var pip = document.getElementById('webcamPip'); if (!pip) return;
pip.addEventListener('mousedown', function(e) {
if (e.target.closest('.pip-btn')) return;
_pipDrag = { active: true, x: e.clientX - pip.offsetLeft, y: e.clientY - pip.offsetTop };
});
document.addEventListener('mousemove', function(e) {
if (!_pipDrag.active) return;
pip.style.left = (e.clientX - _pipDrag.x) + 'px';
pip.style.top = (e.clientY - _pipDrag.y) + 'px';
pip.style.right = 'auto'; pip.style.bottom = 'auto';
});
document.addEventListener('mouseup', function() { _pipDrag.active = false; });
})();
function pollStatus(){fetch('/api/health').then(function(r){return r.json()}).then(function(d){var dot=document.getElementById('statusDot');if(dot){dot.classList.toggle('on',!!d.ok)}}).catch(function(){var dot=document.getElementById('statusDot');if(dot)dot.classList.remove('on')})}
pollStatus();setInterval(pollStatus,15000);
(function(){var s=localStorage.getItem('codec-theme');if(s==='light'){document.documentElement.setAttribute('data-theme','light');updateThemeIcon('light')}})();
/* ── State ── */
var ws = null;
var audioCtx = null;
var mediaStream = null;
var processor = null;
var isInCall = false;
var timerIv = null;
var callStart = 0;
/* ── Audio playback queue ── */
var audioQueue = [];
var isPlaying = false;
var curSource = null;
/* ── Interrupt detection ── */
var INTERRUPT_RMS = 800; // mic RMS threshold to trigger interrupt
var lastInterruptAt = 0; // debounce — ms timestamp
/* ── Streaming transcript ── */
var streamLine = null;
var streamText = "";
/* ── Processing timer ── */
var processingStart = 0;
var processingTmr = null;
/* ── UI helpers ── */
function setState(s) {
var body = document.getElementById('body');
body.className = 'state-' + s;
var el = document.getElementById('statusLabel');
// Clear processing timer on state change
if (processingTmr && s !== 'processing') {
clearInterval(processingTmr); processingTmr = null;
}
if (s === 'idle') el.textContent = '';
else if (s === 'listening') el.textContent = 'Listening — tap "Your Turn" when done';
else if (s === 'speaking') el.textContent = 'Speaking…';
else if (s === 'processing') {
processingStart = Date.now();
el.textContent = 'Transcribing…';
processingTmr = setInterval(function() {
var sec = Math.floor((Date.now() - processingStart) / 1000);
if (sec < 3) el.textContent = 'Transcribing…';
else if (sec < 8) el.textContent = 'Thinking… ' + sec + 's';
else el.textContent = 'Still working… ' + sec + 's';
}, 500);
}
}
function addTranscript(role, text) {
var el = document.getElementById('transcript');
var label = role === 'user' ? 'M' : role === 'assistant' ? 'Q' : 'SYS';
/* Assistant final: replace streaming line instead of adding a duplicate */
if (role === 'assistant' && streamLine) {
var cur = streamLine.querySelector('.cursor');
if (cur) cur.remove();
streamLine.innerHTML = '<span class="tx-label">' + label + '</span>' + escHtml(text);
streamLine = null; streamText = '';
el.scrollTop = el.scrollHeight;
return;
}
if (streamLine) { streamLine.querySelector('.cursor').remove(); streamLine = null; streamText = ''; }
var div = document.createElement('div');
div.className = 'tx-line ' + role;
div.innerHTML = '<span class="tx-label">' + label + '</span>' + escHtml(text);
el.appendChild(div);
el.scrollTop = el.scrollHeight;
}
function appendStreamChunk(chunk) {
var el = document.getElementById('transcript');
if (!streamLine) {
streamLine = document.createElement('div');
streamLine.className = 'tx-line assistant';
streamLine.innerHTML = '<span class="tx-label">Q</span>';
el.appendChild(streamLine);
}
/* Remove cursor, append text, re-add cursor */
var cur = streamLine.querySelector('.cursor');
if (cur) cur.remove();
streamText += escHtml(chunk);
streamLine.innerHTML = '<span class="tx-label">Q</span>' + streamText + '<span class="cursor"></span>';
el.scrollTop = el.scrollHeight;
}
function escHtml(s) {
return String(s)
.replace(/&/g,'&').replace(/</g,'<')
.replace(/>/g,'>').replace(/"/g,'"');
}
/* ── Audio playback ── */
async function playNext() {
if (!audioQueue.length) {
isPlaying = false;
if (isInCall) setState('listening');
return;
}
isPlaying = true;
setState('speaking');
var data = audioQueue.shift();
try {
/* slice to detach, then decode */
var buf = await audioCtx.decodeAudioData(data.slice(0));
var src = audioCtx.createBufferSource();
src.buffer = buf;
src.connect(audioCtx.destination);
src.onended = function() { curSource = null; playNext(); };
src.start();
curSource = src;
} catch(e) {
console.warn('[Voice] Decode error:', e);
playNext();
}
}
function queueAudio(data) {
audioQueue.push(data);
if (!isPlaying) playNext();
}
function stopAudio() {
audioQueue = [];
isPlaying = false;
if (curSource) { try { curSource.stop(); } catch(e){} curSource = null; }
}
/* ── WebSocket ── */
function connectWS() {
var proto = location.protocol === 'https:' ? 'wss:' : 'ws:';
ws = new WebSocket(proto + '//' + location.host + '/ws/voice');
ws.binaryType = 'arraybuffer';
ws.onopen = function() {
setState('listening');
startMic();
};
ws.onmessage = function(e) {
if (e.data instanceof ArrayBuffer) {
queueAudio(e.data);
} else {
try {
var msg = JSON.parse(e.data);
if (msg.type === 'transcript') {
addTranscript(msg.role, msg.text);
} else if (msg.type === 'transcript_chunk') {
appendStreamChunk(msg.text);
} else if (msg.type === 'hint') {
var hint = document.getElementById('interruptHint');
if (hint) hint.textContent = msg.text || '';
} else if (msg.type === 'status') {
if (msg.status === 'processing') setState('processing');
else if (msg.status === 'listening') {
if (!isPlaying) setState('listening');
var hint = document.getElementById('interruptHint');
if (hint) hint.textContent = '';
}
}
} catch(err) {}
}
};
ws.onclose = function() {
if (isInCall) endCall();
addTranscript('system', 'Disconnected — transcript saved to memory');
};
ws.onerror = function(e) {
console.error('[Voice] WS error:', e);
addTranscript('system', 'Connection error');
};
}
/* ── Microphone ── */
async function startMic() {
try {
audioCtx = new (window.AudioContext || window.webkitAudioContext)({ sampleRate: 16000 });
mediaStream = await navigator.mediaDevices.getUserMedia({
audio: {
sampleRate: 16000, channelCount: 1,
echoCancellation: true, noiseSuppression: true,
autoGainControl: true
}
});
var source = audioCtx.createMediaStreamSource(mediaStream);
/* 4096-sample chunks ~= 256 ms at 16 kHz */
processor = audioCtx.createScriptProcessor(4096, 1, 1);
processor.onaudioprocess = function(e) {
if (!ws || ws.readyState !== WebSocket.OPEN) return;
var f32 = e.inputBuffer.getChannelData(0);
/* ── Always compute RMS for energy ring + interrupt ── */
var sum = 0;
for (var j = 0; j < f32.length; j++) sum += f32[j] * f32[j];
var rms = Math.sqrt(sum / f32.length) * 32768;
/* ── Energy ring: scales ring border + glow with mic input ── */
var re = document.getElementById('ringEnergy');
if (re) {
var bodyClass = document.getElementById('body').className;
if (bodyClass.indexOf('state-listening') >= 0) {
var lvl = Math.min(rms / 2800, 1.0);
var sc = (1 + lvl * 0.13).toFixed(3);
var glow = Math.round(lvl * 22);
var op = (0.25 + lvl * 0.6).toFixed(2);
re.style.transform = 'scale(' + sc + ')';
re.style.boxShadow = '0 0 ' + glow + 'px rgba(0,230,118,' + op + ')';
re.style.borderColor = 'rgba(0,230,118,' + op + ')';
} else {
re.style.transform = '';
re.style.boxShadow = '';
re.style.borderColor = '';
}
}
/* ── Interrupt detection: if Q is speaking and user talks ── */
if (isPlaying) {
var now = Date.now();
if (rms > INTERRUPT_RMS && (now - lastInterruptAt) > 1200) {
lastInterruptAt = now;
ws.send(JSON.stringify({ type: 'interrupt' }));
stopAudio();
setState('listening');
console.log('[Voice] Interrupt sent — rms=' + Math.round(rms));
}
}
var i16 = new Int16Array(f32.length);
for (var i = 0; i < f32.length; i++) {
var s = Math.max(-1, Math.min(1, f32[i]));
i16[i] = s < 0 ? s * 0x8000 : s * 0x7FFF;
}
ws.send(i16.buffer);
};
source.connect(processor);
processor.connect(audioCtx.destination);
} catch(e) {
addTranscript('system', 'Microphone error: ' + e.message);
}
}
function stopMic() {
if (processor) { processor.disconnect(); processor = null; }
if (mediaStream) { mediaStream.getTracks().forEach(function(t){ t.stop(); }); mediaStream = null; }
if (audioCtx) { audioCtx.close(); audioCtx = null; }
}
/* ── Call control ── */
function toggleCall() {
if (isInCall) endCall(); else startCall();
}
function startCall() {
isInCall = true;
callStart = Date.now();
var btn = document.getElementById('callBtn');
btn.className = 'call-btn end';
btn.innerHTML = '<svg width="28" height="28" viewBox="0 0 24 24" fill="white"><path d="M6.6 10.8c1.4 2.8 3.8 5.1 6.6 6.6l2.2-2.2c.3-.3.7-.4 1-.2 1.1.4 2.3.6 3.6.6.6 0 1 .4 1 1V20c0 .6-.4 1-1 1-9.4 0-17-7.6-17-17 0-.6.4-1 1-1h3.5c.6 0 1 .4 1 1 0 1.3.2 2.5.6 3.6.1.3 0 .7-.2 1L6.6 10.8z" transform="rotate(135 12 12)"/></svg>';
timerIv = setInterval(updateTimer, 1000);
document.getElementById('timer').textContent = '00:00';
document.getElementById('transcript').innerHTML = '<div class="tx-line system"><span class="tx-label">SYS</span>Connecting…</div>';
setState('processing');
connectWS();
}
function endCall() {
isInCall = false;
var btn = document.getElementById('callBtn');
btn.className = 'call-btn start';
btn.innerHTML = '<svg width="28" height="28" viewBox="0 0 24 24" fill="white"><path d="M6.6 10.8c1.4 2.8 3.8 5.1 6.6 6.6l2.2-2.2c.3-.3.7-.4 1-.2 1.1.4 2.3.6 3.6.6.6 0 1 .4 1 1V20c0 .6-.4 1-1 1-9.4 0-17-7.6-17-17 0-.6.4-1 1-1h3.5c.6 0 1 .4 1 1 0 1.3.2 2.5.6 3.6.1.3 0 .7-.2 1L6.6 10.8z"/></svg>';
if (timerIv) { clearInterval(timerIv); timerIv = null; }
stopAudio();
stopMic();
if (ws) { try { ws.close(); } catch(e){} ws = null; }
setState('idle');
document.getElementById('statusLabel').textContent = 'Call ended — transcript saved to memory';
}
function updateTimer() {
var s = Math.floor((Date.now() - callStart) / 1000);
document.getElementById('timer').textContent =
String(Math.floor(s / 60)).padStart(2,'0') + ':' + String(s % 60).padStart(2,'0');
}
/* ── "Your Turn" — force-send current audio buffer as utterance ── */
function sendYourTurn() {
if (!ws || ws.readyState !== WebSocket.OPEN || !isInCall) return;
ws.send(JSON.stringify({ type: 'your_turn' }));
setState('processing');
document.getElementById('statusLabel').textContent = 'Got it — processing…';
// Brief haptic feedback on mobile
if (navigator.vibrate) navigator.vibrate(30);
}
/* ── Nudge — poke the AI when processing seems stuck ── */
function sendNudge() {
if (!ws || ws.readyState !== WebSocket.OPEN) return;
ws.send(JSON.stringify({ type: 'nudge' }));
document.getElementById('statusLabel').textContent = 'Nudged — hang on…';
if (navigator.vibrate) navigator.vibrate([20, 40, 20]);
}
/* ── Hold-to-talk on avatar ── */
(function() {
var avatar = document.getElementById('avatarWrap');
var holdEl = document.getElementById('holdIndicator');
var holdTimer = null;
var isHolding = false;
function startHold(e) {
if (!isInCall) return;
e.preventDefault();
holdTimer = setTimeout(function() {
isHolding = true;
holdEl.classList.add('active');
// Unmute / signal "user speaking" to server
if (ws && ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify({ type: 'hold_start' }));
}
if (navigator.vibrate) navigator.vibrate(15);
}, 200); // 200ms threshold to distinguish tap from hold
}
function endHold(e) {
if (holdTimer) { clearTimeout(holdTimer); holdTimer = null; }
if (!isHolding) return;
isHolding = false;
holdEl.classList.remove('active');
// Signal "done talking" — force send
if (ws && ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify({ type: 'your_turn' }));
}
setState('processing');
}
avatar.addEventListener('touchstart', startHold, { passive: false });
avatar.addEventListener('touchend', endHold);
avatar.addEventListener('touchcancel', endHold);
avatar.addEventListener('mousedown', startHold);
avatar.addEventListener('mouseup', endHold);
avatar.addEventListener('mouseleave', endHold);
})();
/* ── Auto-connect via ?auto=1 ── */
if (new URLSearchParams(location.search).get('auto') === '1') {
window.addEventListener('load', function() { setTimeout(startCall, 400); });
}
(function(){function pollNotifCount(){fetch('/api/notifications/count').then(function(r){return r.json()}).then(function(d){var c=d.unread||d.count||0;var b=document.getElementById('notifBadge');if(b){b.textContent=c;b.classList.toggle('hidden',c===0)}}).catch(function(){})}pollNotifCount();setInterval(pollNotifCount,30000)})();
</script>
<div class="webcam-pip" id="webcamPip">
<img id="pipVideo" alt="Mac Webcam" onclick="expandPip()" style="cursor:pointer" />
<div class="pip-bar">
<button class="pip-btn snap-btn" onclick="snapFromPip()" title="Snapshot + Analyze"><svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><circle cx="12" cy="12" r="4"/></svg></button>
<button class="pip-btn" onclick="savePipFrame()" title="Save photo"><svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2"><path d="M19 21H5a2 2 0 01-2-2V5a2 2 0 012-2h11l5 5v11a2 2 0 01-2 2z"/><polyline points="17 21 17 13 7 13 7 21"/></svg></button>
<button class="pip-btn" onclick="expandPip()" title="Expand / Shrink"><svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2"><polyline points="15 3 21 3 21 9"/><polyline points="9 21 3 21 3 15"/><line x1="21" y1="3" x2="14" y2="10"/><line x1="3" y1="21" x2="10" y2="14"/></svg></button>
<button class="pip-btn" onclick="closeWebcamPip()" title="Close"><svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg></button>
</div>
</div>
</body>
</html>