Skip to content

Docker: Remove Hub GraphQL dependency from video recorder #2813

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions Video/video.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@ ts_format=${SE_LOG_TIMESTAMP_FORMAT:-"%Y-%m-%d %H:%M:%S,%3N"}
process_name="video.recorder"

if [ "${SE_VIDEO_RECORD_STANDALONE}" = "true" ]; then
JQ_SESSION_ID_QUERY=".value.nodes[]?.slots[]?.session?.sessionId"
JQ_SESSION_ID_QUERY=".value.nodes[0]?.slots[-1]?.session?.sessionId"
JQ_SESSION_CAPABILITIES_QUERY=".value.nodes[0]?.slots[-1]?.session?.capabilities"
SE_NODE_PORT=${SE_NODE_PORT:-"4444"}
NODE_STATUS_ENDPOINT="$(python3 /opt/bin/video_gridUrl.py)/status"
NODE_OWNER_ENDPOINT="$(python3 /opt/bin/video_gridUrl.py)/se/grid/node/owner"
NODE_STATUS_ENDPOINT="${SE_SERVER_PROTOCOL}://${DISPLAY_CONTAINER_NAME}:${SE_NODE_PORT}/status"
else
JQ_SESSION_ID_QUERY=".[]?.node?.slots | .[0]?.session?.sessionId"
JQ_SESSION_ID_QUERY=".value.node?.slots[-1]?.session?.sessionId"
JQ_SESSION_CAPABILITIES_QUERY=".value.node?.slots[-1]?.session?.capabilities"
SE_NODE_PORT=${SE_NODE_PORT:-"5555"}
NODE_STATUS_ENDPOINT="${SE_SERVER_PROTOCOL}://${DISPLAY_CONTAINER_NAME}:${SE_NODE_PORT}/status"
NODE_OWNER_ENDPOINT="${SE_SERVER_PROTOCOL}://${DISPLAY_CONTAINER_NAME}:${SE_NODE_PORT}/se/grid/node/owner"
fi

/opt/bin/validate_endpoint.sh "${NODE_STATUS_ENDPOINT}"
if [ -n "${SE_ROUTER_USERNAME}" ] && [ -n "${SE_ROUTER_PASSWORD}" ]; then
BASIC_AUTH="$(echo -en "${SE_ROUTER_USERNAME}:${SE_ROUTER_PASSWORD}" | base64 -w0)"
BASIC_AUTH="Authorization: Basic ${BASIC_AUTH}"
Expand Down Expand Up @@ -92,6 +91,7 @@ function wait_for_display() {
function check_if_api_respond() {
endpoint_checks=$(curl --noproxy "*" -H "${BASIC_AUTH}" -sk -o /dev/null -w "%{http_code}" "${NODE_STATUS_ENDPOINT}")
if [[ "${endpoint_checks}" != "200" ]]; then
/opt/bin/validate_endpoint.sh "${NODE_STATUS_ENDPOINT}"
return 1
fi
return 0
Expand Down Expand Up @@ -199,8 +199,8 @@ function stop_if_recording_inprogress() {
}

function log_node_response() {
if [[ -f "/tmp/graphQL_$session_id.json" ]]; then
jq '.' "/tmp/graphQL_$session_id.json"
if [[ -n "${session_capabilities}" ]]; then
jq '.' <<<"${session_capabilities}"
fi
}

Expand Down Expand Up @@ -249,15 +249,14 @@ else
recorded_count=0

wait_for_api_respond
while curl --noproxy "*" -H "${BASIC_AUTH}" -sk --request GET ${NODE_STATUS_ENDPOINT} >/tmp/status.json; do
session_id=$(jq -r "${JQ_SESSION_ID_QUERY}" /tmp/status.json)
while curl --noproxy "*" -H "${BASIC_AUTH}" -sk --request GET ${NODE_STATUS_ENDPOINT} >"/tmp/status.json"; do
session_id="$(jq -r "${JQ_SESSION_ID_QUERY}" "/tmp/status.json")"
if [[ "$session_id" != "null" && "$session_id" != "" && "$session_id" != "reserved" && "$recording_started" = "false" ]]; then
echo "$(date -u +"${ts_format}") [${process_name}] - Session: $session_id is created"
return_list=($(bash ${VIDEO_CONFIG_DIRECTORY}/video_graphQLQuery.sh "$session_id"))
session_capabilities="$(jq -r "${JQ_SESSION_CAPABILITIES_QUERY}" "/tmp/status.json")"
return_list=($(bash "${VIDEO_CONFIG_DIRECTORY}/video_nodeQuery.sh" "${session_id}" "${session_capabilities}"))
caps_se_video_record="${return_list[0]}"
video_file_name="${return_list[1]}.mp4"
endpoint_url="${return_list[2]}"
/opt/bin/validate_endpoint.sh "${endpoint_url}" "true"
if [[ "$caps_se_video_record" = "true" ]]; then
echo "$(date -u +"${ts_format}") [${process_name}] - Start recording: $caps_se_video_record, video file name: $video_file_name"
log_node_response
Expand Down
49 changes: 49 additions & 0 deletions Video/video_nodeQuery.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash

# Define parameters
SESSION_ID=$1
SESSION_CAPABILITIES=$2

VIDEO_CAP_NAME=${VIDEO_CAP_NAME:-"se:recordVideo"}
TEST_NAME_CAP=${TEST_NAME_CAP:-"se:name"}
VIDEO_NAME_CAP=${VIDEO_NAME_CAP:-"se:videoName"}
VIDEO_FILE_NAME_TRIM=${SE_VIDEO_FILE_NAME_TRIM_REGEX:-"[:alnum:]-_"}
VIDEO_FILE_NAME_SUFFIX=${SE_VIDEO_FILE_NAME_SUFFIX:-"true"}

if [ -n "${SESSION_CAPABILITIES}" ]; then
# Extract the values from the response
RECORD_VIDEO=$(jq -r '."'${VIDEO_CAP_NAME}'"' <<<"${SESSION_CAPABILITIES}")
TEST_NAME=$(jq -r '."'${TEST_NAME_CAP}'"' <<<"${SESSION_CAPABILITIES}")
VIDEO_NAME=$(jq -r '."'${VIDEO_NAME_CAP}'"' <<<"${SESSION_CAPABILITIES}")
fi

# Check if enabling to record video
if [ "${RECORD_VIDEO,,}" = "false" ]; then
RECORD_VIDEO=false
else
RECORD_VIDEO=true
fi

# Check if video file name is set via capabilities
if [ "${VIDEO_NAME}" != "null" ] && [ -n "${VIDEO_NAME}" ]; then
TEST_NAME="${VIDEO_NAME}"
elif [ "${TEST_NAME}" != "null" ] && [ -n "${TEST_NAME}" ]; then
TEST_NAME="${TEST_NAME}"
else
TEST_NAME=""
fi

# Check if append session ID to the video file name suffix
if [ -z "${TEST_NAME}" ]; then
TEST_NAME="${SESSION_ID}"
elif [ "${VIDEO_FILE_NAME_SUFFIX,,}" = "true" ]; then
TEST_NAME="${TEST_NAME}_${SESSION_ID}"
fi

# Normalize the video file name
TEST_NAME="$(echo "${TEST_NAME}" | tr ' ' '_' | tr -dc "${VIDEO_FILE_NAME_TRIM}" | cut -c 1-251)"

return_array=("${RECORD_VIDEO}" "${TEST_NAME}")

# stdout the values for other scripts consuming
echo "${return_array[@]}"
Loading