diff --git a/config.example.json b/config.example.json index 8654880..d7fa04f 100644 --- a/config.example.json +++ b/config.example.json @@ -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": "" } diff --git a/script.js b/script.js index 728dd0f..50df208 100644 --- a/script.js +++ b/script.js @@ -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 ========== diff --git a/server.py b/server.py index 2a747e7..ecd03df 100644 --- a/server.py +++ b/server.py @@ -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,