feat: add background music support and static files mount
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -660,6 +660,7 @@ function handle(msg) {
|
||||
else showRoundResults(msg);
|
||||
}
|
||||
else if (msg.type === 'podium') {
|
||||
stopBGM();
|
||||
showPodium(msg.leaderboard);
|
||||
}
|
||||
}
|
||||
@@ -685,6 +686,7 @@ document.getElementById('join-btn').addEventListener('click', () => {
|
||||
}
|
||||
|
||||
const display = `${fn} ${ln}`;
|
||||
startBGM();
|
||||
ws.send(JSON.stringify({type: 'join', name: display, dept, display}));
|
||||
});
|
||||
|
||||
@@ -787,6 +789,23 @@ function showPodium(lb) {
|
||||
|
||||
|
||||
// ── INIT ──────────────────────────────────────────────────────────────────────
|
||||
// ── BACKGROUND MUSIC ─────────────────────────────────────────────────────────
|
||||
|
||||
let bgmStarted = false;
|
||||
function startBGM() {
|
||||
const bgm = document.getElementById('bgm');
|
||||
if (bgmStarted) return;
|
||||
bgmStarted = true;
|
||||
bgm.volume = 0.20;
|
||||
bgm.play().catch(() => {});
|
||||
}
|
||||
function stopBGM() {
|
||||
const bgm = document.getElementById('bgm');
|
||||
bgm.pause();
|
||||
bgm.currentTime = 0;
|
||||
bgmStarted = false;
|
||||
}
|
||||
|
||||
window.addEventListener('resize', () => { if (grid) { setupCanvas(); drawGrid(); }});
|
||||
connectWS();
|
||||
</script>
|
||||
@@ -800,5 +819,6 @@ connectWS();
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<audio id="bgm" src="/static/music.mp3" loop preload="auto"></audio>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user