mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-25 08:59:13 +00:00
countdown to upcoming
This commit is contained in:
@@ -121,15 +121,16 @@ class EventTimer extends Timer {
|
|||||||
const now = this._getCurrentTime();
|
const now = this._getCurrentTime();
|
||||||
this.clock = now;
|
this.clock = now;
|
||||||
|
|
||||||
if (this.selectedEventId == null) {
|
if (this.selectedEventId && this.current > 0) {
|
||||||
// look for event if none is loaded
|
|
||||||
this.rollLoad();
|
|
||||||
} else if (now > this._finishAt) {
|
|
||||||
// look for new if finished
|
|
||||||
this.rollLoad();
|
|
||||||
} else {
|
|
||||||
// update timer as usual
|
// update timer as usual
|
||||||
this.current = this._finishAt - now;
|
this.current = this._finishAt - now;
|
||||||
|
} else {
|
||||||
|
// look for event if none is loaded
|
||||||
|
if (this.current <= 0 || this.secondaryTimer <= 0) this.rollLoad();
|
||||||
|
|
||||||
|
// count to next event
|
||||||
|
// TODO: replace with proper counter
|
||||||
|
if (this.secondaryTimer != null) this.secondaryTimer -= 1000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,6 +163,9 @@ class EventTimer extends Timer {
|
|||||||
else if (payload === 'unload') this.unload();
|
else if (payload === 'unload') this.unload();
|
||||||
else if (payload === 'roll') this.roll();
|
else if (payload === 'roll') this.roll();
|
||||||
|
|
||||||
|
// TODO: Cleanup
|
||||||
|
// here tdo this.broadcastState;
|
||||||
|
// remove broadcast from functions
|
||||||
this.broadcastThis('playstate', this.state);
|
this.broadcastThis('playstate', this.state);
|
||||||
this.broadcastThis('selected-id', this.selectedEventId);
|
this.broadcastThis('selected-id', this.selectedEventId);
|
||||||
this.broadcastThis('titles', this.titles);
|
this.broadcastThis('titles', this.titles);
|
||||||
@@ -577,6 +581,42 @@ class EventTimer extends Timer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_loadThisTitles(eventIndex, type) {
|
||||||
|
if (eventIndex < 0 || eventIndex >= this.numEvents) return;
|
||||||
|
const e = this._eventlist[eventIndex];
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
// now, load to both public and private
|
||||||
|
case 'now':
|
||||||
|
break;
|
||||||
|
case 'now-public':
|
||||||
|
break;
|
||||||
|
case 'now-private':
|
||||||
|
break;
|
||||||
|
|
||||||
|
// next, load to both public and private
|
||||||
|
case 'next':
|
||||||
|
this.titles.titleNext = e.title;
|
||||||
|
this.titles.subtitleNext = e.subtitle;
|
||||||
|
this.titles.presenterNext = e.presenter;
|
||||||
|
this.nextEventId = e.id;
|
||||||
|
|
||||||
|
this.titlesPublic.titleNext = e.title;
|
||||||
|
this.titlesPublic.subtitleNext = e.subtitle;
|
||||||
|
this.titlesPublic.presenterNext = e.presenter;
|
||||||
|
this.nextPublicEventId = e.id;
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 'next-public':
|
||||||
|
break;
|
||||||
|
case 'next-private':
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_loadTitlesNext() {
|
_loadTitlesNext() {
|
||||||
// maybe there is nothing to load
|
// maybe there is nothing to load
|
||||||
if (this.selectedEventIndex == null) return;
|
if (this.selectedEventIndex == null) return;
|
||||||
@@ -660,6 +700,7 @@ class EventTimer extends Timer {
|
|||||||
state = ${this.state}
|
state = ${this.state}
|
||||||
current = ${this.current}
|
current = ${this.current}
|
||||||
duration = ${this.duration}
|
duration = ${this.duration}
|
||||||
|
secondaryTimer = ${this.secondaryTimer}
|
||||||
|
|
||||||
Events
|
Events
|
||||||
------------------------------
|
------------------------------
|
||||||
@@ -753,24 +794,57 @@ class EventTimer extends Timer {
|
|||||||
this._resetTimers(true);
|
this._resetTimers(true);
|
||||||
this._resetSelection();
|
this._resetSelection();
|
||||||
|
|
||||||
|
let foundNow = null;
|
||||||
|
let nextIndex = null;
|
||||||
|
let nextStart = null;
|
||||||
|
|
||||||
// loop through events, look for where we should be
|
// loop through events, look for where we should be
|
||||||
for (const [index, e] of this._eventlist.entries()) {
|
for (const [index, e] of this._eventlist.entries()) {
|
||||||
if (e.timeStart <= now && now < e.timeEnd) {
|
if (!foundNow) {
|
||||||
// set timers
|
if (e.timeStart <= now && now < e.timeEnd) {
|
||||||
this._startedAt = e.timeStart;
|
// set flag
|
||||||
this._finishAt = e.timeEnd;
|
foundNow = true;
|
||||||
this.duration = e.timeEnd - e.timeStart;
|
|
||||||
this.current = e.timeEnd - now;
|
|
||||||
|
|
||||||
// set selection
|
// set timers
|
||||||
this.selectedEventId = e.id;
|
this._startedAt = e.timeStart;
|
||||||
this.selectedEventIndex = index;
|
this._finishAt = e.timeEnd;
|
||||||
|
this.duration = e.timeEnd - e.timeStart;
|
||||||
|
this.current = e.timeEnd - now;
|
||||||
|
|
||||||
// set titles
|
// set selection
|
||||||
this._loadTitlesNow();
|
this.selectedEventId = e.id;
|
||||||
this._loadTitlesNext();
|
this.selectedEventIndex = index;
|
||||||
// exit
|
|
||||||
break;
|
// set titles
|
||||||
|
this._loadTitlesNow();
|
||||||
|
|
||||||
|
// skip this entry for next
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// check how far the start is from now
|
||||||
|
let wait = e.timeStart - now;
|
||||||
|
if (wait > 0) {
|
||||||
|
if (nextStart == null || wait < nextStart) {
|
||||||
|
nextStart = wait;
|
||||||
|
nextIndex = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// nothing to play next, unload
|
||||||
|
if (!foundNow && !nextIndex) {
|
||||||
|
this.unload();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nextIndex) {
|
||||||
|
// load titles
|
||||||
|
this._loadThisTitles(nextIndex, 'next');
|
||||||
|
|
||||||
|
if (!foundNow) {
|
||||||
|
// timer counts to nextStart
|
||||||
|
this.secondaryTimer = nextStart;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ class Timer {
|
|||||||
clock = null;
|
clock = null;
|
||||||
duration = null;
|
duration = null;
|
||||||
current = null;
|
current = null;
|
||||||
|
secondaryTimer = null;
|
||||||
_finishAt = null;
|
_finishAt = null;
|
||||||
_finishedAt = null;
|
_finishedAt = null;
|
||||||
_startedAt = null;
|
_startedAt = null;
|
||||||
@@ -113,6 +114,7 @@ class Timer {
|
|||||||
_resetTimers(total = false) {
|
_resetTimers(total = false) {
|
||||||
if (total) this.duration = null;
|
if (total) this.duration = null;
|
||||||
this.current = this.duration;
|
this.current = this.duration;
|
||||||
|
this.secondaryTimer = null;
|
||||||
this._finishAt = null;
|
this._finishAt = null;
|
||||||
this._finishedAt = null;
|
this._finishedAt = null;
|
||||||
this._startedAt = null;
|
this._startedAt = null;
|
||||||
@@ -133,7 +135,7 @@ class Timer {
|
|||||||
return {
|
return {
|
||||||
clock: this.clock,
|
clock: this.clock,
|
||||||
running: Timer.toSeconds(this.current),
|
running: Timer.toSeconds(this.current),
|
||||||
currentSeconds: Timer.toSeconds(Math.max(this.current, 0)),
|
secondary: Timer.toSeconds(this.secondaryTimer),
|
||||||
durationSeconds: Timer.toSeconds(this.duration),
|
durationSeconds: Timer.toSeconds(this.duration),
|
||||||
expectedFinish: this._getExpectedFinish(),
|
expectedFinish: this._getExpectedFinish(),
|
||||||
startedAt: this._startedAt,
|
startedAt: this._startedAt,
|
||||||
|
|||||||
Reference in New Issue
Block a user