diff --git a/Video/Dockerfile b/Video/Dockerfile index 18abd49168..f1952c090d 100644 --- a/Video/Dockerfile +++ b/Video/Dockerfile @@ -26,7 +26,7 @@ RUN apt-get -qqy update \ && rm -rf /var/lib/apt/lists/* /var/cache/apt/* COPY *.conf /etc/supervisor/conf.d/ -COPY --chown="${SEL_UID}:${SEL_GID}" *.sh video_ready.py /opt/bin/ +COPY --chown="${SEL_UID}:${SEL_GID}" *.sh *.py /opt/bin/ USER ${SEL_UID} diff --git a/Video/video.sh b/Video/video.sh index 6413e69a8a..a5037fcad9 100755 --- a/Video/video.sh +++ b/Video/video.sh @@ -24,7 +24,7 @@ process_name="video.recorder" if [ "${SE_VIDEO_RECORD_STANDALONE}" = "true" ]; then JQ_SESSION_ID_QUERY=".value.nodes[]?.slots[]?.session?.sessionId" SE_NODE_PORT=${SE_NODE_PORT:-"4444"} - NODE_STATUS_ENDPOINT="$(/opt/bin/video_gridUrl.sh)/status" + NODE_STATUS_ENDPOINT="$(python3 /opt/bin/video_gridUrl.py)/status" else JQ_SESSION_ID_QUERY=".[]?.node?.slots | .[0]?.session?.sessionId" SE_NODE_PORT=${SE_NODE_PORT:-"5555"} diff --git a/Video/video_graphQLQuery.sh b/Video/video_graphQLQuery.sh index a10d99e99c..c52d9bd407 100755 --- a/Video/video_graphQLQuery.sh +++ b/Video/video_graphQLQuery.sh @@ -8,7 +8,7 @@ SESSION_ID=$1 if [ -n "${SE_NODE_GRID_GRAPHQL_URL}" ]; then GRAPHQL_ENDPOINT=${SE_NODE_GRID_GRAPHQL_URL} else - GRAPHQL_ENDPOINT="$(/opt/bin/video_gridUrl.sh)" + GRAPHQL_ENDPOINT="$(python3 /opt/bin/video_gridUrl.py)" fi if [[ -n ${GRAPHQL_ENDPOINT} ]] && [[ ! ${GRAPHQL_ENDPOINT} == */graphql ]]; then GRAPHQL_ENDPOINT="${GRAPHQL_ENDPOINT}/graphql" diff --git a/Video/video_gridUrl.py b/Video/video_gridUrl.py new file mode 100644 index 0000000000..88515a9937 --- /dev/null +++ b/Video/video_gridUrl.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +import os + +def get_grid_url(): + max_time = 3 + se_sub_path = os.getenv('SE_SUB_PATH', '') + + # If SE_SUB_PATH is "/", set it to empty string + if se_sub_path == "/": + se_sub_path = "" + + # Start with default grid URL + grid_url = os.getenv('SE_NODE_GRID_URL', '') + + # Check for hub/router configuration + se_hub_host = os.getenv('SE_HUB_HOST') or os.getenv('SE_ROUTER_HOST') + se_hub_port = os.getenv('SE_HUB_PORT') or os.getenv('SE_ROUTER_PORT') + + if se_hub_host and se_hub_port: + grid_url = f"{os.getenv('SE_SERVER_PROTOCOL', 'http')}://{se_hub_host}:{se_hub_port}{se_sub_path}" + # Check for standalone mode + elif (os.getenv('DISPLAY_CONTAINER_NAME') and + os.getenv('SE_VIDEO_RECORD_STANDALONE') == 'true'): + display_container = os.getenv('DISPLAY_CONTAINER_NAME') + node_port = os.getenv('SE_NODE_PORT', '4444') + grid_url = f"{os.getenv('SE_SERVER_PROTOCOL', 'http')}://{display_container}:{node_port}{se_sub_path}" + + # Remove trailing slash if present + grid_url = grid_url.rstrip('/') + + return grid_url + +if __name__ == "__main__": + print(get_grid_url()) diff --git a/Video/video_gridUrl.sh b/Video/video_gridUrl.sh deleted file mode 100755 index 537248c496..0000000000 --- a/Video/video_gridUrl.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -max_time=3 - -if [ "${SE_SUB_PATH}" = "/" ]; then - SE_SUB_PATH="" -fi - -grid_url="${SE_NODE_GRID_URL}" -if [ -n "${SE_HUB_HOST:-$SE_ROUTER_HOST}" ] && [ -n "${SE_HUB_PORT:-$SE_ROUTER_PORT}" ]; then - grid_url=${SE_SERVER_PROTOCOL}://${SE_HUB_HOST:-$SE_ROUTER_HOST}:${SE_HUB_PORT:-$SE_ROUTER_PORT}${SE_SUB_PATH} -elif [ -n "${DISPLAY_CONTAINER_NAME}" ] && [ "${SE_VIDEO_RECORD_STANDALONE}" = "true" ]; then - grid_url="${SE_SERVER_PROTOCOL}://${DISPLAY_CONTAINER_NAME}:${SE_NODE_PORT:-4444}${SE_SUB_PATH}" # For standalone mode -fi - -if [[ ${grid_url} == */ ]]; then - grid_url="${grid_url%/}" -fi - -echo "${grid_url}"