mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-04 15:08:01 +00:00
feat: reload on change
This commit is contained in:
@@ -76,7 +76,7 @@ class EventTimer extends Timer {
|
||||
// broadcast state
|
||||
broadcastState() {
|
||||
this.io.emit('timer', this.getObject());
|
||||
this.io.emit('playstate', this.playState);
|
||||
this.io.emit('playstate', this.state);
|
||||
this.io.emit('selected-id', this.selectedEventId);
|
||||
this.io.emit('titles', this.titles);
|
||||
}
|
||||
@@ -121,7 +121,7 @@ class EventTimer extends Timer {
|
||||
// Not yet implemented
|
||||
// else if (payload === 'roll') this.roll();
|
||||
|
||||
this.broadcastThis('playstate', this.playState);
|
||||
this.broadcastThis('playstate', this.state);
|
||||
this.broadcastThis('selected-id', this.selectedEventId);
|
||||
this.broadcastThis('titles', this.titles);
|
||||
|
||||
@@ -179,7 +179,7 @@ class EventTimer extends Timer {
|
||||
|
||||
// send state
|
||||
socket.emit('timer', this.getObject());
|
||||
socket.emit('playstate', this.playState);
|
||||
socket.emit('playstate', this.state);
|
||||
socket.emit('selected-id', this.selectedEventId);
|
||||
socket.emit('titles', this.titles);
|
||||
|
||||
@@ -203,7 +203,7 @@ class EventTimer extends Timer {
|
||||
// general playback state
|
||||
socket.on('get-state', () => {
|
||||
socket.emit('timer', this.getObject());
|
||||
socket.emit('playstate', this.playState);
|
||||
socket.emit('playstate', this.state);
|
||||
socket.emit('selected-id', this.selectedEventId);
|
||||
socket.emit('titles', this.titles);
|
||||
});
|
||||
@@ -225,7 +225,7 @@ class EventTimer extends Timer {
|
||||
});
|
||||
|
||||
socket.on('get-playstate', () => {
|
||||
socket.emit('playstate', this.playState);
|
||||
socket.emit('playstate', this.state);
|
||||
});
|
||||
|
||||
/*******************************************/
|
||||
@@ -261,7 +261,6 @@ class EventTimer extends Timer {
|
||||
/*******************************************/
|
||||
// Presenter message
|
||||
socket.on('set-presenter-text', (data) => {
|
||||
console.log(data);
|
||||
this._setterManager('set-presenter-text', data);
|
||||
});
|
||||
|
||||
@@ -326,10 +325,69 @@ class EventTimer extends Timer {
|
||||
// set general
|
||||
this._eventList = events;
|
||||
this.numEvents = numEvents;
|
||||
// handle reload selected
|
||||
if (this.selectedEventId != null) {
|
||||
// Look for event (order might have changed)
|
||||
const eventIndex = this._eventList.findIndex(
|
||||
(e) => e.id === this.selectedEventId
|
||||
);
|
||||
|
||||
// TODO: What to do about reloading
|
||||
// Maybe is missing
|
||||
if (eventIndex === -1) {
|
||||
this._resetTimers();
|
||||
this._resetSelection();
|
||||
return;
|
||||
}
|
||||
|
||||
// Reload data if running
|
||||
if (this._startedAt != null) this.reloadRunning(eventIndex);
|
||||
else if (this.selectedEventId != null) this.loadEvent(eventIndex);
|
||||
}
|
||||
}
|
||||
|
||||
// Reloads changed info in current event
|
||||
reloadRunning(eventIndex) {
|
||||
const e = this._eventList[eventIndex];
|
||||
const start = e.timeStart == null || e.timeStart === '' ? 0 : e.timeStart;
|
||||
let end = e.timeEnd == null || e.timeEnd === '' ? 0 : e.timeEnd;
|
||||
|
||||
// in case the end is earlier than start, we assume is the day after
|
||||
if (end < start) end += 86400000;
|
||||
|
||||
// time stuff
|
||||
const now = this._getCurrentTime();
|
||||
const elapsed = this.getElapsed();
|
||||
|
||||
this.duration = end - start;
|
||||
this.selectedEvent = eventIndex;
|
||||
this._finishAt = now + (this.duration - elapsed);
|
||||
|
||||
// event titles
|
||||
this.titles.titleNow = e.title;
|
||||
this.titles.subtitleNow = e.subtitle;
|
||||
this.titles.presenterNow = e.presenter;
|
||||
|
||||
// assume tere is no next event
|
||||
this.titles.titleNext = null;
|
||||
this.titles.subtitleNext = null;
|
||||
this.titles.presenterNext = null;
|
||||
|
||||
// look for event after
|
||||
if (eventIndex < this.numEvents - 1) {
|
||||
for (let i = eventIndex + 1; i < this.numEvents; i++) {
|
||||
// check that is the right type
|
||||
if (this._eventList[i].type === 'event') {
|
||||
this.titles.titleNext = this._eventList[i].title;
|
||||
this.titles.subtitleNext = this._eventList[i].subtitle;
|
||||
this.titles.presenterNext = this._eventList[i].presenter;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.broadcastState();
|
||||
}
|
||||
|
||||
// Loads a given event
|
||||
loadEvent(eventIndex) {
|
||||
// set event specific
|
||||
const e = this._eventList[eventIndex];
|
||||
@@ -368,6 +426,7 @@ class EventTimer extends Timer {
|
||||
}
|
||||
}
|
||||
}
|
||||
this.broadcastState();
|
||||
}
|
||||
|
||||
_resetSelection() {
|
||||
|
||||
@@ -54,7 +54,7 @@ class Timer {
|
||||
if (!this.showNegative) {
|
||||
this.current = Math.max(this._finishAt + this._pausedTotal - now, 0);
|
||||
} else {
|
||||
(this.current = this._finishAt + this._pausedTotal - now), 0;
|
||||
this.current = this._finishAt + this._pausedTotal - now;
|
||||
}
|
||||
break;
|
||||
case 'pause':
|
||||
@@ -99,6 +99,11 @@ class Timer {
|
||||
this._pausedTotal = null;
|
||||
}
|
||||
|
||||
// get elapsed time
|
||||
getElapsed() {
|
||||
return this.duration - this.current;
|
||||
}
|
||||
|
||||
// getObject
|
||||
getObject() {
|
||||
this.update();
|
||||
@@ -142,7 +147,6 @@ class Timer {
|
||||
pause() {
|
||||
// do we need to change
|
||||
if (this.state === 'pause') return;
|
||||
|
||||
else if (this.duration === 0) return;
|
||||
|
||||
// update pause time
|
||||
|
||||
@@ -39,6 +39,7 @@ function getEventEvents() {
|
||||
.value();
|
||||
}
|
||||
|
||||
// Updates timer object
|
||||
function _updateTimers() {
|
||||
const results = getEventEvents();
|
||||
global.timer.updateEventList(results);
|
||||
@@ -181,6 +182,11 @@ exports.eventsDelete = async (req, res) => {
|
||||
const c = _getEventsCount();
|
||||
const e = db.get('events').find({ id: req.params.eventId }).value();
|
||||
|
||||
if (e == null) {
|
||||
res.status(400).send(`No match`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (c > 0 && e.order < c) incrementFrom(e.order, -1);
|
||||
|
||||
// add new event
|
||||
|
||||
@@ -5,7 +5,6 @@ const event = {
|
||||
presenter: '',
|
||||
timeStart: 0,
|
||||
timeEnd: 0,
|
||||
clockStarted: null,
|
||||
isPublic: false,
|
||||
type: 'event',
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user