feat: add background music support and static files mount
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -345,6 +345,7 @@ function handleMessage(msg) {
|
||||
show('results-screen');
|
||||
}
|
||||
else if (msg.type === 'podium') {
|
||||
stopBGM();
|
||||
stopGame();
|
||||
showPodium(msg.leaderboard);
|
||||
}
|
||||
@@ -367,6 +368,7 @@ document.getElementById('join-btn').addEventListener('click', () => {
|
||||
}
|
||||
myDept = dept;
|
||||
const displayName = `${fn} ${ln}`;
|
||||
startBGM();
|
||||
ws.send(JSON.stringify({type: 'join', name: `${fn} ${ln}`, dept, display: displayName}));
|
||||
});
|
||||
|
||||
@@ -749,6 +751,21 @@ function hexToRgb(hex) {
|
||||
return `${r},${g},${b}`;
|
||||
}
|
||||
|
||||
// ── BACKGROUND MUSIC ─────────────────────────────────────────────────────────
|
||||
const bgm = document.getElementById('bgm');
|
||||
let bgmStarted = false;
|
||||
function startBGM() {
|
||||
if (bgmStarted) return;
|
||||
bgmStarted = true;
|
||||
bgm.volume = 0.35;
|
||||
bgm.play().catch(() => {});
|
||||
}
|
||||
function stopBGM() {
|
||||
bgm.pause();
|
||||
bgm.currentTime = 0;
|
||||
bgmStarted = false;
|
||||
}
|
||||
|
||||
connectWS();
|
||||
|
||||
function exitGame() {
|
||||
@@ -758,5 +775,6 @@ function exitGame() {
|
||||
connectWS();
|
||||
}
|
||||
</script>
|
||||
<audio id="bgm" src="/static/music.mp3" loop preload="auto"></audio>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user