add buzz sounds
This commit is contained in:
parent
e7ecde32a2
commit
a97f258348
9 changed files with 44 additions and 14 deletions
|
|
@ -103,12 +103,12 @@ const redraw_clients = debounce(_redraw_clients, 200)
|
|||
let highlighted = false
|
||||
function highlight(client_id, until_ns) {
|
||||
if (highlighted) {
|
||||
return
|
||||
return false
|
||||
}
|
||||
const timeout_ms = (until_ns - conn.servertime_now_ns()) / ms_ns
|
||||
if (timeout_ms <= 10) {
|
||||
console.warn("That highlight timeout was ridiculously low:", client_id, timeout_ms)
|
||||
return
|
||||
return false
|
||||
}
|
||||
for (const li of player_list.children) {
|
||||
if (li.dataset.cid === client_id) {
|
||||
|
|
@ -118,7 +118,7 @@ function highlight(client_id, until_ns) {
|
|||
highlighted = false
|
||||
li.classList.remove("buzzing")
|
||||
}, timeout_ms)
|
||||
return
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -126,7 +126,8 @@ function highlight(client_id, until_ns) {
|
|||
function setup_ws() {
|
||||
let clients = {},
|
||||
me,
|
||||
monitored = []
|
||||
monitored = [],
|
||||
sounds = {}
|
||||
const sid = session_id()
|
||||
const overlay = q('#text-overlay')
|
||||
conn = new Connection()
|
||||
|
|
@ -140,7 +141,10 @@ function setup_ws() {
|
|||
const { time: buzztime_ns, client: client_id } = value
|
||||
const duration_ns = 12 * s_ns
|
||||
const until_ns = buzztime_ns + duration_ns
|
||||
highlight(client_id, until_ns)
|
||||
const is_new_buzz = highlight(client_id, until_ns)
|
||||
if (is_new_buzz && sounds[client_id]) {
|
||||
sounds[client_id].play()
|
||||
}
|
||||
})
|
||||
conn.on("clients", ({ value }) => {
|
||||
clients = Object.fromEntries(value.clients.map((c) => [c.id, c]))
|
||||
|
|
@ -161,6 +165,9 @@ function setup_ws() {
|
|||
} else {
|
||||
overlay.classList.add('hidden')
|
||||
}
|
||||
} else if (action === 'sound' && args.sound) {
|
||||
const { client_id, sound } = args
|
||||
sounds[client_id] = new Audio(`sounds/${sound}.mp3`)
|
||||
}
|
||||
})
|
||||
conn.connect(session_url(sid))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue