From 5a68d292e18f86038db19e15c4e8f3335d1d8ec3 Mon Sep 17 00:00:00 2001 From: cv <34649812+cpvalente@users.noreply.github.com> Date: Sun, 31 Oct 2021 11:16:32 +0100 Subject: [PATCH 1/6] fix: reset timers reset timers as needed with roll mode --- server/src/classes/EventTimer.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server/src/classes/EventTimer.js b/server/src/classes/EventTimer.js index 89b4433b0..1af05326a 100644 --- a/server/src/classes/EventTimer.js +++ b/server/src/classes/EventTimer.js @@ -961,6 +961,7 @@ export class EventTimer extends Timer { foundNow = true; // set timers + this.secondaryTimer = null; this._startedAt = e.timeStart; this._finishAt = e.timeEnd; this.duration = e.timeEnd - e.timeStart; @@ -1000,8 +1001,13 @@ export class EventTimer extends Timer { this._loadThisTitles(e, 'next'); if (foundNow == null) { + // only warn the first time if (this.secondaryTimer == null) console.log('Roll: waiting for event start'); + + // reset running timer + this.current = null; + // timer counts to nextStart this.secondaryTimer = nextStart; } From 0bb728d76c80e2bc3ac21140d04ae07d7f1dded9 Mon Sep 17 00:00:00 2001 From: cv <34649812+cpvalente@users.noreply.github.com> Date: Sun, 31 Oct 2021 11:20:35 +0100 Subject: [PATCH 2/6] refract: broadcast state - ability to broadcast state without recalculating timer --- server/src/classes/EventTimer.js | 11 ++++++++--- server/src/classes/Timer.js | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/server/src/classes/EventTimer.js b/server/src/classes/EventTimer.js index 1af05326a..b47d15ee5 100644 --- a/server/src/classes/EventTimer.js +++ b/server/src/classes/EventTimer.js @@ -203,8 +203,8 @@ export class EventTimer extends Timer { } // broadcast state - broadcastState() { - this.io.emit('timer', this.getObject()); + broadcastState(update = true) { + this.io.emit('timer', this.getObject(update)); this.io.emit('playstate', this.state); this.io.emit('selected', { id: this.selectedEventId, @@ -241,7 +241,12 @@ export class EventTimer extends Timer { this.current = this._finishAt - now; } else { // look for event if none is loaded - if (this.current <= 0 || this.secondaryTimer <= 0) this.rollLoad(); + if (this.current <= 0 || this.secondaryTimer <= 0) { + const newState = this.rollLoad(); + + // broadcast state without recalling timer + if (newState) this.broadcastState(false); + } } } diff --git a/server/src/classes/Timer.js b/server/src/classes/Timer.js index feacd458a..b777063fa 100644 --- a/server/src/classes/Timer.js +++ b/server/src/classes/Timer.js @@ -136,9 +136,9 @@ export class Timer { } // getObject - getObject() { + getObject(update = true) { // update timer - this.update(); + if (update) this.update(); // update timetag this.timeTag = stringFromMillis(this.current); From 4d2769dee4beff612ca3afc48a51e8d5279c99db Mon Sep 17 00:00:00 2001 From: cv <34649812+cpvalente@users.noreply.github.com> Date: Sun, 31 Oct 2021 12:53:46 +0100 Subject: [PATCH 3/6] fix: recalculate timers - recalculate timers in same update call if necessary - use new variable to keep track of upcoming rolling events without recalculating titles --- server/src/classes/EventTimer.js | 39 ++++++++++++++++++++++---------- server/src/classes/Timer.js | 2 ++ 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/server/src/classes/EventTimer.js b/server/src/classes/EventTimer.js index b47d15ee5..ee0d57607 100644 --- a/server/src/classes/EventTimer.js +++ b/server/src/classes/EventTimer.js @@ -232,21 +232,28 @@ export class EventTimer extends Timer { if (this.state !== 'roll') { super.update(); } else { - // get current time + // update timer as usual const now = this._getCurrentTime(); this.clock = now; - if (this.selectedEventId && this.current > 0) { - // update timer as usual + // something is running, update this.current = this._finishAt - now; - } else { - // look for event if none is loaded - if (this.current <= 0 || this.secondaryTimer <= 0) { - const newState = this.rollLoad(); + } else if (this.secondaryTimer > 0) { + // waiting to start, update secondary + this.secondaryTimer = this._secondaryTarget - now; + } - // broadcast state without recalling timer - if (newState) this.broadcastState(false); - } + // look for event if none is loaded + 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' : 'load'; 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') { // TODO: should be more selective on the need to load titles this._loadTitlesNext(); @@ -967,6 +979,8 @@ export class EventTimer extends Timer { // set timers this.secondaryTimer = null; + this._secondaryTarget = null; + this._startedAt = e.timeStart; this._finishAt = e.timeEnd; 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) { this.unload(); console.log('Roll: no events found'); return; } + // we found something to play next if (nextIndex != null) { - // load titles const e = this._eventlist[nextIndex]; this._loadThisTitles(e, 'next'); @@ -1015,6 +1029,7 @@ export class EventTimer extends Timer { // timer counts to nextStart this.secondaryTimer = nextStart; + this._secondaryTarget = e.timeStart; } } } diff --git a/server/src/classes/Timer.js b/server/src/classes/Timer.js index b777063fa..543459c1e 100644 --- a/server/src/classes/Timer.js +++ b/server/src/classes/Timer.js @@ -12,6 +12,7 @@ export class Timer { current = null; timeTag = null; secondaryTimer = null; + _secondaryTarget = null; _finishAt = null; _finishedAt = null; _startedAt = null; @@ -122,6 +123,7 @@ export class Timer { this.current = this.duration; this.running = null; this.secondaryTimer = null; + this._secondaryTarget = null; this._finishAt = null; this._finishedAt = null; this._startedAt = null; From 03ef3e58edf7fb7fdab7eb97df7282b16c381079 Mon Sep 17 00:00:00 2001 From: cv <34649812+cpvalente@users.noreply.github.com> Date: Sun, 31 Oct 2021 13:12:22 +0100 Subject: [PATCH 4/6] style: button disable disable playback buttons while rolling (interface only) --- .../src/common/components/buttons/UnloadIconBtn.jsx | 4 ++-- client/src/features/control/PlaybackButtons.jsx | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/client/src/common/components/buttons/UnloadIconBtn.jsx b/client/src/common/components/buttons/UnloadIconBtn.jsx index e27d5a29d..c5c5f1812 100644 --- a/client/src/common/components/buttons/UnloadIconBtn.jsx +++ b/client/src/common/components/buttons/UnloadIconBtn.jsx @@ -6,8 +6,8 @@ export default function UnloadIconBtn(props) { return ( } - colorScheme='whiteAlpha' - backgroundColor='#ffffff05' + colorScheme='red' + backgroundColor='#ff000022' variant='outline' onClick={clickhandler} width={90} diff --git a/client/src/features/control/PlaybackButtons.jsx b/client/src/features/control/PlaybackButtons.jsx index 081795df7..624aff651 100644 --- a/client/src/features/control/PlaybackButtons.jsx +++ b/client/src/features/control/PlaybackButtons.jsx @@ -16,17 +16,18 @@ const areEqual = (prevProps, nextProps) => { }; const Playback = ({ playback, selectedId, playbackControl }) => { + const isRolling = playback === 'roll'; return (
playbackControl('start')} - disabled={!selectedId} + disabled={!selectedId || isRolling} /> playbackControl('pause')} - disabled={!selectedId} + disabled={!selectedId || isRolling} /> { }; const Transport = ({ playback, selectedId, playbackControl }) => { + const isRolling = playback === 'roll'; return (
{ /> playbackControl('reload')} - disabled={!selectedId} + disabled={!selectedId || isRolling} + /> + playbackControl('unload')} + disabled={!selectedId && !isRolling} /> - playbackControl('unload')} />
); }; From 93580554bd7326b00dc9f037bd276a2cf4523774 Mon Sep 17 00:00:00 2001 From: cv <34649812+cpvalente@users.noreply.github.com> Date: Sun, 31 Oct 2021 13:26:32 +0100 Subject: [PATCH 5/6] fix: roll state fix issue when the call of roll() was resetting the state after trying to load titles --- server/src/classes/EventTimer.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/src/classes/EventTimer.js b/server/src/classes/EventTimer.js index ee0d57607..f93599cc1 100644 --- a/server/src/classes/EventTimer.js +++ b/server/src/classes/EventTimer.js @@ -252,7 +252,7 @@ export class EventTimer extends Timer { // look for events this.rollLoad(); - // broadcast state without recalling timer + // broadcast state without recalculating timer this.broadcastState(false); } } @@ -1038,12 +1038,12 @@ export class EventTimer extends Timer { // do we need to change if (this.state === 'roll') return; - // load into event - this.rollLoad(); - // set state this.state = 'roll'; + // load into event + this.rollLoad(); + this.broadcastState(); } From 9bc29235862280563699f8fd9e35b66342bb2948 Mon Sep 17 00:00:00 2001 From: cv <34649812+cpvalente@users.noreply.github.com> Date: Sun, 31 Oct 2021 13:38:28 +0100 Subject: [PATCH 6/6] fix: handle midnight fixed issue where roll mode wouldnt recognise a end time lower than start time (go through midnight) --- server/src/classes/EventTimer.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/server/src/classes/EventTimer.js b/server/src/classes/EventTimer.js index f93599cc1..64ba0c383 100644 --- a/server/src/classes/EventTimer.js +++ b/server/src/classes/EventTimer.js @@ -973,7 +973,14 @@ export class EventTimer extends Timer { // loop through events, look for where we should be for (const [index, e] of this._eventlist.entries()) { if (!foundNow) { - if (e.timeStart <= now && now < e.timeEnd) { + let normalEnd = e.timeEnd; + + // handle midnight + if (normalEnd < e.timeStart) { + normalEnd += this.DAYMS; + } + + if (e.timeStart <= now && now < normalEnd) { // set flag foundNow = true; @@ -982,9 +989,9 @@ export class EventTimer extends Timer { this._secondaryTarget = null; this._startedAt = e.timeStart; - this._finishAt = e.timeEnd; - this.duration = e.timeEnd - e.timeStart; - this.current = e.timeEnd - now; + this._finishAt = normalEnd; + this.duration = normalEnd - e.timeStart; + this.current = normalEnd - now; // set selection this.selectedEventId = e.id;