Improve downloading with yt-dlp fallback and fix listener streaming

This commit is contained in:
3nd3r
2026-01-02 21:20:32 -06:00
parent 5026d39280
commit e8163fb9a2
5 changed files with 137 additions and 50 deletions

View File

@@ -1551,12 +1551,25 @@ function initSocket() {
if (socket) return socket;
// Log connection details
const serverUrl = window.location.origin;
const urlParams = new URLSearchParams(window.location.search);
const isListenerMode =
window.location.port === '5001' ||
window.location.hostname.startsWith('music.') ||
window.location.hostname.startsWith('listen.') ||
urlParams.get('listen') === 'true';
// If someone opens listener mode on the DJ port (e.g. :5000?listen=true),
// force the Socket.IO connection to the listener backend (:5001).
const serverUrl = (isListenerMode && window.location.port !== '5001' &&
!window.location.hostname.startsWith('music.') &&
!window.location.hostname.startsWith('listen.'))
? `${window.location.protocol}//${window.location.hostname}:5001`
: window.location.origin;
console.log(`🔌 Initializing Socket.IO connection to: ${serverUrl}`);
console.log(` Protocol: ${window.location.protocol}`);
console.log(` Host: ${window.location.host}`);
socket = io({
socket = io(serverUrl, {
transports: ['websocket'],
reconnection: true,
reconnectionAttempts: 10
@@ -2025,14 +2038,14 @@ function restartBroadcast() {
}
// Copy stream URL to clipboard
function copyStreamUrl() {
function copyStreamUrl(evt) {
const urlInput = document.getElementById('stream-url');
urlInput.select();
urlInput.setSelectionRange(0, 99999); // For mobile
try {
document.execCommand('copy');
const btn = event.target;
const btn = evt?.target;
const originalText = btn.textContent;
btn.textContent = '✓';
setTimeout(() => {
@@ -2142,10 +2155,6 @@ function initListenerMode() {
sourceBuffer = mediaSource.addSourceBuffer('audio/webm;codecs=opus');
sourceBuffer.mode = 'sequence';
// Request the startup header now that we are ready to receive it
console.log('📡 Requesting stream header...');
socket.emit('request_header');
// Kick off first append if data is already in queue
if (audioQueue.length > 0 && !sourceBuffer.updating && mediaSource.readyState === 'open') {
sourceBuffer.appendBuffer(audioQueue.shift());
@@ -2229,9 +2238,6 @@ function initListenerMode() {
audioQueue = [];
chunksReceived = 0;
window.sourceBufferErrorCount = 0;
setTimeout(() => {
if (socket) socket.emit('request_header');
}, 1000);
}
}
}
@@ -2317,7 +2323,12 @@ async function enableListenerAudio() {
// Unmute just in case
window.listenerAudio.muted = false;
window.listenerAudio.volume = settings.volume || 0.8;
// Volume is controlled via listenerGainNode; keep element volume sane.
window.listenerAudio.volume = 1.0;
const volEl = document.getElementById('listener-volume');
const volValue = volEl ? parseInt(volEl.value, 10) : 80;
setListenerVolume(Number.isFinite(volValue) ? volValue : 80);
// Check if we have buffered data
const hasBufferedData = () => {