diff --git a/ai_animation/Dockerfile b/ai_animation/Dockerfile index 7d529ca..eb8c3a3 100644 --- a/ai_animation/Dockerfile +++ b/ai_animation/Dockerfile @@ -16,10 +16,16 @@ COPY . . # Accept build arguments for environment variables ARG VITE_ELEVENLABS_API_KEY ARG VITE_WEBHOOK_URL +ARG VITE_STREAMING_MODE +ARG VITE_DEBUG_MODE +ARG VITE_INSTANT_MODE # Set environment variables for the build ENV VITE_ELEVENLABS_API_KEY=$VITE_ELEVENLABS_API_KEY ENV VITE_WEBHOOK_URL=$VITE_WEBHOOK_URL +ENV VITE_STREAMING_MODE=$VITE_STREAMING_MODE +ENV VITE_DEBUG_MODE=$VITE_DEBUG_MODE +ENV VITE_INSTANT_MODE=$VITE_INSTANT_MODE # Build the production-ready files (dist/) RUN npm run build diff --git a/docker-compose.yaml b/docker-compose.yaml index 7cf9d07..beb4ddb 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -17,6 +17,9 @@ services: args: - VITE_ELEVENLABS_API_KEY=${VITE_ELEVENLABS_API_KEY} - VITE_WEBHOOK_URL=${VITE_WEBHOOK_URL} + - VITE_STREAMING_MODE=True + - VITE_DEBUG_MODE=False + - VITE_INSTANT_MODE=False env_file: "./ai_animation/.env" ports: - "4173:4173" diff --git a/twitch-streamer/Dockerfile b/twitch-streamer/Dockerfile index 1b9496d..0aeb13d 100644 --- a/twitch-streamer/Dockerfile +++ b/twitch-streamer/Dockerfile @@ -14,6 +14,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ pulseaudio \ fluxbox \ dbus dbus-x11 \ + xdotool \ && rm -rf /var/lib/apt/lists/* # Install Google Chrome @@ -38,10 +39,8 @@ ENV SCREEN_GEOMETRY=1920x1080x24 RUN mkdir /twitch-streamer/ COPY pulse-virtual-audio.sh /twitch-streamer/pulse-virtual-audio.sh COPY entrypoint.sh /twitch-streamer/entrypoint.sh -RUN chmod +x /twitch-streamer/pulse-virtual-audio.sh /twitch-streamer/entrypoint.sh +COPY chrome-launcher.sh /twitch-streamer/chrome-launcher.sh +RUN chmod +x /twitch-streamer/pulse-virtual-audio.sh /twitch-streamer/entrypoint.sh /twitch-streamer/chrome-launcher.sh WORKDIR /twitch-streamer/ -# Switch to non-root user -USER chrome - ENTRYPOINT ["/twitch-streamer/entrypoint.sh"] diff --git a/twitch-streamer/chrome-launcher.sh b/twitch-streamer/chrome-launcher.sh new file mode 100644 index 0000000..c412e18 --- /dev/null +++ b/twitch-streamer/chrome-launcher.sh @@ -0,0 +1,65 @@ +#!/bin/bash +# Chrome launcher with restart capability + +while true; do + echo "Starting Chrome browser..." + + # Set PulseAudio environment for Chrome + export PULSE_RUNTIME_PATH=/tmp/pulse + export PULSE_SERVER=unix:/tmp/pulse/native + + DISPLAY=$DISPLAY google-chrome \ + --remote-debugging-port=9222 \ + --no-sandbox \ + --disable-setuid-sandbox \ + --disable-dev-shm-usage \ + --no-first-run \ + --disable-background-timer-throttling \ + --disable-renderer-backgrounding \ + --disable-backgrounding-occluded-windows \ + --disable-features=TranslateUI \ + --disable-ipc-flooding-protection \ + --disable-frame-rate-limit \ + --enable-precise-memory-info \ + --max-gum-fps=30 \ + --user-data-dir=/home/chrome/chrome-data \ + --window-size=1600,900 --window-position=0,0 \ + --kiosk \ + --autoplay-policy=no-user-gesture-required \ + --disable-features=AudioServiceSandbox,RendererCodeIntegrity,IsolateOrigins \ + --disable-site-isolation-trials \ + --use-fake-ui-for-media-stream \ + --enable-usermedia-screen-capturing \ + --enable-gpu \ + --use-gl=swiftshader \ + --disable-gpu-vsync \ + --force-device-scale-factor=1 \ + --disable-web-security \ + --disable-features=VizDisplayCompositor \ + --enable-features=NetworkService \ + --disable-background-networking \ + --disable-background-mode \ + --disable-client-side-phishing-detection \ + --disable-component-update \ + --disable-default-apps \ + --disable-domain-reliability \ + --disable-features=AudioServiceOutOfProcess \ + --disable-hang-monitor \ + --disable-popup-blocking \ + --disable-prompt-on-repost \ + --disable-sync \ + --metrics-recording-only \ + --no-default-browser-check \ + --no-pings \ + --password-store=basic \ + --use-mock-keychain \ + --force-color-profile=srgb \ + --disable-features=Translate \ + --disable-features=BlinkGenPropertyTrees \ + --max_old_space_size=512 \ + --js-flags="--max-old-space-size=512" \ + "http://diplomacy:4173" + + echo "Chrome exited with code $?. Restarting in 5 seconds..." + sleep 5 +done \ No newline at end of file diff --git a/twitch-streamer/entrypoint.sh b/twitch-streamer/entrypoint.sh index 2fd2e6d..603fb27 100755 --- a/twitch-streamer/entrypoint.sh +++ b/twitch-streamer/entrypoint.sh @@ -10,8 +10,8 @@ fi # Start PulseAudio (virtual audio) in the background /twitch-streamer/pulse-virtual-audio.sh & -# Start Xvfb (the in-memory X server) in the background -Xvfb $DISPLAY -screen 0 1920x1080x24 & +# Start Xvfb (the in-memory X server) in the background with optimizations +Xvfb $DISPLAY -screen 0 1600x900x24 -ac -nolisten tcp & echo "Display is ${DISPLAY}" # Give Xvfb a moment to start @@ -19,46 +19,42 @@ sleep 2 mkdir -p /home/chrome -# Launch Chrome in the background, pointing at your site. -# --disable-background-timer-throttling & related flags to prevent fps throttling in headless/Xvfb -DISPLAY=$DISPLAY google-chrome \ - --remote-debugging-port=9222 \ - --no-sandbox \ - --disable-setuid-sandbox \ - --disable-dev-shm-usage \ - --no-first-run \ - --disable-background-timer-throttling \ - --disable-renderer-backgrounding \ - --disable-backgrounding-occluded-windows \ - --disable-features=TranslateUI \ - --disable-ipc-flooding-protection \ - --disable-frame-rate-limit \ - --enable-precise-memory-info \ - --max-gum-fps=30 \ - --user-data-dir=/home/chrome/chrome-data \ - --window-size=1920,1080 --window-position=0,0 \ - --kiosk \ - --autoplay-policy=no-user-gesture-required \ - --enable-gpu \ - --use-gl=swiftshader \ - --disable-gpu-vsync \ - --force-device-scale-factor=1 \ - "http://diplomacy:4173" & +# Launch Chrome with restart capability +/twitch-streamer/chrome-launcher.sh & -sleep 5 # let the page load or animations start +sleep 10 # let the page load or animations start + +# Simulate multiple clicks to enable audio and move mouse to corner +echo "Simulating clicks for audio autoplay..." +# Click on the play button area +xdotool mousemove 960 540 # Move to center +sleep 1 +xdotool click 1 # Left click +sleep 0.5 +# Click multiple times to ensure audio starts +xdotool click 1 # Second click +sleep 0.2 +xdotool click 1 # Third click +sleep 0.2 +# Try clicking on chat area in case it helps +xdotool mousemove 300 300 +xdotool click 1 +sleep 0.5 +xdotool mousemove 1599 899 # Move to bottom right corner # Set PulseAudio environment export PULSE_RUNTIME_PATH=/tmp/pulse export PULSE_SERVER=unix:/tmp/pulse/native +export PULSE_SINK=dummy_sink # Start streaming with FFmpeg. # - For video: x11grab at 30fps # - For audio: pulse from the dummy sink monitor exec ffmpeg -y \ - -f x11grab -video_size 1920x1080 -framerate 30 -thread_queue_size 1024 -i $DISPLAY \ + -f x11grab -video_size 1600x900 -framerate 15 -thread_queue_size 4096 -i $DISPLAY \ -f pulse -thread_queue_size 1024 -i dummy_sink.monitor \ - -c:v libx264 -preset fast -tune animation -b:v 4500k -maxrate 4500k -bufsize 9000k \ - -g 60 -keyint_min 60 \ + -c:v libx264 -preset ultrafast -tune zerolatency -b:v 1000k -maxrate 1500k -bufsize 300k -profile:v baseline -level 3.0 -crf 32 -threads 1 -x264-params "nal-hrd=cbr:force-cfr=1:keyint=30" \ + -g 40 -keyint_min 20 \ -pix_fmt yuv420p \ -c:a aac -b:a 128k \ -vsync cfr \