File size: 6,123 Bytes
e7d37f3 | 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 | #!/bin/bash
#
# WebRTC Latency Test POC - Start Script
# Starts the WebRTC server for latency testing
#
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
RED='\033[0;31m'
NC='\033[0m'
success() { echo -e "${GREEN}β${NC} $1"; }
warn() { echo -e "${YELLOW}β ${NC} $1"; }
error() { echo -e "${RED}β${NC} $1"; }
header() { echo -e "\n${CYAN}$1${NC}"; }
# Default configuration
HOST="0.0.0.0"
PORT=9000
LOG_FILE="/tmp/webrtc-server.log"
PID_FILE="/tmp/webrtc-server.pid"
SERVER_SCRIPT="$PROJECT_DIR/webrtc-server-fixed.py"
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
-p|--port)
PORT="$2"
shift 2
;;
-h|--host)
HOST="$2"
shift 2
;;
--no-daemon)
NO_DAEMON=true
shift
;;
*)
echo "Unknown option: $1"
echo "Usage: $0 [--port PORT] [--host HOST] [--no-daemon]"
exit 1
;;
esac
done
echo ""
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo "β WEBRTC LATENCY TEST - START SERVER β"
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo ""
# ============================================================
# CHECK IF SERVER SCRIPT EXISTS
# ============================================================
if [ ! -f "$SERVER_SCRIPT" ]; then
error "Server script not found: $SERVER_SCRIPT"
echo " Please install the project first:"
echo " $SCRIPT_DIR/install_webrtc.sh"
exit 1
fi
# ============================================================
# CHECK IF ALREADY RUNNING
# ============================================================
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
if ps -p "$PID" > /dev/null 2>&1; then
header "Server already running"
echo " PID: $PID"
echo " Port: $PORT"
echo ""
echo " To stop: $SCRIPT_DIR/stop_webrtc.sh"
exit 0
else
# Stale PID file, remove it
rm -f "$PID_FILE"
fi
fi
# ============================================================
# STOP EXISTING PROCESSES
# ============================================================
header "Stopping existing WebRTC server processes..."
# Kill any existing webrtc-server processes
pkill -f "webrtc-server" 2>/dev/null || true
sleep 1
# Kill any process using the port
if lsof -Pi :$PORT -sTCP:LISTEN -t >/dev/null 2>&1; then
lsof -ti :$PORT | xargs kill -9 2>/dev/null || true
fi
success "Cleanup completed"
# ============================================================
# START SERVER
# ============================================================
header "Starting WebRTC server..."
cd "$PROJECT_DIR"
if [ "$NO_DAEMON" = "true" ]; then
# Run in foreground
echo " Starting in foreground mode..."
echo " Host: $HOST"
echo " Port: $PORT"
echo " Log: $LOG_FILE"
echo ""
python3 -u "$SERVER_SCRIPT" > "$LOG_FILE" 2>&1
else
# Run in background
echo " Host: $HOST"
echo " Port: $PORT"
echo " Log: $LOG_FILE"
echo ""
# Start in background with nohup
nohup python3 -u "$SERVER_SCRIPT" > "$LOG_FILE" 2>&1 &
SERVER_PID=$!
# Save PID
echo $SERVER_PID > "$PID_FILE"
# Wait a moment for startup
sleep 3
# Check if process is still running
if ps -p $SERVER_PID > /dev/null 2>&1; then
success "Server started successfully"
echo " PID: $SERVER_PID"
# Wait for port to be listening
for i in {1..10}; do
if lsof -Pi :$PORT -sTCP:LISTEN -t >/dev/null 2>&1; then
success "Server listening on port $PORT"
break
fi
sleep 1
done
else
error "Server failed to start"
echo " Check log: $LOG_FILE"
rm -f "$PID_FILE"
exit 1
fi
fi
# ============================================================
# DISPLAY STATUS
# ============================================================
header "SERVER STATUS"
echo ""
printf " %-15s %-10s %s\n" "Service" "Port" "Status"
echo " βββββββββββββββββββββββββββββββββ"
if lsof -Pi :$PORT -sTCP:LISTEN -t >/dev/null 2>&1; then
printf " %-15s %-10s ${GREEN}β Online${NC}\n" "WebRTC Server" "$PORT"
# Show last few log lines
if [ -f "$LOG_FILE" ]; then
echo ""
echo " Last log entries:"
tail -5 "$LOG_FILE" | sed 's/^/ /'
fi
else
printf " %-15s %-10s ${RED}β Offline${NC}\n" "WebRTC Server" "$PORT"
echo ""
error "Server is not responding"
exit 1
fi
# ============================================================
# ACCESS INFORMATION
# ============================================================
header "ACCESS INFORMATION"
echo ""
if [ "$HOST" = "0.0.0.0" ]; then
echo " Local access: http://localhost:$PORT"
echo " Network access: http://$(hostname -I | awk '{print $1}'):$PORT"
else
echo " Server URL: http://$HOST:$PORT"
fi
echo ""
echo " Web client: Open http://localhost:$PORT in browser"
echo " Logs: tail -f $LOG_FILE"
echo ""
# ============================================================
# QUICK TEST COMMANDS
# ============================================================
echo " Quick test commands:"
echo " β’ Manual test: Open http://localhost:$PORT in browser"
echo " β’ Auto test: python3 test_latency_playwright.py 1 true"
echo " β’ Load test: python3 test_latency_playwright.py 5 true"
echo ""
echo " To stop server: $SCRIPT_DIR/stop_webrtc.sh"
echo ""
success "WebRTC server started successfully!"
echo ""
|