feat: add background music support and static files mount
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,7 @@ services:
|
|||||||
build: .
|
build: .
|
||||||
volumes:
|
volumes:
|
||||||
- quiz-data:/data
|
- quiz-data:/data
|
||||||
|
- ./static:/app/static
|
||||||
environment:
|
environment:
|
||||||
- DB_PATH=/data/quiz.db
|
- DB_PATH=/data/quiz.db
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|||||||
@@ -345,6 +345,7 @@ function handleMessage(msg) {
|
|||||||
show('results-screen');
|
show('results-screen');
|
||||||
}
|
}
|
||||||
else if (msg.type === 'podium') {
|
else if (msg.type === 'podium') {
|
||||||
|
stopBGM();
|
||||||
stopGame();
|
stopGame();
|
||||||
showPodium(msg.leaderboard);
|
showPodium(msg.leaderboard);
|
||||||
}
|
}
|
||||||
@@ -367,6 +368,7 @@ document.getElementById('join-btn').addEventListener('click', () => {
|
|||||||
}
|
}
|
||||||
myDept = dept;
|
myDept = dept;
|
||||||
const displayName = `${fn} ${ln}`;
|
const displayName = `${fn} ${ln}`;
|
||||||
|
startBGM();
|
||||||
ws.send(JSON.stringify({type: 'join', name: `${fn} ${ln}`, dept, display: displayName}));
|
ws.send(JSON.stringify({type: 'join', name: `${fn} ${ln}`, dept, display: displayName}));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -749,6 +751,21 @@ function hexToRgb(hex) {
|
|||||||
return `${r},${g},${b}`;
|
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();
|
connectWS();
|
||||||
|
|
||||||
function exitGame() {
|
function exitGame() {
|
||||||
@@ -758,5 +775,6 @@ function exitGame() {
|
|||||||
connectWS();
|
connectWS();
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
<audio id="bgm" src="/static/music.mp3" loop preload="auto"></audio>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user