mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-14 11:53:49 +00:00
feat: increment running timer
This commit is contained in:
@@ -239,6 +239,12 @@ class EventTimer extends Timer {
|
||||
socket.emit('timer', this.getObject());
|
||||
});
|
||||
|
||||
socket.on('increment-timer', (data) => {
|
||||
if (isNaN(parseInt(data))) return;
|
||||
if (data < -5 || data > 5) return;
|
||||
this.increment(data * 1000 * 60);
|
||||
});
|
||||
|
||||
/*******************************************/
|
||||
// playstate
|
||||
socket.on('set-playstate', (data) => {
|
||||
@@ -624,6 +630,14 @@ class EventTimer extends Timer {
|
||||
this.broadcastState();
|
||||
}
|
||||
|
||||
increment(amount) {
|
||||
// call super
|
||||
super.increment(amount);
|
||||
|
||||
// broadcast current state
|
||||
this.broadcastState();
|
||||
}
|
||||
|
||||
goto(eventIndex) {
|
||||
// load event
|
||||
this.loadEvent(eventIndex);
|
||||
|
||||
+18
-2
@@ -58,6 +58,7 @@ class Timer {
|
||||
}
|
||||
break;
|
||||
case 'pause':
|
||||
if (this.current <= 0) return;
|
||||
// update paused time
|
||||
this._pausedInterval = now - this._pausedAt;
|
||||
break;
|
||||
@@ -129,8 +130,8 @@ class Timer {
|
||||
start() {
|
||||
// do we need to change
|
||||
if (this.state === 'start') return;
|
||||
else if (this.duration === 0) return;
|
||||
else if (this.startedAt == null) {
|
||||
else if (this.duration <= 0) return;
|
||||
else if (this._startedAt == null) {
|
||||
this._resetTimers();
|
||||
const now = this._getCurrentTime();
|
||||
this._startedAt = now;
|
||||
@@ -165,6 +166,21 @@ class Timer {
|
||||
this._resetTimers();
|
||||
this.state = 'stop';
|
||||
}
|
||||
|
||||
increment(amount) {
|
||||
|
||||
if (amount < 0) {
|
||||
if (Math.abs(amount) > this.current) {
|
||||
console.log('ot os');
|
||||
|
||||
this.current = 0;
|
||||
this._finishAt = this._getCurrentTime();
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.current += amount;
|
||||
this._finishAt += amount;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Timer;
|
||||
|
||||
Reference in New Issue
Block a user