Add cache-busting for JS/WASM assets, WASM readiness signaling to JS, and robust fetch with cache control. Improve lobby updates and refine WebSocket logic.
Some checks failed
Dynamic Branch Deploy / build-and-deploy (push) Failing after 46s
Some checks failed
Dynamic Branch Deploy / build-and-deploy (push) Failing after 46s
This commit is contained in:
@@ -216,27 +216,65 @@ function requestLeaderboardDirect() {
|
||||
setTimeout(() => clearInterval(checkAndRequest), 3000);
|
||||
}
|
||||
|
||||
// Callback von WASM wenn vollständig geladen
|
||||
window.onWasmReady = function() {
|
||||
console.log('✅ WASM fully initialized');
|
||||
wasmReady = true;
|
||||
|
||||
// Switch to menu state
|
||||
setUIState(UIState.MENU);
|
||||
|
||||
// Enable all start buttons
|
||||
enableStartButtons();
|
||||
|
||||
// Load initial leaderboard via direct WebSocket
|
||||
setTimeout(() => {
|
||||
requestLeaderboardDirect();
|
||||
}, 500);
|
||||
};
|
||||
|
||||
// Cache Management - Version wird bei jedem Build aktualisiert
|
||||
const CACHE_VERSION = 1767553871926; // Wird durch Build-Prozess ersetzt
|
||||
|
||||
// Fetch mit Cache-Busting
|
||||
async function fetchWithCache(url) {
|
||||
const cacheBustedUrl = `${url}?v=${CACHE_VERSION}`;
|
||||
console.log(`📦 Loading: ${cacheBustedUrl}`);
|
||||
|
||||
try {
|
||||
const response = await fetch(cacheBustedUrl, {
|
||||
cache: 'no-cache', // Immer vom Server holen wenn Version neu ist
|
||||
headers: {
|
||||
'Cache-Control': 'no-cache, no-store, must-revalidate',
|
||||
'Pragma': 'no-cache'
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
||||
}
|
||||
|
||||
return response;
|
||||
} catch (err) {
|
||||
console.error(`❌ Failed to fetch ${url}:`, err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize WASM
|
||||
async function initWASM() {
|
||||
const go = new Go();
|
||||
|
||||
try {
|
||||
const result = await WebAssembly.instantiateStreaming(fetch("main.wasm"), go.importObject);
|
||||
console.log(`🚀 Loading WASM (Cache Version: ${CACHE_VERSION})...`);
|
||||
|
||||
// WASM mit Cache-Busting laden
|
||||
const response = await fetchWithCache("main.wasm");
|
||||
const result = await WebAssembly.instantiateStreaming(response, go.importObject);
|
||||
|
||||
go.run(result.instance);
|
||||
wasmReady = true;
|
||||
|
||||
// Switch to menu state
|
||||
setUIState(UIState.MENU);
|
||||
|
||||
// Enable all start buttons
|
||||
enableStartButtons();
|
||||
|
||||
console.log('✅ WASM loaded successfully');
|
||||
|
||||
// Load initial leaderboard via direct WebSocket
|
||||
setTimeout(() => {
|
||||
requestLeaderboardDirect();
|
||||
}, 500);
|
||||
// WICHTIG: wasmReady wird erst in onWasmReady() gesetzt, nicht hier!
|
||||
console.log('✅ WASM runtime started, waiting for full initialization...');
|
||||
} catch (err) {
|
||||
console.error('❌ Failed to load WASM:', err);
|
||||
document.getElementById('loading').innerHTML = '<div class="spinner"></div><p>Fehler beim Laden: ' + err.message + '</p>';
|
||||
@@ -322,7 +360,10 @@ function createRoom() {
|
||||
|
||||
// Trigger WASM game start (im Hintergrund)
|
||||
if (window.startGame) {
|
||||
console.log('🎮 Calling window.startGame with:', 'coop', playerName, roomID, teamName, true);
|
||||
window.startGame('coop', playerName, roomID, teamName, true);
|
||||
} else {
|
||||
console.error('❌ window.startGame is not defined!');
|
||||
}
|
||||
|
||||
console.log('🎮 Room created:', roomID);
|
||||
@@ -358,7 +399,10 @@ function joinRoom() {
|
||||
|
||||
// Trigger WASM game start (im Hintergrund)
|
||||
if (window.startGame) {
|
||||
console.log('🎮 Calling window.startGame with:', 'coop', playerName, roomID, teamName, false);
|
||||
window.startGame('coop', playerName, roomID, teamName, false);
|
||||
} else {
|
||||
console.error('❌ window.startGame is not defined!');
|
||||
}
|
||||
|
||||
console.log('🎮 Joining room:', roomID);
|
||||
|
||||
Reference in New Issue
Block a user