diff --git a/.env b/.env index b1c9560..dc0f397 100644 --- a/.env +++ b/.env @@ -1,15 +1,13 @@ -# Only 'openvidu-local.dev', '*.openvidu-local.dev' or 'localhost' can be used. -# To access in a LAN environment using 'openvidu-local.dev', just add the IP as a -# subdomain. For example if your IP is 192.168.1.105, just use '192-168-1-105.openvidu-local.dev'. -# In this way, you can access from any device in your LAN. -LOCAL_DOMAIN=localhost -# If false, services will not run with TLS. + +# Expose OpenVidu with HTTPS. USE_TLS=false -# Announced IP for LAN access. If 'auto', best effort will be made to find -# the private IP of the machine. -# If the detected IP is not correct, you can set it manually. -PRIVATE_IP=auto +# If true, you can access OpenVidu through your LAN +# If true USE_TLS must be true +LAN_MODE=false + +# LAN IP Address to expose OpenVidu +LAN_PRIVATE_IP=auto # LiveKit API Key and Secret used for apps to connect to the LiveKit server. LIVEKIT_API_KEY=key1 diff --git a/README.md b/README.md index 8d4f872..5aef657 100644 --- a/README.md +++ b/README.md @@ -34,9 +34,9 @@ If you want to access the deployment in your LAN for Android or iOS devices, you 1. Get the private IP of your computer in your LAN. 2. Configure your Firewall to allow devices in your LAN to access your computer. -3. Change `LOCAL_DOMAIN` in the `.env` file to have the IP of your computer in your LAN. +3. Change `LAN_DOMAIN` in the `.env` file to have the IP of your computer in your LAN. - If your IP for example is `192.168.1.10`, `LOCAL_DOMAIN` should be `192-168-1-10.openvidu-local.dev`. + If your IP for example is `192.168.1.10`, `LAN_DOMAIN` should be `192-168-1-10.openvidu-local.dev`. ### About `openvidu-local.dev` diff --git a/caddy-proxy/main.go b/caddy-proxy/main.go index 694f68b..543e2e9 100644 --- a/caddy-proxy/main.go +++ b/caddy-proxy/main.go @@ -14,6 +14,7 @@ type TemplateData any var indexData = &templates.IndexData{} var caddyData = &templates.CaddyData{} +var app502Data = &templates.App502Data{} func main() { err := Initialize() @@ -21,6 +22,7 @@ func main() { fmt.Println(err) os.Exit(1) } + rawIndex, err := GenerateTemplate(templates.IndexTemplate, indexData) if err != nil { fmt.Println(err) @@ -43,7 +45,7 @@ func main() { os.Exit(1) } - rawApp502, err := GenerateTemplate(templates.App502Template, nil) + rawApp502, err := GenerateTemplate(templates.App502Template, app502Data) if err != nil { fmt.Println(err) os.Exit(1) @@ -57,25 +59,52 @@ func main() { } func Initialize() error { + httpPort := 8090 + httpsPort := 4443 + AppPort := 5442 version := os.Getenv("VERSION") if version == "" { return fmt.Errorf("VERSION is not set") } - localDomain := os.Getenv("LOCAL_DOMAIN") - if localDomain == "" { - return fmt.Errorf("LOCAL_DOMAIN is not set") - } - rawUseTLS := os.Getenv("USE_TLS") if rawUseTLS == "" { - return fmt.Errorf("USE_TLS is not set") + rawUseTLS = "false" } useTLS, err := strconv.ParseBool(rawUseTLS) if err != nil { return fmt.Errorf("USE_TLS is not a boolean") } + lanMode := os.Getenv("LAN_MODE") + if lanMode == "" { + lanMode = "false" + } + + lanPrivateIP := os.Getenv("LAN_PRIVATE_IP") + if lanPrivateIP == "" { + return fmt.Errorf("LAN_PRIVATE_IP is not set") + } + + lanDomain := os.Getenv("LAN_DOMAIN") + if lanDomain == "" { + lanDomain = "openvidu-local.dev" + } + + if lanPrivateIP != "none" && lanDomain == "openvidu-local.dev" { + ipDashes := strings.ReplaceAll(lanPrivateIP, ".", "-") + lanDomain = fmt.Sprintf("%s.%s", ipDashes, lanDomain) + } + + httpUrl := fmt.Sprintf("http://localhost:%d", httpPort) + httpsUrl := "" + if useTLS { + httpsUrl = fmt.Sprintf("https://localhost:%d", httpsPort) + if lanMode == "true" { + httpsUrl = fmt.Sprintf("https://%s:%d", lanDomain, httpsPort) + } + } + livekitApiKey := os.Getenv("LIVEKIT_API_KEY") if livekitApiKey == "" { return fmt.Errorf("LIVEKIT_API_KEY is not set") @@ -107,9 +136,9 @@ func Initialize() error { indexData = &templates.IndexData{ OpenViduVersion: version, - DomainName: localDomain, - IsLocalhost: localDomain == "localhost", - IsTLS: useTLS, + LanMode: lanMode == "true", + HttpUrl: httpUrl, + HttpsUrl: httpsUrl, LiveKitApiKey: livekitApiKey, LiveKitApiSecret: livekitApiSecret, OpenViduSecret: openviduSecret, @@ -120,9 +149,17 @@ func Initialize() error { } caddyData = &templates.CaddyData{ - DomainName: localDomain, - IsLocalhost: localDomain == "localhost", - IsTLS: useTLS, + LanMode: lanMode == "true", + LanDomain: lanDomain, + HttpUrl: httpUrl, + HttpsUrl: httpsUrl, + HttpPort: strconv.Itoa(httpPort), + HttpsPort: strconv.Itoa(httpsPort), + AppPort: strconv.Itoa(AppPort), + } + + app502Data = &templates.App502Data{ + AppPort: strconv.Itoa(AppPort), } return nil diff --git a/caddy-proxy/templates/app502.go b/caddy-proxy/templates/app502.go index 80dd296..84d8813 100644 --- a/caddy-proxy/templates/app502.go +++ b/caddy-proxy/templates/app502.go @@ -1,5 +1,9 @@ package templates +type App502Data struct { + AppPort string +} + const App502Template = ` @@ -35,7 +39,7 @@ const App502Template = `
502 - Bad Gateway

