From 30701530526ff27c1f677a2e3c7e12641da38606 Mon Sep 17 00:00:00 2001 From: legop3 Date: Sun, 15 Mar 2026 22:57:15 -0400 Subject: [PATCH] fix thing --- pi/bin/audio-forward-listener.sh | 12 ++++++++- server/src/services/videoAuthService.js | 33 ++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/pi/bin/audio-forward-listener.sh b/pi/bin/audio-forward-listener.sh index 95504980..8b5d4794 100755 --- a/pi/bin/audio-forward-listener.sh +++ b/pi/bin/audio-forward-listener.sh @@ -31,7 +31,11 @@ else exit 1 fi +LAST_FFMPEG_STATUS="unknown" +LAST_APLAY_STATUS="unknown" + run_pipeline() { + set +e "${FFMPEG_BIN_PATH}" \ -hide_banner \ -loglevel warning \ @@ -51,6 +55,12 @@ run_pipeline() { -f S16_LE \ -r 16000 \ -c 1 + local rc=$? + local -a statuses=("${PIPESTATUS[@]}") + LAST_FFMPEG_STATUS="${statuses[0]:-unknown}" + LAST_APLAY_STATUS="${statuses[1]:-unknown}" + set -e + return "${rc}" } trap 'kill 0 2>/dev/null' EXIT INT TERM @@ -59,6 +69,6 @@ while true; do if run_pipeline; then exit 0 fi - echo "Audio forward listener exited ffmpeg=${PIPESTATUS[0]} aplay=${PIPESTATUS[1]}, restarting in 2s..." >&2 + echo "Audio forward listener exited ffmpeg=${LAST_FFMPEG_STATUS:-unknown} aplay=${LAST_APLAY_STATUS:-unknown}, restarting in 2s..." >&2 sleep 2 done diff --git a/server/src/services/videoAuthService.js b/server/src/services/videoAuthService.js index 68644a27..fe88703f 100644 --- a/server/src/services/videoAuthService.js +++ b/server/src/services/videoAuthService.js @@ -57,6 +57,37 @@ function extractStreamInfo(path) { return null; } +function extractSrtStreamId(rawValue) { + const value = decodeURIComponent(String(rawValue || '').trim()); + if (!value) return ''; + + // streamid may be passed as the full value or as query text. + const match = value.match(/(?:^|[?&]|,|#!::)r=([^,&]+)/); + if (match?.[1]) { + return match[1]; + } + + // Fallback: treat plain token as stream id when no separators are present. + if (!/[?&=,:]/.test(value)) { + return value; + } + return ''; +} + +function extractStreamInfoFromBody(body = {}) { + const fromPath = extractStreamInfo((body.path || '').replace(/^\//, '')); + if (fromPath) return fromPath; + + const srtId = + extractSrtStreamId(body.streamid) || + extractSrtStreamId(body.streamId) || + extractSrtStreamId(body.query); + if (!srtId) return null; + + const baseId = srtId.endsWith('-audio') ? srtId.slice(0, -6) : srtId; + return { type: 'rover', id: srtId, baseId }; +} + function canView(socket) { const mode = getMode(); if (!socket) { @@ -79,7 +110,7 @@ app.post('/mediamtx/auth', (req, res) => { const action = (body.action || '').toLowerCase(); const protocol = (body.protocol || '').toLowerCase(); const ip = getRequestIp(req, body.ip); - const streamInfo = extractStreamInfo(path); + const streamInfo = extractStreamInfoFromBody(body); logger.info('video auth request', { path: body.path, sessionId, stream: streamInfo, action, protocol }); if (ip) {