This commit is contained in:
ducklet 2021-03-02 20:06:03 +01:00
parent e197c2364f
commit a4b0297c3f
3 changed files with 92 additions and 43 deletions

View file

@ -59,7 +59,7 @@ function _redraw_clients(clients, monitored) {
const player_tpl = q("template#player").content.firstElementChild
for (const cid of monitored) {
const c = clients[cid] ?? {id: cid, name:'', points:0, tokens:0}
const c = clients[cid] ?? { id: cid, name: "", points: 0, tokens: 0 }
let player_el = q(`.player[data-cid='${c.id}']`)
if (player_el) {
// Ensure the element is at the correct position.
@ -129,7 +129,7 @@ function setup_ws() {
monitored = [],
sounds = {}
const sid = session_id()
const overlay = q('#text-overlay')
const overlay = q("#text-overlay")
conn = new Connection()
conn.on("helo", () => {
conn.send("name", "Monitor")
@ -154,22 +154,29 @@ function setup_ws() {
clients[client.id] = client
redraw_clients(clients, monitored)
})
conn.on("control", ({ value: {payload: {action, ...args}} }) => {
if (action === 'monitor' && Array.isArray(args.targets)) {
monitored = args.targets
redraw_clients(clients, monitored)
} else if (action === 'text' && args.text !== undefined) {
if (args.text.length) {
overlay.textContent = args.text
overlay.classList.remove('hidden')
} else {
overlay.classList.add('hidden')
conn.on(
"control",
({
value: {
payload: { action, ...args },
},
}) => {
if (action === "monitor" && Array.isArray(args.targets)) {
monitored = args.targets
redraw_clients(clients, monitored)
} else if (action === "text" && args.text !== undefined) {
if (args.text.length) {
overlay.textContent = args.text
overlay.classList.remove("hidden")
} else {
overlay.classList.add("hidden")
}
} else if (action === "sound" && args.sound) {
const { client_id, sound } = args
sounds[client_id] = new Audio(`sounds/${sound}.mp3`)
}
} else if (action === 'sound' && args.sound) {
const { client_id, sound } = args
sounds[client_id] = new Audio(`sounds/${sound}.mp3`)
}
})
},
)
conn.connect(session_url(sid))
}