Fix stream URL detection for custom domains; add listener_url config

This commit is contained in:
ComputerTech 2026-03-10 19:07:04 +00:00
parent dfccec2b48
commit 1fa6887efd
3 changed files with 32 additions and 5 deletions

View File

@ -12,5 +12,8 @@
"stream_bitrate": "192k",
"max_upload_mb": 500,
"cors_origins": "*",
"debug": false
"debug": false,
"_comment_listener_url": "Public URL of the listener page. Shown in DJ panel as the shareable stream link. Leave empty to auto-detect.",
"listener_url": ""
}

View File

@ -1802,11 +1802,28 @@ window.addEventListener('DOMContentLoaded', () => {
updateManualGlow('B', settings.glowB);
// Set stream URL in the streaming panel
const streamUrl = window.location.hostname.startsWith('dj.')
? `${window.location.protocol}//music.${window.location.hostname.split('.').slice(1).join('.')}`
: `${window.location.protocol}//${window.location.hostname}:5001`;
// Priority: server-configured listener_url > auto-detect > fallback
const streamInput = document.getElementById('stream-url');
if (streamInput) streamInput.value = streamUrl;
if (streamInput) {
const _autoDetectListenerUrl = () => {
const host = window.location.hostname;
// dj.techy.music → techy.music (strip leading "dj.")
// dj.anything.com → anything.com
if (host.startsWith('dj.')) {
return `${window.location.protocol}//${host.slice(3)}`;
}
return `${window.location.protocol}//${host}:5001`;
};
// Try server-configured URL first
fetch('/client_config')
.then(r => r.json())
.then(cfg => {
streamInput.value = cfg.listener_url || _autoDetectListenerUrl();
})
.catch(() => {
streamInput.value = _autoDetectListenerUrl();
});
}
});
// ========== LIVE STREAMING FUNCTIONALITY ==========

View File

@ -42,6 +42,7 @@ CONFIG_SECRET = (CONFIG.get('secret_key') or '').strip() or 'dj_panel_secret'
CONFIG_CORS = CONFIG.get('cors_origins', '*')
CONFIG_MAX_UPLOAD_MB = int(CONFIG.get('max_upload_mb') or 500)
CONFIG_DEBUG = bool(CONFIG.get('debug', False))
CONFIG_LISTENER_URL = (CONFIG.get('listener_url') or '').strip()
DJ_PANEL_PASSWORD = (CONFIG.get('dj_panel_password') or '').strip()
DJ_AUTH_ENABLED = bool(DJ_PANEL_PASSWORD)
@ -605,6 +606,12 @@ def dj_logout():
302,
{'Location': '/login'}
)
@dj_app.route('/client_config')
def client_config():
"""Expose server-side config values needed by the DJ panel client."""
return jsonify({'listener_url': CONFIG_LISTENER_URL})
dj_socketio = SocketIO(
dj_app,
cors_allowed_origins=CONFIG_CORS,