mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-06 16:03:52 +00:00
fix paused (#486)
* fix: prevent timer continue on paused count up * refactor: throw if not found on delete
This commit is contained in:
@@ -5,7 +5,7 @@ import { eventStore } from '../stores/EventStore.js';
|
||||
import { PlaybackService } from './PlaybackService.js';
|
||||
import { updateRoll } from './rollUtils.js';
|
||||
import { integrationService } from './integration-service/IntegrationService.js';
|
||||
import { getCurrent, getElapsed, getExpectedFinish } from './timerUtils.js';
|
||||
import { getCurrent, getExpectedFinish } from './timerUtils.js';
|
||||
import { clock } from './Clock.js';
|
||||
import { logger } from '../classes/Logger.js';
|
||||
|
||||
@@ -280,7 +280,7 @@ export class TimerService {
|
||||
|
||||
this.timer.current = updatedTimer;
|
||||
this.timer.secondaryTimer = updatedSecondaryTimer;
|
||||
this.timer.elapsed = getElapsed(this.timer.startedAt, this.timer.clock);
|
||||
this.timer.elapsed = this.timer.duration - this.timer.current;
|
||||
|
||||
if (isFinished) {
|
||||
this.timer.selectedEventId = null;
|
||||
@@ -299,7 +299,8 @@ export class TimerService {
|
||||
this.pausedTime = this.timer.clock - this.pausedAt;
|
||||
}
|
||||
|
||||
if (this.playback === Playback.Play && this.timer.current <= 0 && this.timer.finishedAt === null) {
|
||||
const finishedNow = this.timer.current <= 0 && this.timer.finishedAt === null;
|
||||
if (this.playback === Playback.Play && finishedNow) {
|
||||
this.timer.finishedAt = this.timer.clock;
|
||||
this._onFinish();
|
||||
} else {
|
||||
@@ -318,7 +319,7 @@ export class TimerService {
|
||||
this.pausedTime,
|
||||
this.timer.clock,
|
||||
);
|
||||
this.timer.elapsed = getElapsed(this.timer.startedAt, this.timer.clock);
|
||||
this.timer.elapsed = this.timer.duration - this.timer.current;
|
||||
}
|
||||
|
||||
update(force = false) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { dayInMs } from 'ontime-utils';
|
||||
|
||||
import { getCurrent, getElapsed, getExpectedFinish } from '../timerUtils.js';
|
||||
import { getCurrent, getExpectedFinish } from '../timerUtils.js';
|
||||
|
||||
describe('getExpectedFinish()', () => {
|
||||
it('is null if we havent started', () => {
|
||||
@@ -134,23 +134,7 @@ describe('getCurrent()', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getElapsedTime()', () => {
|
||||
it('time since we started', () => {
|
||||
const startedAt = 0;
|
||||
const clock = 5;
|
||||
const elapsed = getElapsed(startedAt, clock);
|
||||
expect(elapsed).toBe(5);
|
||||
});
|
||||
it('rolls past midnight', () => {
|
||||
const startedAt = 10;
|
||||
const clock = 5;
|
||||
const elapsed = getElapsed(startedAt, clock);
|
||||
|
||||
expect(elapsed).toBe(dayInMs - startedAt + clock);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getExpectedFinish() getElapsedTime() and getCurrentTime() combined', () => {
|
||||
describe('getExpectedFinish() and getCurrentTime() combined', () => {
|
||||
it('without added times, they combine to be duration', () => {
|
||||
const startedAt = 0;
|
||||
const duration = 10;
|
||||
@@ -159,8 +143,8 @@ describe('getExpectedFinish() getElapsedTime() and getCurrentTime() combined', (
|
||||
const addedTime = 0;
|
||||
const clock = 0;
|
||||
const expectedFinish = getExpectedFinish(startedAt, finishedAt, duration, pausedTime, addedTime);
|
||||
const elapsed = getElapsed(startedAt, clock);
|
||||
const current = getCurrent(startedAt, duration, addedTime, pausedTime, clock);
|
||||
const elapsed = duration - current;
|
||||
expect(expectedFinish).toBe(10);
|
||||
expect(elapsed).toBe(0);
|
||||
expect(current).toBe(10);
|
||||
@@ -174,10 +158,10 @@ describe('getExpectedFinish() getElapsedTime() and getCurrentTime() combined', (
|
||||
const addedTime = 2;
|
||||
const clock = 5;
|
||||
const expectedFinish = getExpectedFinish(startedAt, finishedAt, duration, pausedTime, addedTime);
|
||||
const elapsed = getElapsed(startedAt, clock);
|
||||
const current = getCurrent(startedAt, duration, addedTime, pausedTime, clock);
|
||||
const elapsed = duration - current;
|
||||
expect(expectedFinish).toBe(13);
|
||||
expect(elapsed).toBe(5);
|
||||
expect(elapsed).toBe(2);
|
||||
expect(current).toBe(8);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -16,7 +16,14 @@ import { EventLoader, eventLoader } from '../../classes/event-loader/EventLoader
|
||||
import { eventTimer } from '../TimerService.js';
|
||||
import { sendRefetch } from '../../adapters/websocketAux.js';
|
||||
import { runtimeCacheStore } from '../../stores/cachingStore.js';
|
||||
import { cachedAdd, cachedDelete, cachedEdit, cachedReorder, delayedRundownCacheKey } from './delayedRundown.utils.js';
|
||||
import {
|
||||
cachedAdd,
|
||||
cachedClear,
|
||||
cachedDelete,
|
||||
cachedEdit,
|
||||
cachedReorder,
|
||||
delayedRundownCacheKey,
|
||||
} from './delayedRundown.utils.js';
|
||||
import { logger } from '../../classes/Logger.js';
|
||||
import { clock } from '../Clock.js';
|
||||
|
||||
@@ -221,9 +228,6 @@ export async function deleteEvent(eventId) {
|
||||
// notify event loader that rundown size has changed
|
||||
updateChangeNumEvents();
|
||||
|
||||
// invalidate cache
|
||||
runtimeCacheStore.invalidate(delayedRundownCacheKey);
|
||||
|
||||
// advice socket subscribers of change
|
||||
sendRefetch();
|
||||
}
|
||||
@@ -233,7 +237,9 @@ export async function deleteEvent(eventId) {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function deleteAllEvents() {
|
||||
await DataProvider.clearRundown();
|
||||
await cachedClear();
|
||||
|
||||
// notify timer service of changed events
|
||||
updateTimer();
|
||||
forceReset();
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ export async function cachedDelete(eventId: string) {
|
||||
if (delayedRundown.findIndex((event) => event.id === eventId) >= 0) {
|
||||
invalidateFromError();
|
||||
}
|
||||
return;
|
||||
throw new Error(`Event with id ${eventId} not found`);
|
||||
}
|
||||
|
||||
let updatedRundown = DataProvider.getRundown();
|
||||
@@ -171,6 +171,12 @@ export async function cachedReorder(eventId: string, from: number, to: number) {
|
||||
return reorderedEvent;
|
||||
}
|
||||
|
||||
export async function cachedClear() {
|
||||
await DataProvider.clearRundown();
|
||||
runtimeCacheStore.setCached(delayedRundownCacheKey, []);
|
||||
console.log(DataProvider.getRundown(), getDelayedRundown());
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates all delays in a given rundown
|
||||
* @param rundown
|
||||
|
||||
@@ -47,18 +47,3 @@ export function getCurrent(
|
||||
}
|
||||
return startedAt + duration + addedTime + pausedTime - clock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates elapsed time
|
||||
*/
|
||||
export function getElapsed(startedAt: number | null, clock: number): number | null {
|
||||
if (startedAt === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// we are in the day after
|
||||
if (startedAt > clock) {
|
||||
return dayInMs - startedAt + clock;
|
||||
}
|
||||
return clock - startedAt;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user