mirror of
https://github.com/smittix/intercept.git
synced 2026-07-16 05:18:10 -07:00
Bind monitor audio stream to start request token
This commit is contained in:
@@ -1609,6 +1609,17 @@ def audio_probe() -> Response:
|
|||||||
@receiver_bp.route('/audio/stream')
|
@receiver_bp.route('/audio/stream')
|
||||||
def stream_audio() -> Response:
|
def stream_audio() -> Response:
|
||||||
"""Stream WAV audio."""
|
"""Stream WAV audio."""
|
||||||
|
request_token_raw = request.args.get('request_token')
|
||||||
|
request_token = None
|
||||||
|
if request_token_raw is not None:
|
||||||
|
try:
|
||||||
|
request_token = int(request_token_raw)
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
request_token = None
|
||||||
|
|
||||||
|
if request_token is not None and request_token < audio_start_token:
|
||||||
|
return Response(b'', mimetype='audio/wav', status=204)
|
||||||
|
|
||||||
if audio_source == 'waterfall':
|
if audio_source == 'waterfall':
|
||||||
for _ in range(40):
|
for _ in range(40):
|
||||||
if audio_running:
|
if audio_running:
|
||||||
@@ -1633,6 +1644,8 @@ def stream_audio() -> Response:
|
|||||||
inactive_since: float | None = None
|
inactive_since: float | None = None
|
||||||
|
|
||||||
while audio_running and audio_source == 'waterfall':
|
while audio_running and audio_source == 'waterfall':
|
||||||
|
if request_token is not None and request_token < audio_start_token:
|
||||||
|
break
|
||||||
chunk = read_shared_monitor_audio_chunk(timeout=1.0)
|
chunk = read_shared_monitor_audio_chunk(timeout=1.0)
|
||||||
if chunk:
|
if chunk:
|
||||||
inactive_since = None
|
inactive_since = None
|
||||||
@@ -1699,6 +1712,8 @@ def stream_audio() -> Response:
|
|||||||
first_chunk_deadline = time.time() + 20.0
|
first_chunk_deadline = time.time() + 20.0
|
||||||
warned_wait = False
|
warned_wait = False
|
||||||
while audio_running and proc.poll() is None:
|
while audio_running and proc.poll() is None:
|
||||||
|
if request_token is not None and request_token < audio_start_token:
|
||||||
|
break
|
||||||
# Use select to avoid blocking forever
|
# Use select to avoid blocking forever
|
||||||
ready, _, _ = select.select([proc.stdout], [], [], 2.0)
|
ready, _, _ = select.select([proc.stdout], [], [], 2.0)
|
||||||
if ready:
|
if ready:
|
||||||
|
|||||||
@@ -2603,7 +2603,7 @@ const Waterfall = (function () {
|
|||||||
player.load();
|
player.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function _attachMonitorAudio(nonce) {
|
async function _attachMonitorAudio(nonce, streamToken = null) {
|
||||||
const player = document.getElementById('wfAudioPlayer');
|
const player = document.getElementById('wfAudioPlayer');
|
||||||
if (!player) {
|
if (!player) {
|
||||||
return { ok: false, reason: 'player_missing', message: 'Audio player is unavailable.' };
|
return { ok: false, reason: 'player_missing', message: 'Audio player is unavailable.' };
|
||||||
@@ -2622,7 +2622,10 @@ const Waterfall = (function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await _pauseMonitorAudioElement();
|
await _pauseMonitorAudioElement();
|
||||||
player.src = `/receiver/audio/stream?fresh=1&t=${Date.now()}-${attempt}`;
|
const tokenQuery = (streamToken !== null && streamToken !== undefined && String(streamToken).length > 0)
|
||||||
|
? `&request_token=${encodeURIComponent(String(streamToken))}`
|
||||||
|
: '';
|
||||||
|
player.src = `/receiver/audio/stream?fresh=1&t=${Date.now()}-${attempt}${tokenQuery}`;
|
||||||
player.load();
|
player.load();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -2886,7 +2889,7 @@ const Waterfall = (function () {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const attach = await _attachMonitorAudio(nonce);
|
const attach = await _attachMonitorAudio(nonce, payload?.request_token);
|
||||||
if (nonce !== _audioConnectNonce) return;
|
if (nonce !== _audioConnectNonce) return;
|
||||||
_monitorSource = payload?.source === 'waterfall' ? 'waterfall' : 'process';
|
_monitorSource = payload?.source === 'waterfall' ? 'waterfall' : 'process';
|
||||||
if (
|
if (
|
||||||
|
|||||||
Reference in New Issue
Block a user