selkies-gstreamer-entrypoint.sh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/bash
  2. # This Source Code Form is subject to the terms of the Mozilla Public
  3. # License, v. 2.0. If a copy of the MPL was not distributed with this
  4. # file, You can obtain one at https://mozilla.org/MPL/2.0/.
  5. set -e
  6. # Set password for basic authentication
  7. if [ "$(echo ${SELKIES_ENABLE_BASIC_AUTH} | tr '[:upper:]' '[:lower:]')" = "true" ] && [ -z "${SELKIES_BASIC_AUTH_PASSWORD}" ]; then export SELKIES_BASIC_AUTH_PASSWORD="${PASSWD}"; fi
  8. # Set default display
  9. export DISPLAY="${DISPLAY:-:0}"
  10. # PipeWire-Pulse server socket path
  11. export PIPEWIRE_LATENCY="32/48000"
  12. export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/tmp}"
  13. export PIPEWIRE_RUNTIME_DIR="${PIPEWIRE_RUNTIME_DIR:-${XDG_RUNTIME_DIR:-/tmp}}"
  14. export PULSE_RUNTIME_PATH="${PULSE_RUNTIME_PATH:-${XDG_RUNTIME_DIR:-/tmp}/pulse}"
  15. export PULSE_SERVER="${PULSE_SERVER:-unix:${PULSE_RUNTIME_PATH:-${XDG_RUNTIME_DIR:-/tmp}/pulse}/native}"
  16. # Export environment variables required for Selkies-GStreamer
  17. export GST_DEBUG="${GST_DEBUG:-*:2}"
  18. export GSTREAMER_PATH=/opt/gstreamer
  19. # Source environment for GStreamer
  20. . /opt/gstreamer/gst-env
  21. export SELKIES_ENCODER="${SELKIES_ENCODER:-x264enc}"
  22. export SELKIES_ENABLE_RESIZE="${SELKIES_ENABLE_RESIZE:-false}"
  23. if ( [ -z "${SELKIES_TURN_USERNAME}" ] || [ -z "${SELKIES_TURN_PASSWORD}" ] ) && [ -z "${SELKIES_TURN_SHARED_SECRET}" ] || [ -z "${SELKIES_TURN_HOST}" ] || [ -z "${SELKIES_TURN_PORT}" ]; then
  24. export TURN_RANDOM_PASSWORD="$(tr -dc 'A-Za-z0-9' < /dev/urandom 2>/dev/null | head -c 24)"
  25. export SELKIES_TURN_HOST="$(curl -fsSL checkip.amazonaws.com)"
  26. export SELKIES_TURN_PORT="3478"
  27. export SELKIES_TURN_USERNAME="selkies"
  28. export SELKIES_TURN_PASSWORD="${TURN_RANDOM_PASSWORD}"
  29. /etc/start-turnserver.sh &
  30. fi
  31. export SELKIES_TURN_PROTOCOL="${SELKIES_TURN_PROTOCOL:-tcp}"
  32. # Wait for X server to start
  33. echo 'Waiting for X Socket' && until [ -S "/tmp/.X11-unix/X${DISPLAY#*:}" ]; do sleep 0.5; done && echo 'X Server is ready'
  34. # Clear the cache registry
  35. rm -rf "${HOME}/.cache/gstreamer-1.0"
  36. # Start the Selkies-GStreamer WebRTC HTML5 remote desktop application
  37. selkies-gstreamer \
  38. --addr="0.0.0.0" \
  39. --port="8080" \
  40. $@