Add WebSocket audio fallback for listening

This commit is contained in:
Smittix
2026-02-04 09:46:34 +00:00
parent 6e57927409
commit 43db7c309d

View File

@@ -2147,6 +2147,20 @@ async function _startDirectListenInternal() {
console.log('[LISTEN] Initial play blocked, waiting for canplay');
});
// Fallback: if stream never starts, switch to WebSocket audio
setTimeout(async () => {
if (!isDirectListening || !audioPlayer) return;
if (audioPlayer.readyState > 0) return;
console.warn('[LISTEN] HTTP stream not ready, attempting WebSocket audio fallback');
await startWebSocketListen({
frequency: freq,
modulation: currentModulation,
squelch: squelch,
gain: gain,
device: device
}, audioPlayer);
}, 1500);
// Initialize audio visualizer to feed signal levels to synthesizer
initAudioVisualizer();
@@ -2164,6 +2178,35 @@ async function _startDirectListenInternal() {
}
}
async function startWebSocketListen(config, audioPlayer) {
const selectedType = typeof getSelectedSDRType === 'function'
? getSelectedSDRType()
: getSelectedSDRTypeForScanner();
if (selectedType && selectedType !== 'rtlsdr') {
console.warn('[LISTEN] WebSocket audio supports RTL-SDR only');
return;
}
try {
// Stop HTTP audio stream before switching
await fetch('/listening/audio/stop', { method: 'POST' });
} catch (e) {}
// Reset audio element for MediaSource
try {
audioPlayer.pause();
} catch (e) {}
audioPlayer.removeAttribute('src');
audioPlayer.load();
const ws = initWebSocketAudio();
if (!ws) return;
// Ensure MediaSource is set up
setupMediaSource(audioPlayer);
sendWebSocketCommand('start', config);
}
/**
* Stop direct listening
*/