Add sounds
This commit is contained in:
parent
f60718e8fd
commit
51b701663d
8 changed files with 84 additions and 3 deletions
22
public/scripts/make-sounds.js
Executable file
22
public/scripts/make-sounds.js
Executable file
|
|
@ -0,0 +1,22 @@
|
|||
const sounds = {};
|
||||
sounds['victory'] = new Audio('/sounds/victory.ogg');
|
||||
sounds['defeat'] = new Audio('/sounds/defeat.ogg');
|
||||
sounds['draw'] = new Audio('/sounds/draw.ogg');
|
||||
sounds['move'] = new Audio('/sounds/move.ogg');
|
||||
|
||||
Object.values(sounds).forEach((sound) => {
|
||||
sound.volume = 0.12;
|
||||
});
|
||||
|
||||
document.addEventListener('htmx:wsAfterMessage', function (e) {
|
||||
let msg;
|
||||
try {
|
||||
msg = JSON.parse(e.detail.message);
|
||||
} catch (_) {
|
||||
return;
|
||||
}
|
||||
if (msg.type !== 'sound') {
|
||||
return;
|
||||
}
|
||||
sounds[msg.sound].play();
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue