brief-evening-79958
12/01/2025, 11:43 AMtall-airline-16756
12/01/2025, 11:43 AMtall-airline-16756
12/01/2025, 11:44 AMbrief-evening-79958
12/01/2025, 11:48 AMtall-airline-16756
12/01/2025, 11:50 AMsetup-livekit.sh, make it executable, then run it.
Script (paste into the VM):
#!/bin/bash
set -euo pipefail
# Usage: edit YOUR_API_KEY and YOUR_API_SECRET below, then: sudo bash setup-livekit.sh
API_KEY="YOUR_API_KEY"
API_SECRET="YOUR_API_SECRET"
VM_IP=$(curl -s ifconfig.me || hostname -I | awk '{print $1}')
WORKDIR="/opt/livekit"
mkdir -p ${WORKDIR}
cd ${WORKDIR}
# 1) Update & deps
sudo apt update && sudo apt install -y docker.io docker-compose wget curl jq ca-certificates
sudo systemctl enable --now docker
sudo usermod -aG docker $USER || true
# 2) Start Redis (Docker)
docker run -d --name livekit-redis --restart always -p 6379:6379 redis:alpine
# 3) Write LiveKit server config
cat > ${WORKDIR}/livekit.yaml <<EOF
port: 7880
rtc:
tcp_port: 7881
udp_port: 7882
port_range_start: 50000
port_range_end: 60000
use_external_ip: true
external_ip: ${VM_IP}
redis:
address: ${VM_IP}:6379
keys:
${API_KEY}: ${API_SECRET}
logging:
level: info
EOF
# 4) Run LiveKit Server (Docker)
docker run -d --name livekit-server --network host --restart always \
-v ${WORKDIR}/livekit.yaml:/etc/livekit/livekit.yaml \
livekit/livekit-server --config /etc/livekit/livekit.yaml
# 5) Egress config & run (requires chrome/gstreamer later if you need complex composites)
cat > ${WORKDIR}/egress.yaml <<EOF
api_key: ${API_KEY}
api_secret: ${API_SECRET}
ws_url: ws://${VM_IP}:7880
redis:
address: ${VM_IP}:6379
enable_chrome_sandbox: false
prometheus_port: 7981
log_level: debug
EOF
docker run -d --name livekit-egress --cap-add SYS_ADMIN --network host --restart always \
-v ${WORKDIR}/egress.yaml:/etc/egress/config.yaml \
livekit/egress --config /etc/egress/config.yaml
# 6) Ingress config & run (RTMP/WHIP)
cat > ${WORKDIR}/ingress.yaml <<EOF
api_key: ${API_KEY}
api_secret: ${API_SECRET}
ws_url: ws://${VM_IP}:7880
redis:
address: ${VM_IP}:6379
rtmp_port: 1935
whip_port: 8080
http_relay_port: 9090
rtc_config:
tcp_port: 7885
udp_port: 7885
use_external_ip: true
external_ip: ${VM_IP}
health_port: 7982
log_level: debug
EOF
docker run -d --name livekit-ingress --network host --restart always \
-v ${WORKDIR}/ingress.yaml:/etc/ingress/config.yaml \
livekit/ingress --config /etc/ingress/config.yaml
# 7) SIP config & run
cat > ${WORKDIR}/sip.yaml <<EOF
api_key: ${API_KEY}
api_secret: ${API_SECRET}
ws_url: ws://${VM_IP}:7880
redis:
address: ${VM_IP}:6379
sip_port: 5060
rtp_port: 10000-20000
use_external_ip: true
external_ip: ${VM_IP}
logging:
level: debug
EOF
docker run -d --name livekit-sip --network host --restart always \
-v ${WORKDIR}/sip.yaml:/etc/sip/config.yaml \
livekit/sip --config /etc/sip/config.yaml
# 8) Basic firewall suggestions (optional; may require cloud provider security group)
echo "Open these ports on your VM/network: TCP 22,7880,7881,1935,8080,9090,5060; UDP 3478,50000-60000,10000-20000"
echo "Setup complete. VM IP: ${VM_IP}"
After running the script, use these commands to verify services and perform basic tests.
Service checks
1. Check container status:
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Image}}"
1. Check logs (replace <name>):
docker logs -f livekit-server
docker logs -f livekit-egress
docker logs -f livekit-ingress
docker logs -f livekit-sip
Quick tests
1. Generate a token (install livekit-cli or use the helper below). For a quick token with the `livekit-cli`:
# install CLI (one-line)
curl -sSL https://get.livekit.io | bash
export LIVEKIT_URL="http://${VM_IP}:7880"
export LIVEKIT_API_KEY="${API_KEY}"
export LIVEKIT_API_SECRET="${API_SECRET}"
# create token for room "test-room", identity "tester"
lk token create --room test-room --identity tester
Use the returned token in your client (SDK or Web) with ws://<VM_IP>:7880.
1. Test RTMP ingress (OBS)
• Create an ingress via CLI:
cat > /tmp/ingress-create.json <<EOF
{
"input_type": 0,
"name": "test-ingress",
"room_name": "test-room",
"participant_identity": "ingress-bot",
"participant_name": "Ingress Bot"
}
EOF
lk ingress create /tmp/ingress-create.json --url ${LIVEKIT_URL}
• Use OBS to stream to: rtmp//<VM IP>1935 and the returned stream key.
1. Test Egress (room composite)
# start recording the room (room must exist and have participants)
lk egress start --type room-composite --room test-room --layout speaker --url ${LIVEKIT_URL}
Check egress logs for saving/upload events.
1. Test SIP (basic)
• Verify SIP process listening:
ss -u -lntp | grep :5060 || ss -tulnp | grep 5060
• Use a SIP client (Linphone) pointing to <VM_IP>:5060 to place a call into the configured SIP server or use lk sip helper if available.
Important notes and next steps
• This setup uses IP-only, no TLS. Do not expose sensitive workloads publicly without TLS or additional network protections.
• Egress advanced features (composites requiring Chrome/GStreamer) may need host packages (Chrome, GStreamer). If you need them, I can provide the exact apt install commands and update the egress container run options.
• If you want I can: (a) provide the expanded init script that installs Chrome/GStreamer and systemd unit wrappers, or (b) walk you step-by-step to run each section manually and verify. Which would you prefer? Sources: Self-hosting the Ingress Service | LiveKit docs | Self-hosting the Egress Service | LiveKit docs | Self-hosted SIP server | LiveKit docs | Deploy to a VM | LiveKit docs | Ports and firewall | LiveKit docsbrief-evening-79958
12/01/2025, 11:53 AMtall-airline-16756
12/01/2025, 11:53 AM<vm_ip> or ${VM_IP}.
Why:
• Services (LiveKit Server, Ingress, SIP, Egress) need the VM IP for RTC ICE, SIP RTP, Redis connections, and RTMP/WHIP endpoints so peers and other services can reach them.
• With no domain, the public IP is the anchor for ws://, rtmp://, and SIP URIs.
Where to put it (examples from the script/configs):
• livekit.yaml — set external_ip: <VM_IP> and redis.address: <VM_IP>:6379
• egress.yaml — ws_url: ws://<VM_IP>:7880, redis.address: <VM_IP>:6379
• ingress.yaml — ws_url: ws://<VM_IP>:7880, rtc_config.external_ip: <VM_IP>
• sip.yaml — ws_url: ws://<VM_IP>:7880, redis.address: <VM_IP>:6379, external_ip: <VM_IP>
• Docker/env usage — set LIVEKIT_URL to http://<VM_IP>:7880 and API vars accordingly.
If you want, paste your VM IP here (or confirm you’ll replace placeholders) and I’ll update the exact script/config contents for you.brief-evening-79958
12/01/2025, 12:15 PMtall-airline-16756
12/01/2025, 12:16 PMbrief-evening-79958
12/01/2025, 12:20 PMtall-airline-16756
12/01/2025, 12:20 PMdocker logs livekit-sip showing an INVITE or error, or the output of:
• ss -u -lntp | grep 5060
• docker logs --tail 200 livekit-sip
Tell me which option and provide any of the info above and I’ll give step‑by‑step tests and commands.brief-evening-79958
12/01/2025, 12:21 PMtall-airline-16756
12/01/2025, 12:21 PMbrief-evening-79958
12/01/2025, 12:27 PMtall-airline-16756
12/01/2025, 12:29 PM{
"trunk": {
"name": "freeswitch-trunk",
"address": "FREESWITCH_IP",
"transport": "SIP_TRANSPORT_UDP",
"numbers": [
"*"
],
"allowed_addresses": [
"FREESWITCH_IP/32"
],
"media_encryption": "SIP_MEDIA_ENCRYPT_DISABLE"
}
}
• Apply (using your CLI/SDK): lk sip outbound create outbound-trunk.json
3) Configure FreeSWITCH gateway to LiveKit
• Create file: /usr/local/freeswitch/conf/sip_profiles/external/livekit.xml
<include>
<gateway name="livekit_trunk">
<param name="proxy" value="YOUR_VM_IP:5060"/>
<param name="register" value="false"/>
<param name="from-domain" value="YOUR_VM_IP"/>
<param name="retry-seconds" value="30"/>
<param name="expire-seconds" value="600"/>
<param name="register-transport" value="udp"/>
</gateway>
</include>
• Reload in FS: fs_cli -x "reloadxml"
4) Dialplan to match dynamic 4‑digit extensions and send to LiveKit number
• Example dialplan (place in dialplan/default/ or your context):
<include>
<context name="default">
<extension name="route_4digit_to_livekit">
<condition field="destination_number" expression="^\d{4}$"/>
<action application="set" data="effective_caller_id_number=${caller_id_number}"/>
<action application="set" data="sip_h_X-Extension=${destination_number}"/>
<action application="bridge" data="sofia/gateway/livekit_trunk/+15183171307"/>
</extension>
</context>
</include>
• Reload dialplan: fs_cli -x "reloadxml"
5) Ensure LiveKit SIP config binds to external IP
• On the LiveKit SIP config (sip.yaml) ensure:
◦ sip_port: 5060
◦ use_external_ip: true
◦ external_ip: YOUR_VM_IP
◦ redis/ws url point to your LiveKit server (ws://YOUR_VM_IP:7880)
6) Create a LiveKit dispatch rule to map inbound call → room → agent
• dispatch-rule.json:
{
"dispatch_rule": {
"name": "freeswitch-agent-rule",
"rule": {
"dispatchRuleDirect": {
"roomName": "agent-room"
}
},
"roomConfig": {
"agents": [
{
"agentName": "inbound-agent",
"metadata": "from=freeswitch"
}
]
}
}
}
• Apply: lk sip dispatch create dispatch-rule.json
• Ensure your AI agent process connects and registers with agentName "inbound-agent".
7) Test flow from FreeSWITCH
• From a FreeSWITCH extension (or MicroSIP registered to FreeSWITCH), dial a 4‑digit extension (e.g., 4000).
• FreeSWITCH should bridge to sofia/gateway/livekit_trunk/+15183171307 and send SIP INVITE to YOUR_VM_IP:5060.
8) Observe and debug on LiveKit side
• Tail SIP logs: docker logs -f livekit-sip (or journalctl if systemd)
• Monitor SIP traffic: sudo tcpdump -n -i any port 5060 or udp and host FREESWITCH_IP
• Confirm LiveKit creates the participant and dispatches the agent to room "agent-room".
9) Test MicroSIP (internal)
• Register MicroSIP to FreeSWITCH (best flow):
◦ SIP server: FREESWITCH_IP, port 5060, transport UDP
◦ Username/password: a FreeSWITCH extension (e.g., 1000/1234)
• From MicroSIP call the 4-digit extension (e.g., 4000). Call should flow FreeSWITCH → LiveKit → +15183171307 → dispatched agent.
• Alternatively, Quick Call in MicroSIP to: +15183171307@YOUR_VM_IP (if LiveKit allowed your client IP) — but registration via FreeSWITCH is preferred.
10) RTP / audio troubleshooting
• Confirm RTP ports open on both hosts (FreeSWITCH and LiveKit). For SIP media, check 10000–20000 on LiveKit and FreeSWITCH.
• If audio one-way: verify external_ip is set on LiveKit SIP config and on FreeSWITCH SIP profile if NAT involved.
• Use tcpdump to capture RTP: sudo tcpdump -n -i any udp portrange 10000-20000
11) Useful commands to share if you want me to interpret results
• On LiveKit host:
◦ ss -u -lntp | grep 5060
◦ docker logs --tail 200 livekit-sip
◦ tcpdump -n -i any port 5060 -c 100
• On FreeSWITCH host:
◦ fs_cli -x "sofia status"
◦ fs_cli -x "show channels"
◦ tcpdump capturing towards YOUR_VM_IP: sudo tcpdump -n host YOUR_VM_IP and port 5060 -c 100
If you want, paste:
• FREESWITCH_IP and YOUR_VM_IP (or confirm you’ll substitute)
• Output of ss -u -lntp | grep 5060 on both hosts
• A short docker logs --tail 200 livekit-sip capture after attempting a test call
I’ll interpret logs and give targeted next steps (NAT fixes, SDP codec issues, or dialplan adjustments). Which part should I help with now — applying configs, running a test, or reading logs?
Sources: SIP APIs | LiveKit docs | Agent dispatch | LiveKit docs | Ports and firewall | LiveKit docs | Inbound calls with Twilio Voice | LiveKit docs | Using Wavix to accept and make calls | LiveKit docs