mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-19 22:24:11 +00:00
fix: recalculate timers
- recalculate timers in same update call if necessary - use new variable to keep track of upcoming rolling events without recalculating titles
This commit is contained in:
@@ -232,21 +232,28 @@ export class EventTimer extends Timer {
|
|||||||
if (this.state !== 'roll') {
|
if (this.state !== 'roll') {
|
||||||
super.update();
|
super.update();
|
||||||
} else {
|
} else {
|
||||||
// get current time
|
// update timer as usual
|
||||||
const now = this._getCurrentTime();
|
const now = this._getCurrentTime();
|
||||||
this.clock = now;
|
this.clock = now;
|
||||||
|
|
||||||
if (this.selectedEventId && this.current > 0) {
|
if (this.selectedEventId && this.current > 0) {
|
||||||
// update timer as usual
|
// something is running, update
|
||||||
this.current = this._finishAt - now;
|
this.current = this._finishAt - now;
|
||||||
} else {
|
} else if (this.secondaryTimer > 0) {
|
||||||
// look for event if none is loaded
|
// waiting to start, update secondary
|
||||||
if (this.current <= 0 || this.secondaryTimer <= 0) {
|
this.secondaryTimer = this._secondaryTarget - now;
|
||||||
const newState = this.rollLoad();
|
}
|
||||||
|
|
||||||
// broadcast state without recalling timer
|
// look for event if none is loaded
|
||||||
if (newState) this.broadcastState(false);
|
const currentRunning = this.current <= 0 && this.current !== null;
|
||||||
}
|
const secondaryRunning =
|
||||||
|
this.secondaryTimer <= 0 && this.secondaryTimer !== null;
|
||||||
|
|
||||||
|
if (currentRunning || secondaryRunning) {
|
||||||
|
// look for events
|
||||||
|
this.rollLoad();
|
||||||
|
|
||||||
|
// broadcast state without recalling timer
|
||||||
|
this.broadcastState(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -566,6 +573,11 @@ export class EventTimer extends Timer {
|
|||||||
? 'reload'
|
? 'reload'
|
||||||
: 'load';
|
: 'load';
|
||||||
this.loadEvent(this.selectedEventIndex, type);
|
this.loadEvent(this.selectedEventIndex, type);
|
||||||
|
} else if (e.id === this.nextEventId) {
|
||||||
|
// roll needs to recalculate
|
||||||
|
if (this.state === 'roll') {
|
||||||
|
this.rollLoad();
|
||||||
|
}
|
||||||
} else if ('title' in e || 'subtitle' in e || 'presenter') {
|
} else if ('title' in e || 'subtitle' in e || 'presenter') {
|
||||||
// TODO: should be more selective on the need to load titles
|
// TODO: should be more selective on the need to load titles
|
||||||
this._loadTitlesNext();
|
this._loadTitlesNext();
|
||||||
@@ -967,6 +979,8 @@ export class EventTimer extends Timer {
|
|||||||
|
|
||||||
// set timers
|
// set timers
|
||||||
this.secondaryTimer = null;
|
this.secondaryTimer = null;
|
||||||
|
this._secondaryTarget = null;
|
||||||
|
|
||||||
this._startedAt = e.timeStart;
|
this._startedAt = e.timeStart;
|
||||||
this._finishAt = e.timeEnd;
|
this._finishAt = e.timeEnd;
|
||||||
this.duration = e.timeEnd - e.timeStart;
|
this.duration = e.timeEnd - e.timeStart;
|
||||||
@@ -993,15 +1007,15 @@ export class EventTimer extends Timer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// nothing to play next, unload
|
// nothing to play, unload
|
||||||
if (foundNow == null && nextIndex == null) {
|
if (foundNow == null && nextIndex == null) {
|
||||||
this.unload();
|
this.unload();
|
||||||
console.log('Roll: no events found');
|
console.log('Roll: no events found');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// we found something to play next
|
||||||
if (nextIndex != null) {
|
if (nextIndex != null) {
|
||||||
// load titles
|
|
||||||
const e = this._eventlist[nextIndex];
|
const e = this._eventlist[nextIndex];
|
||||||
this._loadThisTitles(e, 'next');
|
this._loadThisTitles(e, 'next');
|
||||||
|
|
||||||
@@ -1015,6 +1029,7 @@ export class EventTimer extends Timer {
|
|||||||
|
|
||||||
// timer counts to nextStart
|
// timer counts to nextStart
|
||||||
this.secondaryTimer = nextStart;
|
this.secondaryTimer = nextStart;
|
||||||
|
this._secondaryTarget = e.timeStart;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ export class Timer {
|
|||||||
current = null;
|
current = null;
|
||||||
timeTag = null;
|
timeTag = null;
|
||||||
secondaryTimer = null;
|
secondaryTimer = null;
|
||||||
|
_secondaryTarget = null;
|
||||||
_finishAt = null;
|
_finishAt = null;
|
||||||
_finishedAt = null;
|
_finishedAt = null;
|
||||||
_startedAt = null;
|
_startedAt = null;
|
||||||
@@ -122,6 +123,7 @@ export class Timer {
|
|||||||
this.current = this.duration;
|
this.current = this.duration;
|
||||||
this.running = null;
|
this.running = null;
|
||||||
this.secondaryTimer = null;
|
this.secondaryTimer = null;
|
||||||
|
this._secondaryTarget = null;
|
||||||
this._finishAt = null;
|
this._finishAt = null;
|
||||||
this._finishedAt = null;
|
this._finishedAt = null;
|
||||||
this._startedAt = null;
|
this._startedAt = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user