Adjust to new timer channel format.

This commit is contained in:
2025-09-22 23:26:56 +10:00
parent b21a5969e3
commit 0de496bf3c

View File

@@ -31,14 +31,16 @@ class Timer {
var minutes = Math.floor(dur_seconds / 60);
var hours = Math.floor(minutes / 60);
minutes = minutes - 60 * hours;
// Change rendering mode based on hours or minutes left
if (hours > 0) {
timestr = String(hours).padStart(2, '0') + ':' + String(minutes).padStart(2, '0');
} else {
timestr = String(minutes).padStart(2, '0') + ':' + String(seconds).padStart(2, '0');
}
}
if (this.running) {
this.renderer.update_time(timestr);
}
}
tick() {
// Recursive call run per second to update and change stage
@@ -47,8 +49,10 @@ class Timer {
return
}
this.render_time();
if (this.running) {
setTimeout(this.tick.bind(this), 1000);
}
}
}
class TimerRenderer {
@@ -74,23 +78,13 @@ class TimerRenderer {
this.time_element.textContent = timestr;
}
set_break_color () {
this.background.style.setProperty('--stage-color', 'var(--break-color)');
this.time_element.style.color = "var(--break-color)";
}
set_focus_color () {
this.background.style.setProperty('--stage-color', 'var(--focus-color)');
this.time_element.style.color = "var(--focus-color)";
}
}
function communicate(websocket) {
console.log("Communicating");
const params = new URLSearchParams(window.location.search);
websocket.send(JSON.stringify({type: "init", channel: "SubTimer", channelid: params.get('channelid')}));
websocket.send(JSON.stringify({type: "init", channel: "SubTimer", community: params.get('community')}));
var renderer = new TimerRenderer();
let timer;
@@ -111,11 +105,20 @@ function communicate(websocket) {
timer = new Timer(
renderer,
new Date(args.end_at),
true
args.running
)
timer.tick();
timer.running = args.running;
break;
case "noTimer":
if (timer != null) {
timer.renderer.update_time("--:--")
timer.destroying = true;
}
case "endTimer":
if (timer != null) {
timer.renderer.update_time("00:00")
timer.destroying = true;
}
default:
throw new Error(`Unsupported method requested: ${event.method}.`)
}