mirror of
https://github.com/DeNNiiInc/Connect-5.git
synced 2026-04-23 00:06:01 +00:00
Fix production connection: Remove bad proxies, add UI feedback
This commit is contained in:
@@ -23,28 +23,30 @@ class MultiplayerClient {
|
|||||||
// Dynamically construct proxy URLs based on current origin
|
// Dynamically construct proxy URLs based on current origin
|
||||||
const targetUrl = window.location.origin;
|
const targetUrl = window.location.origin;
|
||||||
const servers = [
|
const servers = [
|
||||||
targetUrl, // Primary (local/current)
|
targetUrl, // Primary (Production/Local)
|
||||||
'http://localhost:3000', // Explicit local backend port (common for dev)
|
'http://localhost:3000' // Failover for local dev
|
||||||
`https://corsproxy.io/?${targetUrl}`, // CorsProxy.io
|
|
||||||
`https://api.allorigins.win/raw?url=${encodeURIComponent(targetUrl)}`, // AllOrigins
|
|
||||||
`https://cors-anywhere.herokuapp.com/${targetUrl}` // Corsair Anywhere (Demo)
|
|
||||||
];
|
];
|
||||||
|
|
||||||
let connected = false;
|
let connected = false;
|
||||||
|
const loadingEl = document.querySelector('.loading');
|
||||||
|
|
||||||
for (const serverUrl of servers) {
|
for (const serverUrl of servers) {
|
||||||
if (connected) break;
|
if (connected) break;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (loadingEl) loadingEl.textContent = `Connecting to ${serverUrl}...`;
|
||||||
console.log(`Attempting connection to: ${serverUrl}`);
|
console.log(`Attempting connection to: ${serverUrl}`);
|
||||||
await this.tryConnect(serverUrl);
|
await this.tryConnect(serverUrl);
|
||||||
connected = true;
|
connected = true;
|
||||||
console.log(`✅ Successfully connected to: ${serverUrl}`);
|
console.log(`✅ Successfully connected to: ${serverUrl}`);
|
||||||
|
if (loadingEl) loadingEl.textContent = 'Connected! verifying functionality...';
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn(`❌ Failed to connect to ${serverUrl}:`, error);
|
console.warn(`❌ Failed to connect to ${serverUrl}:`, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!connected) {
|
if (!connected) {
|
||||||
this.showMessage('Failed to connect to any multiplayer server. Please try again later.', 'error');
|
this.showMessage('Failed to connect to any multiplayer server. Please try again later.', 'error');
|
||||||
const loading = document.querySelector('.loading');
|
const loading = document.querySelector('.loading');
|
||||||
@@ -96,6 +98,16 @@ class MultiplayerClient {
|
|||||||
setupSocketListeners() {
|
setupSocketListeners() {
|
||||||
if (!this.socket) return;
|
if (!this.socket) return;
|
||||||
|
|
||||||
|
// Safety timeout: If we are connected but don't get a player list or login prompt within 5 seconds, warn the user.
|
||||||
|
setTimeout(() => {
|
||||||
|
const loading = document.querySelector('.loading');
|
||||||
|
if (loading && loading.textContent.includes('Connecting')) {
|
||||||
|
loading.textContent = 'Connection successful, but server response is slow...';
|
||||||
|
} else if (loading && loading.textContent === 'Loading players...') {
|
||||||
|
loading.innerHTML = 'Server not responding. <a href="#" onclick="multiplayerClient.connect()">Retry</a>';
|
||||||
|
}
|
||||||
|
}, 5000);
|
||||||
|
|
||||||
this.socket.on('connect', () => {
|
this.socket.on('connect', () => {
|
||||||
console.log('✅ Connected to multiplayer server');
|
console.log('✅ Connected to multiplayer server');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user