setup api

This commit is contained in:
cv
2021-04-07 14:50:14 +02:00
parent e20d9d91ae
commit 115b4f6100
11 changed files with 228 additions and 68 deletions
+56
View File
@@ -0,0 +1,56 @@
class Timer {
constructor(durationInSeconds) {
const now = new Date().getTime();
this.duration = durationInSeconds;
this.current = durationInSeconds;
this.finish = new Date().getTime() + durationInSeconds * 1000;
this.started = now;
}
// update()
update() {
// doesnt include start time yet
const now = new Date().getTime();
this.current = (this.finish - now) * 0.001;
}
// getObject
getObject() {
this.update();
return {
duration: this.duration,
current: this.current,
finish: this.finish,
started: this.started,
};
}
// duration
getDuration(durationInSeconds) {
return this.duration;
}
setDuration() {
try {
this.duration = durationInSeconds;
return true;
} catch (e) {
console.error(e);
return false;
}
}
// current time in seconds
getCurrentInSeconds() {
// update timeStamp
this.update();
return this.current;
}
// playback
start() {}
pause() {}
// playback
stop() {}
}
module.exports = Timer;