Adjust to new timer channel format.
This commit is contained in:
35
timer.js
35
timer.js
@@ -31,14 +31,16 @@ class Timer {
|
|||||||
var minutes = Math.floor(dur_seconds / 60);
|
var minutes = Math.floor(dur_seconds / 60);
|
||||||
var hours = Math.floor(minutes / 60);
|
var hours = Math.floor(minutes / 60);
|
||||||
minutes = minutes - 60 * hours;
|
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');
|
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);
|
this.renderer.update_time(timestr);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
tick() {
|
tick() {
|
||||||
// Recursive call run per second to update and change stage
|
// Recursive call run per second to update and change stage
|
||||||
@@ -47,9 +49,11 @@ class Timer {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.render_time();
|
this.render_time();
|
||||||
|
if (this.running) {
|
||||||
setTimeout(this.tick.bind(this), 1000);
|
setTimeout(this.tick.bind(this), 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class TimerRenderer {
|
class TimerRenderer {
|
||||||
constructor (){
|
constructor (){
|
||||||
@@ -74,23 +78,13 @@ class TimerRenderer {
|
|||||||
this.time_element.textContent = timestr;
|
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) {
|
function communicate(websocket) {
|
||||||
console.log("Communicating");
|
console.log("Communicating");
|
||||||
const params = new URLSearchParams(window.location.search);
|
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();
|
var renderer = new TimerRenderer();
|
||||||
let timer;
|
let timer;
|
||||||
@@ -111,11 +105,20 @@ function communicate(websocket) {
|
|||||||
timer = new Timer(
|
timer = new Timer(
|
||||||
renderer,
|
renderer,
|
||||||
new Date(args.end_at),
|
new Date(args.end_at),
|
||||||
true
|
args.running
|
||||||
)
|
)
|
||||||
timer.tick();
|
timer.tick();
|
||||||
timer.running = args.running;
|
|
||||||
break;
|
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:
|
default:
|
||||||
throw new Error(`Unsupported method requested: ${event.method}.`)
|
throw new Error(`Unsupported method requested: ${event.method}.`)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user