V2 ws store (#310)

* Update TimerService.ts

* refactor: message service publishes to store

* refactor: several type improvements

* V2 ws store wss (#309)

* refactor: shared logging types

* refactor: simplify message service consumption

* refactor: create discrete logging system

* refactor: move socket.io > websocket
This commit is contained in:
Carlos Valente
2023-03-15 22:06:47 +01:00
committed by GitHub
parent 11648ee546
commit 76c8f8a4d5
86 changed files with 1876 additions and 1936 deletions
+14 -27
View File
@@ -1,4 +1,4 @@
import { TimerLifeCycle, TimerType } from 'ontime-types';
import { Playback, TimerLifeCycle, TimerState } from 'ontime-types';
import { eventStore } from '../stores/EventStore.js';
import { PlaybackService } from './PlaybackService.js';
@@ -11,27 +11,14 @@ import { clock } from './Clock.js';
export class TimerService {
private readonly _interval: NodeJS.Timer;
playback: string;
playback: Playback;
timer: TimerState;
loadedTimerId: null;
private pausedTime: number;
private pausedAt: number | null;
private secondaryTarget: number | null;
timer: {
clock: number; // realtime clock
current: number | null; // running countdown
elapsed: number | null; // elapsed time in current timer
expectedFinish: number | null;
addedTime: number; // time added by user, can be negative
startedAt: number | null;
finishedAt: number | null; // only if timer has already finished
secondaryTimer: number | null; // used for roll mode
selectedEventId: string | null;
duration: number | null;
timerType: TimerType | null;
};
/**
* @constructor
* @param {object} [timerConfig]
@@ -47,7 +34,7 @@ export class TimerService {
* @private
*/
_clear() {
this.playback = 'stop';
this.playback = Playback.Stop;
this.timer = {
clock: clock.timeNow(),
current: null,
@@ -128,7 +115,7 @@ export class TimerService {
this.loadedTimerId = timer.id;
this.timer.duration = timer.duration;
this.timer.current = timer.duration;
this.playback = 'armed';
this.playback = Playback.Armed;
this.timer.timerType = timer.timerType;
this.pausedTime = 0;
this.pausedAt = 0;
@@ -151,7 +138,7 @@ export class TimerService {
return;
}
if (this.playback === 'play') {
if (this.playback === Playback.Play) {
return;
}
@@ -166,7 +153,7 @@ export class TimerService {
this.timer.startedAt = this.timer.clock;
}
this.playback = 'play';
this.playback = Playback.Play;
this.timer.expectedFinish = getExpectedFinish(
this.timer.startedAt,
this.timer.finishedAt,
@@ -188,11 +175,11 @@ export class TimerService {
}
pause() {
if (this.playback !== 'play') {
if (this.playback !== Playback.Play) {
return;
}
this.playback = 'pause';
this.playback = Playback.Pause;
this.timer.clock = clock.timeNow();
this.pausedAt = this.timer.clock;
this._onPause();
@@ -205,7 +192,7 @@ export class TimerService {
}
stop() {
if (this.playback === 'stop') {
if (this.playback === Playback.Stop) {
return;
}
@@ -248,7 +235,7 @@ export class TimerService {
update() {
this.timer.clock = clock.timeNow();
if (this.playback === 'roll') {
if (this.playback === Playback.Roll) {
const tempCurrentTimer = {
selectedEventId: this.loadedTimerId,
current: this.timer.current,
@@ -279,11 +266,11 @@ export class TimerService {
} else {
// we only update timer if a timer has been started
if (this.timer.startedAt !== null) {
if (this.playback === 'pause') {
if (this.playback === Playback.Pause) {
this.pausedTime = this.timer.clock - this.pausedAt;
}
if (this.playback === 'play' && this.timer.current <= 0 && this.timer.finishedAt === null) {
if (this.playback === Playback.Play && this.timer.current <= 0 && this.timer.finishedAt === null) {
this.timer.finishedAt = this.timer.clock;
this._onFinish();
} else {
@@ -338,7 +325,7 @@ export class TimerService {
this.secondaryTarget = nextEvent.timeStart;
}
this.playback = 'roll';
this.playback = Playback.Roll;
this._onRoll();
this.update();
}