Fix: Use dynamic URLs for all frontend connections
- CSP: Allow WebSocket/HTTP connections to any domain (for production) - Nakama: Detect host/SSL from browser location instead of hardcoded localhost - WebSocket: Dynamic protocol/host detection for stream and watch sync - HLS/LLHLS/WebRTC: Dynamic URLs in live page and stream components - RTMP/SRT: Show actual domain in my-realms settings page - Forums: Use numeric forum ID for banner/title-color API calls 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
e26fd346f3
commit
118629549e
9 changed files with 121 additions and 28 deletions
|
|
@ -1,11 +1,33 @@
|
|||
import { writable, derived } from 'svelte/store';
|
||||
import { browser } from '$app/environment';
|
||||
|
||||
// Nakama configuration from environment
|
||||
// Nakama configuration - dynamically detect from browser location for production
|
||||
const NAKAMA_SERVER_KEY = import.meta.env.VITE_NAKAMA_SERVER_KEY || 'defaultkey';
|
||||
const NAKAMA_HOST = import.meta.env.VITE_NAKAMA_HOST || 'localhost';
|
||||
const NAKAMA_PORT = import.meta.env.VITE_NAKAMA_PORT || '80';
|
||||
const NAKAMA_USE_SSL = import.meta.env.VITE_NAKAMA_USE_SSL === 'true';
|
||||
|
||||
// Dynamically detect host/protocol from browser location
|
||||
// This ensures production uses the correct domain and SSL settings
|
||||
function getNakamaConfig() {
|
||||
if (!browser) {
|
||||
// SSR fallback - use env vars or defaults
|
||||
return {
|
||||
host: import.meta.env.VITE_NAKAMA_HOST || 'localhost',
|
||||
port: import.meta.env.VITE_NAKAMA_PORT || '80',
|
||||
useSSL: import.meta.env.VITE_NAKAMA_USE_SSL === 'true'
|
||||
};
|
||||
}
|
||||
// Browser: use current page's host/protocol
|
||||
const isSSL = window.location.protocol === 'https:';
|
||||
return {
|
||||
host: window.location.hostname,
|
||||
port: isSSL ? '443' : (window.location.port || '80'),
|
||||
useSSL: isSSL
|
||||
};
|
||||
}
|
||||
|
||||
const nakamaConfig = getNakamaConfig();
|
||||
const NAKAMA_HOST = nakamaConfig.host;
|
||||
const NAKAMA_PORT = nakamaConfig.port;
|
||||
const NAKAMA_USE_SSL = nakamaConfig.useSSL;
|
||||
|
||||
// Polling interval for games lists (ms)
|
||||
export const GAMES_POLL_INTERVAL = 30000;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,16 @@
|
|||
import { writable, derived, get } from 'svelte/store';
|
||||
import { browser } from '$app/environment';
|
||||
|
||||
const WS_URL = import.meta.env.VITE_WS_URL || 'ws://localhost/ws';
|
||||
// Dynamically detect WebSocket URL from browser location
|
||||
function getWsUrl() {
|
||||
if (!browser) {
|
||||
return import.meta.env.VITE_WS_URL || 'ws://localhost/ws';
|
||||
}
|
||||
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||
return `${protocol}//${window.location.host}/ws`;
|
||||
}
|
||||
|
||||
const WS_URL = getWsUrl();
|
||||
const SYNC_INTERVAL = 5000; // Sync every 5 seconds (server pushes every 1s anyway)
|
||||
const DRIFT_THRESHOLD = 2; // Seek if drift > 2 seconds (CyTube-style tight sync)
|
||||
const LEAD_IN_DURATION = 3000; // 3 seconds lead-in for buffering
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue