mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-13 03:13:47 +00:00
setup api
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user