OpenVidu Application Not Found


-

If you are developing an application and run it locally at port 5442, you will see here your application, under +

If you are developing an application and run it locally at port {{.AppPort}}, you will see here your application, under the same domain and TLS certificate as OpenVidu.

diff --git a/caddy-proxy/templates/caddy.go b/caddy-proxy/templates/caddy.go index 5823681..2148886 100644 --- a/caddy-proxy/templates/caddy.go +++ b/caddy-proxy/templates/caddy.go @@ -1,35 +1,25 @@ package templates type CaddyData struct { - DomainName string - IsLocalhost bool - IsTLS bool + LanMode bool + LanDomain string + HttpUrl string + HttpsUrl string + HttpPort string + HttpsPort string + AppPort string } const CaddyfileTemplate = ` -# Minio -{{- if hasSuffix .DomainName ".openvidu-local.dev" }} -http{{if .IsTLS}}s{{end}}://*.openvidu-local.dev:9000, http{{if .IsTLS}}s{{end}}://openvidu-local.dev:9000 { -{{- else }} -http{{if .IsTLS}}s{{end}}://{{.DomainName}}:9000 { -{{- end }} - {{if .IsTLS}}{{if hasSuffix .DomainName "openvidu-local.dev"}}tls internal { - get_certificate http https://certs.openvidu-local.dev/caddy.pem - }{{else}}tls internal{{end}}{{end}} - reverse_proxy http://minio:9000 +(index) { + # Default / + handle_path /* { + root * /var/www/ + file_server + } } - -# General -{{- if hasSuffix .DomainName ".openvidu-local.dev" }} -http{{if .IsTLS}}s{{end}}://*.openvidu-local.dev:4443, http{{if .IsTLS}}s{{end}}://openvidu-local.dev:4443 { -{{- else }} -http{{if .IsTLS}}s{{end}}://{{.DomainName}}:4443 { -{{- end }} - {{if .IsTLS}}{{if hasSuffix .DomainName "openvidu-local.dev"}}tls internal { - get_certificate http https://certs.openvidu-local.dev/caddy.pem - }{{else}}tls internal{{end}}{{end}} - - # API +(general_rules) { + # LiveKit API @openvidu path /twirp/* /rtc/* /rtc handle @openvidu { reverse_proxy http://openvidu:7880 @@ -62,22 +52,8 @@ http{{if .IsTLS}}s{{end}}://{{.DomainName}}:4443 { reverse_proxy http://default-app:5442 } - # Default / - handle_path /* { - root * /var/www/ - file_server - } } - -# Your OpenVidu App -{{- if hasSuffix .DomainName ".openvidu-local.dev" }} -http{{if .IsTLS}}s{{end}}://*.openvidu-local.dev:8000, http{{if .IsTLS}}s{{end}}://openvidu-local.dev:8000 { -{{- else }} -http{{if .IsTLS}}s{{end}}://{{.DomainName}}:8000 { -{{- end }} - {{if .IsTLS}}{{if hasSuffix .DomainName "openvidu-local.dev"}}tls internal { - get_certificate http https://certs.openvidu-local.dev/caddy.pem - }{{else}}tls internal{{end}}{{end}} +(custom_app) { handle_errors { @502 expression {http.error.status_code} == 502 rewrite @502 /app502.html @@ -85,7 +61,36 @@ http{{if .IsTLS}}s{{end}}://{{.DomainName}}:8000 { root /var/www } } - reverse_proxy http://host.docker.internal:5442 + reverse_proxy http://host.docker.internal:{{ .AppPort }} } +# Servers +:{{.HttpPort}} { + import general_rules + import index +} + +{{- if .HttpsUrl }} + +{{- if .LanMode }} +{{.HttpsUrl}} { + {{- if hasSuffix .LanDomain ".openvidu-local.dev" }} + tls internal { + get_certificate http https://certs.openvidu-local.dev/caddy.pem + } + {{- else }} + tls internal + {{- end }} + import general_rules + import custom_app +} +{{- else }} +https://*:{{.HttpsPort}} { + tls internal + import general_rules + import custom_app +} +{{- end }} + +{{- end}} ` diff --git a/caddy-proxy/templates/index.go b/caddy-proxy/templates/index.go index 97b0665..bc2d27d 100644 --- a/caddy-proxy/templates/index.go +++ b/caddy-proxy/templates/index.go @@ -2,9 +2,9 @@ package templates type IndexData struct { OpenViduVersion string - DomainName string - IsLocalhost bool - IsTLS bool + LanMode bool + HttpUrl string + HttpsUrl string DashboardAdminUsername string DashboardAdminPassword string MinioAdminKey string @@ -14,14 +14,15 @@ type IndexData struct { OpenViduSecret string } -const IndexTemplate = ` +const IndexTemplate = ` + OpenVidu Local Deployment - + +
@@ -40,47 +42,76 @@ const IndexTemplate = ` This deployment is only for development purposes.

+ {{- if .HttpsUrl }} + +

HTTPS URLs

+ {{- if .LanMode }} + + {{- end}}
- {{- if not .IsLocalhost }} -

If you want to access this deployment with http(s)://localhost:4443, just change the LOCAL_DOMAIN variable to localhost in the .env file.

- {{- else }} -

If you want to access this deployment with http(s)://openvidu-local.dev:4443, just change the LOCAL_DOMAIN variable to openvidu-local.dev in the .env file.

- {{- end }} - {{- if .IsTLS }} -

If you want to disable TLS, just change the USE_TLS variable to false in the .env file.

- {{- else }} -

If you want to enable TLS, just change the USE_TLS variable to true in the .env file.

+ {{- end }} +

HTTP URLs

+ +
+ +

Credentials

+
- -` + +` diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 71d659d..c344719 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -4,9 +4,11 @@ services: container_name: openvidu-call restart: on-failure environment: + - USE_TLS=${USE_TLS:-false} + - LAN_MODE=${LAN_MODE:-false} + - LAN_DOMAIN=${LAN_DOMAIN:-} + - LAN_PRIVATE_IP=${LAN_PRIVATE_IP:-} - SERVER_PORT=5442 - - USE_TLS=${USE_TLS:-?} - - LIVEKIT_URL=wss://${LOCAL_DOMAIN:-?}:4443/ - LIVEKIT_URL_PRIVATE=ws://openvidu:7880/ - LIVEKIT_API_KEY=${LIVEKIT_API_KEY} - LIVEKIT_API_SECRET=${LIVEKIT_API_SECRET} @@ -15,6 +17,10 @@ services: - CALL_SECRET=${CALL_SECRET:-} - CALL_ADMIN_SECRET=${CALL_ADMIN_SECRET:-} - CALL_RECORDING=${CALL_RECORDING:-} + volumes: + - ./scripts/entrypoint_default_app.sh:/scripts/entrypoint.sh + - ./scripts/utils.sh:/scripts/utils.sh + entrypoint: /bin/sh /scripts/entrypoint.sh depends_on: setup: condition: service_completed_successfully diff --git a/docker-compose.yaml b/docker-compose.yaml index d57c2d0..f19f112 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -7,19 +7,20 @@ services: extra_hosts: - "host.docker.internal:host-gateway" environment: - - LOCAL_DOMAIN=${LOCAL_DOMAIN:-?} - - USE_TLS=${USE_TLS:-?} - - LIVEKIT_API_KEY=${LIVEKIT_API_KEY:-?} - - LIVEKIT_API_SECRET=${LIVEKIT_API_SECRET:-?} - - DASHBOARD_ADMIN_USERNAME=${DASHBOARD_ADMIN_USERNAME:-?} - - DASHBOARD_ADMIN_PASSWORD=${DASHBOARD_ADMIN_PASSWORD:-?} - - MINIO_ACCESS_KEY=${MINIO_ACCESS_KEY:-?} - - MINIO_SECRET_KEY=${MINIO_SECRET_KEY:-?} - - OPENVIDU_SHIM_SECRET=${OPENVIDU_SHIM_SECRET:-?} + - LAN_DOMAIN=${LAN_DOMAIN:-} + - LAN_PRIVATE_IP=${LAN_PRIVATE_IP:-} + - LAN_MODE=${LAN_MODE:-false} + - USE_TLS=${USE_TLS:-false} + - LIVEKIT_API_KEY=${LIVEKIT_API_KEY:-} + - LIVEKIT_API_SECRET=${LIVEKIT_API_SECRET:-} + - DASHBOARD_ADMIN_USERNAME=${DASHBOARD_ADMIN_USERNAME:-} + - DASHBOARD_ADMIN_PASSWORD=${DASHBOARD_ADMIN_PASSWORD:-} + - MINIO_ACCESS_KEY=${MINIO_ACCESS_KEY:-} + - MINIO_SECRET_KEY=${MINIO_SECRET_KEY:-} + - OPENVIDU_SHIM_SECRET=${OPENVIDU_SHIM_SECRET:-} ports: - 4443:4443 - - 9000:9000 - - 8000:8000 + - 8090:8090 depends_on: setup: condition: service_completed_successfully @@ -33,7 +34,7 @@ services: command: > redis-server --bind 0.0.0.0 - --requirepass ${REDIS_PASSWORD:-?} + --requirepass ${REDIS_PASSWORD:-} depends_on: setup: condition: service_completed_successfully @@ -42,10 +43,11 @@ services: image: bitnami/minio:2024.3.15-debian-12-r0 container_name: minio restart: unless-stopped + ports: + - 9000:9000 environment: - - LOCAL_DOMAIN=${LOCAL_DOMAIN:-?} - - MINIO_ROOT_USER=${MINIO_ACCESS_KEY:-?} - - MINIO_ROOT_PASSWORD=${MINIO_SECRET_KEY:-?} + - MINIO_ROOT_USER=${MINIO_ACCESS_KEY:-} + - MINIO_ROOT_PASSWORD=${MINIO_SECRET_KEY:-} - MINIO_DEFAULT_BUCKETS=openvidu - MINIO_CONSOLE_SUBPATH=/minio-console - MINIO_BROWSER_REDIRECT_URL=http://localhost:4443/minio-console/ @@ -63,8 +65,8 @@ services: volumes: - ./mongo/data:/bitnami/mongodb/ environment: - - MONGODB_ROOT_USER=${MONGO_ADMIN_USERNAME:-?} - - MONGODB_ROOT_PASSWORD=${MONGO_ADMIN_PASSWORD:-?} + - MONGODB_ROOT_USER=${MONGO_ADMIN_USERNAME:-} + - MONGODB_ROOT_PASSWORD=${MONGO_ADMIN_PASSWORD:-} depends_on: setup: condition: service_completed_successfully @@ -75,8 +77,8 @@ services: restart: unless-stopped environment: - SERVER_PORT=5000 - - ADMIN_USERNAME=${DASHBOARD_ADMIN_USERNAME:-?} - - ADMIN_PASSWORD=${DASHBOARD_ADMIN_PASSWORD:-?} + - ADMIN_USERNAME=${DASHBOARD_ADMIN_USERNAME:-} + - ADMIN_PASSWORD=${DASHBOARD_ADMIN_PASSWORD:-} - DATABASE_URL=mongodb://mongoadmin:mongoadmin@mongo:27017 depends_on: setup: @@ -87,14 +89,14 @@ services: restart: unless-stopped container_name: openvidu environment: - - PRIVATE_IP=${PRIVATE_IP:-} + - LAN_PRIVATE_IP=${LAN_PRIVATE_IP:-} ports: - "3478:3478/udp" - entrypoint: /bin/sh /entrypoint_openvidu.sh + entrypoint: /bin/sh /scripts/entrypoint.sh command: --config /etc/livekit.yaml volumes: - ./livekit.yaml:/tmp/livekit.yaml - - ./scripts/entrypoint_openvidu.sh:/entrypoint_openvidu.sh + - ./scripts/entrypoint_openvidu.sh:/scripts/entrypoint.sh depends_on: setup: condition: service_completed_successfully @@ -105,7 +107,7 @@ services: restart: unless-stopped ports: - "1935:1935" - - "8080:8080" + - "8085:8085" - "7885:7885/udp" environment: - INGRESS_CONFIG_FILE=/etc/ingress.yaml @@ -132,34 +134,29 @@ services: image: docker.io/wcm65pck/openvidu-v2compatibility:main restart: unless-stopped container_name: openvidu-v2compatibility - command: > - /bin/sh -c " - OV_URL=https://$$LOCAL_DOMAIN:4443/; - LK_URL=wss://$$LOCAL_DOMAIN:4443/; - if [ \"$USE_TLS\" = 'false' ]; then - OV_URL=$(echo $$OV_URL | sed 's/https/http/'); - LK_URL=$(echo $$LK_URL | sed 's/wss/ws/'); - fi && - export OPENVIDU_SHIM_URL=$$OV_URL && - export LIVEKIT_URL=$$LK_URL && - node dist/server.js" + entrypoint: /bin/sh /scripts/entrypoint.sh environment: - - USE_TLS=${USE_TLS:-?} - - LOCAL_DOMAIN=${LOCAL_DOMAIN:-?} + - USE_TLS=${USE_TLS:-false} + - LAN_DOMAIN=${LAN_DOMAIN:-} + - LAN_MODE=${LAN_MODE:-false} + - LAN_PRIVATE_IP=${LAN_PRIVATE_IP:-} - SERVER_PORT=4443 - - OPENVIDU_SHIM_SECRET=${OPENVIDU_SHIM_SECRET:-?} + - OPENVIDU_SHIM_SECRET=${OPENVIDU_SHIM_SECRET:-} - LIVEKIT_URL_PRIVATE=ws://openvidu:7880 - - LIVEKIT_API_KEY=${LIVEKIT_API_KEY:-?} - - LIVEKIT_API_SECRET=${LIVEKIT_API_SECRET:-?} + - LIVEKIT_API_KEY=${LIVEKIT_API_KEY:-} + - LIVEKIT_API_SECRET=${LIVEKIT_API_SECRET:-} - OPENVIDU_PRO_AWS_S3_BUCKET=openvidu - OPENVIDU_PRO_AWS_S3_SERVICE_ENDPOINT=http://minio:9000 - - OPENVIDU_PRO_AWS_S3_ACCESS_KEY=${MINIO_ACCESS_KEY:-?} - - OPENVIDU_PRO_AWS_S3_SECRET_KEY=${MINIO_SECRET_KEY:-?} + - OPENVIDU_PRO_AWS_S3_ACCESS_KEY=${MINIO_ACCESS_KEY:-} + - OPENVIDU_PRO_AWS_S3_SECRET_KEY=${MINIO_SECRET_KEY:-} - REDIS_HOST=redis - REDIS_PORT=6379 - - REDIS_PASSWORD=${REDIS_PASSWORD:-?} + - REDIS_PASSWORD=${REDIS_PASSWORD:-} - REDIS_DB=0 - OPENVIDU_WEBHOOK=false + volumes: + - ./scripts/entrypoint_v2comp.sh:/scripts/entrypoint.sh + - ./scripts/utils.sh:/scripts/utils.sh depends_on: setup: condition: service_completed_successfully @@ -169,8 +166,10 @@ services: container_name: ready-check restart: on-failure environment: - - LOCAL_DOMAIN=${LOCAL_DOMAIN:-?} - - USE_TLS=${USE_TLS:-?} + - USE_TLS=${USE_TLS:-false} + - LAN_DOMAIN=${LAN_DOMAIN:-} + - LAN_MODE=${LAN_MODE:-false} + - LAN_PRIVATE_IP=${LAN_PRIVATE_IP:-} depends_on: - openvidu - ingress @@ -179,8 +178,9 @@ services: - minio - mongo volumes: - - ./scripts/ready-check.sh:/ready-check.sh - command: /bin/sh /ready-check.sh + - ./scripts/ready-check.sh:/scripts/ready-check.sh + - ./scripts/utils.sh:/scripts/utils.sh + command: /bin/sh /scripts/ready-check.sh setup: image: busybox @@ -190,14 +190,14 @@ services: - ./minio:/minio - ./mongo:/mongo - ./egress:/egress - - ./scripts/setup.sh:/setup.sh + - ./scripts/setup.sh:/scripts/setup.sh environment: + - USE_TLS=${USE_TLS:-false} + - LAN_MODE=${LAN_MODE:-false} + - LAN_PRIVATE_IP=${LAN_PRIVATE_IP:-} - RUN_WITH_SCRIPT=${RUN_WITH_SCRIPT:-false} - - PRIVATE_IP=${PRIVATE_IP:-?} user: root - command: /bin/sh -c "/setup.sh" - - + command: /bin/sh scripts/setup.sh volumes: minio-certs: diff --git a/ingress.yaml b/ingress.yaml index 35f257a..5846e6a 100644 --- a/ingress.yaml +++ b/ingress.yaml @@ -8,7 +8,7 @@ api_key: key1 api_secret: abcdefghijklmnopqrstuvwxyz123456 ws_url: ws://openvidu:7880 rtmp_port: 1935 -whip_port: 8080 +whip_port: 8085 http_relay_port: 9090 health_port: 9091 logging: diff --git a/livekit.yaml b/livekit.yaml index 736226e..26ce351 100644 --- a/livekit.yaml +++ b/livekit.yaml @@ -33,7 +33,7 @@ webhook: - http://openvidu-v2compatibility:4443/openvidu/api/webhook ingress: rtmp_base_url: rtmp://localhost:1935/rtmp - whip_base_url: http://localhost:8080/whip + whip_base_url: http://localhost:8085/whip logging: # Logging level for the LiveKit server. # Values: "debug", "info" (default), "warn", "error". diff --git a/openvidu_linux.sh b/openvidu_linux.sh index 948603d..6900b6d 100755 --- a/openvidu_linux.sh +++ b/openvidu_linux.sh @@ -61,21 +61,21 @@ if [ "$START" = "true" ]; then export $(grep -v '^#' .env | xargs) fi - if [ "$PRIVATE_IP" = "auto" ]; then - PRIVATE_IP="$(getPrivateIp)" - if [ -z "$PRIVATE_IP" ]; then - PRIVATE_IP=none + if [ "$LAN_PRIVATE_IP" = "auto" ]; then + LAN_PRIVATE_IP="$(getPrivateIp)" + if [ -z "$LAN_PRIVATE_IP" ]; then + LAN_PRIVATE_IP=none fi - export PRIVATE_IP + export LAN_PRIVATE_IP fi echo "Starting OpenVidu..." export RUN_WITH_SCRIPT=true - docker compose down + docker compose down --volumes docker compose up fi if [ "$STOP" = "true" ]; then echo "Stopping OpenVidu" - docker compose down + docker compose down --volumes fi diff --git a/scripts/entrypoint_default_app.sh b/scripts/entrypoint_default_app.sh new file mode 100644 index 0000000..dcfbbcc --- /dev/null +++ b/scripts/entrypoint_default_app.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +. /scripts/utils.sh + +URL=$(getDeploymentUrl) +export LIVEKIT_URL="${URL}" + +/usr/local/bin/entrypoint.sh diff --git a/scripts/entrypoint_openvidu.sh b/scripts/entrypoint_openvidu.sh index 5f07d84..bf30db0 100644 --- a/scripts/entrypoint_openvidu.sh +++ b/scripts/entrypoint_openvidu.sh @@ -2,17 +2,17 @@ set -e CONFIG_FILE_TMP="/tmp/livekit.yaml" CONFIG_FILE="/etc/livekit.yaml" -PRIVATE_IP="${PRIVATE_IP:-}" +LAN_PRIVATE_IP="${LAN_PRIVATE_IP:-}" cp ${CONFIG_FILE_TMP} ${CONFIG_FILE} -if [ "$PRIVATE_IP" != "none" ]; then +if [ "$LAN_PRIVATE_IP" != "none" ]; then if ! grep -q "^[[:space:]]*node_ip:.*" "$CONFIG_FILE"; then if grep -q "^rtc:" "$CONFIG_FILE"; then - sed -i "/^rtc:/a \ node_ip: $PRIVATE_IP" "$CONFIG_FILE" + sed -i "/^rtc:/a \ node_ip: $LAN_PRIVATE_IP" "$CONFIG_FILE" else echo "rtc:" >> "$CONFIG_FILE" - echo " node_ip: $PRIVATE_IP" >> "$CONFIG_FILE" + echo " node_ip: $LAN_PRIVATE_IP" >> "$CONFIG_FILE" fi fi fi diff --git a/scripts/entrypoint_v2comp.sh b/scripts/entrypoint_v2comp.sh new file mode 100644 index 0000000..ac0e3fe --- /dev/null +++ b/scripts/entrypoint_v2comp.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -e +. /scripts/utils.sh + +URL=$(getDeploymentUrl) +export OPENVIDU_SHIM_URL="${URL}" +export LIVEKIT_URL="${URL}" +node dist/server.js diff --git a/scripts/ready-check.sh b/scripts/ready-check.sh index 5be3d28..2e06ad5 100644 --- a/scripts/ready-check.sh +++ b/scripts/ready-check.sh @@ -1,5 +1,7 @@ #!/bin/sh +. /scripts/utils.sh + wait_for_service() { SERVICE_NAME=$1 SERVICE_URL=$2 @@ -26,10 +28,7 @@ wait_for_service 'Minio' 'http://minio:9000/minio/health/live' wait_for_service 'Minio Console' 'http://minio:9001/minio-console' wait_for_service 'Mongo' 'http://mongo:27017' --connect-timeout 10 --silent -URL=https://$LOCAL_DOMAIN:4443/ -if [ "$USE_TLS" = 'false' ]; then - URL=$(echo $URL | sed 's/https/http/') -fi +URL=$(getDeploymentUrl) for i in $(seq 1 10); do echo 'Starting OpenVidu... Please be patient...' diff --git a/scripts/setup.sh b/scripts/setup.sh old mode 100755 new mode 100644 index 9993c18..00f3f1b --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -6,18 +6,26 @@ if [ "$RUN_WITH_SCRIPT" = 'false' ]; then echo 'Do not run this docker-compose file via "docker compose up" directly.' echo 'Please run it via the provided scripts.' echo '' - echo ' - Linux: ./openvidu_linux.sh' - echo ' - MacOS: ./openvidu_macos.sh' + echo ' - Linux: ./openvidu_linux.sh start' + echo ' - MacOS: ./openvidu_macos.sh start' echo ' - Windows: ./openvidu_windows.ps1' echo '' echo '------------------------' exit 1 fi -if [ "$PRIVATE_IP" = '?' ]; then - echo 'PRIVATE_IP is required' + +if [ -z "$LAN_PRIVATE_IP" ]; then + echo 'LAN_PRIVATE_IP is required' + echo 'Valid values are: "none", "auto" or a valid IP address' echo 'Define it in the .env file' exit 1 fi +if [ "$LAN_MODE" = 'true' ] && [ "$USE_TLS" = 'false' ]; then + echo 'LAN_MODE cannot be "true" if USE_TLS is "false"' + exit 1 +fi + +# Prepare volumes mkdir -p /minio/data && mkdir -p /mongo/data && mkdir -p /mongo/data/ && diff --git a/scripts/utils.sh b/scripts/utils.sh new file mode 100644 index 0000000..108b1db --- /dev/null +++ b/scripts/utils.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +getDeploymentUrl() { + URL="http://localhost:8090" + if [ "${USE_TLS}" = 'true' ]; then + URL="https://localhost:4443" + fi + if [ "${LAN_MODE}" = 'true' ]; then + LAN_DOMAIN=${LAN_DOMAIN:-"openvidu-local.dev"} + if [ "$LAN_PRIVATE_IP" != 'none' ] && [ "${LAN_DOMAIN}" = 'openvidu-local.dev' ]; then + # Replace dots with dashes + LAN_DOMAIN="$(echo "$LAN_PRIVATE_IP" | sed 's/\./-/g').openvidu-local.dev" + fi + URL="https://${LAN_DOMAIN}:4443" + fi + echo "$URL" +}