mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-04 06:58:02 +00:00
Compare commits
32 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7f095f0f06 | |||
| 2a3c7f28ff | |||
| 23bfc0787f | |||
| 8169ea724c | |||
| efcd6494be | |||
| f720c56345 | |||
| 52a61777ed | |||
| dfd38c91f6 | |||
| e5f6e5afb9 | |||
| 04f7b342c9 | |||
| cdca5eaad3 | |||
| f39c8b46bb | |||
| c30b0cbf0a | |||
| 95bb9b4366 | |||
| 2dd872eb2d | |||
| c0f9521f86 | |||
| 5577fc0505 | |||
| b77d74a37e | |||
| 42c92329a0 | |||
| b9dbda072d | |||
| a670913320 | |||
| de93827e40 | |||
| 2b2c092d99 | |||
| 858aee83ac | |||
| 1e930851ca | |||
| 477fbbe666 | |||
| 4c38207a15 | |||
| 2b87f72acb | |||
| 563ea92a3b | |||
| 7a5bc76a9e | |||
| 89c7f8707b | |||
| 4c039220dc |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ontime-ui",
|
||||
"version": "2.24.8",
|
||||
"version": "2.21.3",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@chakra-ui/react": "^2.7.0",
|
||||
|
||||
@@ -10,6 +10,10 @@ $icon-color: $ui-white;
|
||||
$button-bg: $gray-1050;
|
||||
$button-size: 48px;
|
||||
|
||||
.mirror {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
|
||||
.buttonContainer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
@@ -22,7 +22,7 @@ function NavigationMenu() {
|
||||
const location = useLocation();
|
||||
|
||||
const { isFullScreen, toggleFullScreen } = useFullscreen();
|
||||
const { toggleMirror } = useViewOptionsStore();
|
||||
const { mirror, toggleMirror } = useViewOptionsStore();
|
||||
const [showButton, setShowButton] = useState(false);
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
const [showMenu, setShowMenu] = useState(false);
|
||||
@@ -63,7 +63,7 @@ function NavigationMenu() {
|
||||
};
|
||||
|
||||
return createPortal(
|
||||
<div id='navigation-menu-portal' ref={menuRef}>
|
||||
<div id='navigation-menu-portal' ref={menuRef} className={mirror ? style.mirror : ''}>
|
||||
<RenameClientModal isOpen={isOpen} onClose={onClose} />
|
||||
<div className={`${style.buttonContainer} ${!showButton && !showMenu ? style.hidden : ''}`}>
|
||||
<button onClick={toggleMenu} aria-label='toggle menu' className={style.navButton}>
|
||||
|
||||
@@ -75,8 +75,8 @@ export const setPlayback = {
|
||||
reload: () => {
|
||||
socketSendJson('reload');
|
||||
},
|
||||
addTime: (amount: number) => {
|
||||
socketSendJson('addtime', amount);
|
||||
delay: (amount: number) => {
|
||||
socketSendJson('delay', amount);
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { cx, getAccessibleColour } from '../styleUtils';
|
||||
import { cx } from '../styleUtils';
|
||||
|
||||
import style from './styleUtils.module.scss';
|
||||
|
||||
@@ -13,24 +13,3 @@ describe('cx()', () => {
|
||||
expect(merged).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getAccessibleColour()', () => {
|
||||
it('handles named colours', () => {
|
||||
const colour = 'red';
|
||||
const { backgroundColor, color } = getAccessibleColour(colour);
|
||||
expect(backgroundColor).toBe('#FF0000FF');
|
||||
expect(color).toBe('#fffffa');
|
||||
});
|
||||
it('handles hex colours', () => {
|
||||
const colour = '#0F0';
|
||||
const { backgroundColor, color } = getAccessibleColour(colour);
|
||||
expect(backgroundColor).toBe('#00FF00FF');
|
||||
expect(color).toBe('black');
|
||||
});
|
||||
it('handles transparens', () => {
|
||||
const colour = '#0F08';
|
||||
const { backgroundColor, color } = getAccessibleColour(colour);
|
||||
expect(backgroundColor).toBe('#0C940CFF');
|
||||
expect(color).toBe('#fffffa');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export const isOnlyNumbers = /^\d+$/;
|
||||
export const isIPAddress = /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$/;
|
||||
export const startsWithHttp = /^http:\/\//;
|
||||
export const startsWithHttpOrS = /^https?:\/\//;
|
||||
|
||||
@@ -13,15 +13,13 @@ type ColourCombination = {
|
||||
export const getAccessibleColour = (bgColour?: string): ColourCombination => {
|
||||
if (bgColour) {
|
||||
try {
|
||||
const originalColour = Color(bgColour);
|
||||
const backgroundColorMix = originalColour.alpha(1).mix(Color('#1a1a1a'), 1 - originalColour.alpha());
|
||||
const textColor = backgroundColorMix.isLight() ? 'black' : '#fffffa';
|
||||
return { backgroundColor: backgroundColorMix.hexa(), color: textColor };
|
||||
const textColor = Color(bgColour).isLight() ? 'black' : '#fffffa';
|
||||
return { backgroundColor: bgColour, color: textColor };
|
||||
} catch (_error) {
|
||||
/* we do not handle errors here */
|
||||
}
|
||||
}
|
||||
return { backgroundColor: '#1a1a1a', color: '#fffffa' };
|
||||
return { backgroundColor: '#000', color: '#fffffa' };
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -86,22 +86,22 @@ export default function PlaybackTimer(props: PlaybackTimerProps) {
|
||||
)}
|
||||
<div className={style.btn}>
|
||||
<Tooltip label='Remove 1 minute' openDelay={tooltipDelayMid} shouldWrapChildren={disableButtons}>
|
||||
<TapButton onClick={() => setPlayback.addTime(-60)} disabled={disableButtons} aspect='square'>
|
||||
<TapButton onClick={() => setPlayback.delay(-1)} disabled={disableButtons} aspect='square'>
|
||||
-1
|
||||
</TapButton>
|
||||
</Tooltip>
|
||||
<Tooltip label='Add 1 minute' openDelay={tooltipDelayMid} shouldWrapChildren={disableButtons}>
|
||||
<TapButton onClick={() => setPlayback.addTime(60)} disabled={disableButtons} aspect='square'>
|
||||
<TapButton onClick={() => setPlayback.delay(1)} disabled={disableButtons} aspect='square'>
|
||||
+1
|
||||
</TapButton>
|
||||
</Tooltip>
|
||||
<Tooltip label='Remove 5 minutes' openDelay={tooltipDelayMid} shouldWrapChildren={disableButtons}>
|
||||
<TapButton onClick={() => setPlayback.addTime(-5 * 60)} disabled={disableButtons} aspect='square'>
|
||||
<TapButton onClick={() => setPlayback.delay(-5)} disabled={disableButtons} aspect='square'>
|
||||
-5
|
||||
</TapButton>
|
||||
</Tooltip>
|
||||
<Tooltip label='Add 5 minutes' openDelay={tooltipDelayMid} shouldWrapChildren={disableButtons}>
|
||||
<TapButton onClick={() => setPlayback.addTime(+5 * 60)} disabled={disableButtons} aspect='square'>
|
||||
<TapButton onClick={() => setPlayback.delay(+5)} disabled={disableButtons} aspect='square'>
|
||||
+5
|
||||
</TapButton>
|
||||
</Tooltip>
|
||||
|
||||
@@ -5,7 +5,6 @@ import { isOntimeBlock, isOntimeDelay, isOntimeEvent, OntimeRundown, OntimeRundo
|
||||
|
||||
import useFollowComponent from '../../common/hooks/useFollowComponent';
|
||||
import { useLocalStorage } from '../../common/hooks/useLocalStorage';
|
||||
import { getAccessibleColour } from '../../common/utils/styleUtils';
|
||||
|
||||
import BlockRow from './cuesheet-table-elements/BlockRow';
|
||||
import CuesheetHeader from './cuesheet-table-elements/CuesheetHeader';
|
||||
@@ -121,8 +120,8 @@ export default function Cuesheet({ data, columns, handleUpdate, selectedId }: Cu
|
||||
} else if (row.original.colour) {
|
||||
try {
|
||||
// the colour is user defined and might be invalid
|
||||
const accessibleBackgroundColor = Color(getAccessibleColour(row.original.colour).backgroundColor);
|
||||
rowBgColour = accessibleBackgroundColor.fade(0.75).hexa();
|
||||
const colour = new Color(row.original.colour).alpha(0.25);
|
||||
rowBgColour = colour.hsl().string();
|
||||
} catch (_error) {
|
||||
/* we do not handle errors here */
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ function EventRow(props: PropsWithChildren<EventRowProps>) {
|
||||
const ownRef = useRef<HTMLTableRowElement>(null);
|
||||
const [isVisible, setIsVisible] = useState(false);
|
||||
|
||||
const textColour = getAccessibleColour(colour);
|
||||
const bgColour = textColour.backgroundColor;
|
||||
const bgColour = colour;
|
||||
const textColour = getAccessibleColour(bgColour);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const observer = new IntersectionObserver(
|
||||
@@ -55,7 +55,7 @@ function EventRow(props: PropsWithChildren<EventRowProps>) {
|
||||
style={{ opacity: `${isPast ? pastOpacity : '1'}` }}
|
||||
ref={selectedRef ?? ownRef}
|
||||
>
|
||||
<td className={style.indexColumn} style={{ backgroundColor: bgColour, color: textColour.color }}>
|
||||
<td className={style.indexColumn} style={{ backgroundColor: bgColour, color: textColour?.color }}>
|
||||
{eventIndex}
|
||||
</td>
|
||||
{isVisible ? children : null}
|
||||
|
||||
@@ -79,7 +79,6 @@ export default function HttpIntegration() {
|
||||
</div>
|
||||
<Switch {...register('enabledOut')} variant='ontime-on-light' />
|
||||
</div>
|
||||
|
||||
<HttpSubscriptionRow
|
||||
cycle={TimerLifeCycle.onLoad}
|
||||
title={sectionText.onLoad.title}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { IoRemove } from '@react-icons/all-files/io5/IoRemove';
|
||||
import { HttpSettings, TimerLifeCycle } from 'ontime-types';
|
||||
|
||||
import { useEmitLog } from '../../../../common/stores/logger';
|
||||
import { startsWithHttp } from '../../../../common/utils/regex';
|
||||
import { startsWithHttpOrS } from '../../../../common/utils/regex';
|
||||
|
||||
import collapseStyles from '../../../../common/components/collapse-bar/CollapseBar.module.scss';
|
||||
import styles from '../../Modal.module.scss';
|
||||
@@ -71,7 +71,7 @@ export default function SubscriptionRow(props: SubscriptionRowProps) {
|
||||
variant='ontime-filled-on-light'
|
||||
autoComplete='off'
|
||||
{...register(`subscriptions.${cycle}.${index}.message`, {
|
||||
pattern: { value: startsWithHttp, message: 'Request address must start with http://' },
|
||||
pattern: { value: startsWithHttpOrS, message: 'Request address must start with http://' },
|
||||
})}
|
||||
/>
|
||||
<Switch variant='ontime-on-light' {...register(`subscriptions.${cycle}.${index}.enabled`)} />
|
||||
|
||||
@@ -140,7 +140,7 @@ export default function Backstage(props: BackstageProps) {
|
||||
{isNegative ? (
|
||||
<div className='aux-timers__value'>{expectedFinish}</div>
|
||||
) : (
|
||||
<SuperscriptTime time={expectedFinish} className='aux-timers__value' />
|
||||
<SuperscriptTime time={startedAt} className='aux-timers__value' />
|
||||
)}
|
||||
</div>
|
||||
<div className='timer-gap' />
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ontime",
|
||||
"version": "2.24.8",
|
||||
"version": "2.21.3",
|
||||
"author": "Carlos Valente",
|
||||
"description": "Time keeping for live events",
|
||||
"repository": "https://github.com/cpvalente/ontime",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"name": "ontime-server",
|
||||
"type": "module",
|
||||
"main": "src/index.ts",
|
||||
"version": "2.24.8",
|
||||
"version": "2.21.3",
|
||||
"exports": "./src/index.js",
|
||||
"dependencies": {
|
||||
"body-parser": "^1.20.0",
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { LogOrigin, OntimeEvent } from 'ontime-types';
|
||||
import { EventLoader } from '../classes/event-loader/EventLoader.js';
|
||||
import { editEvent } from '../services/rundown-service/RundownService.js';
|
||||
import { coerceString, coerceNumber, coerceBoolean, coerceColour } from '../utils/coerceType.js';
|
||||
import { coerceString, coerceNumber, coerceBoolean } from '../utils/coerceType.js';
|
||||
import { logger } from '../classes/Logger.js';
|
||||
import { isKeyOfType, isOntimeEvent } from 'ontime-types/src/utils/guards.js';
|
||||
|
||||
const whitelistedPayload = {
|
||||
title: coerceString,
|
||||
@@ -17,8 +16,7 @@ const whitelistedPayload = {
|
||||
isPublic: coerceBoolean,
|
||||
skip: coerceBoolean,
|
||||
|
||||
colour: coerceColour,
|
||||
|
||||
colour: coerceString,
|
||||
user0: coerceString,
|
||||
user1: coerceString,
|
||||
user2: coerceString,
|
||||
@@ -31,12 +29,12 @@ const whitelistedPayload = {
|
||||
user9: coerceString,
|
||||
};
|
||||
|
||||
export function parse(property: string, value: unknown) {
|
||||
if (!isKeyOfType(property, whitelistedPayload)) {
|
||||
throw new Error(`Property ${property} not permitted`);
|
||||
export function parse(field: string, value: unknown) {
|
||||
if (!Object.hasOwn(whitelistedPayload, field)) {
|
||||
throw new Error(`Field ${field} not permitted`);
|
||||
}
|
||||
const parserFn = whitelistedPayload[property];
|
||||
return { parsedProperty: property, parsedPayload: parserFn(value) };
|
||||
const parserFn = whitelistedPayload[field];
|
||||
return parserFn(value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,10 +49,8 @@ export function updateEvent(
|
||||
newValue: OntimeEvent[typeof propertyName],
|
||||
) {
|
||||
const event = EventLoader.getEventWithId(eventId);
|
||||
|
||||
if (event) {
|
||||
if (!isOntimeEvent(event)) {
|
||||
throw new Error(`Can only update events`);
|
||||
}
|
||||
const propertiesToUpdate = { [propertyName]: newValue };
|
||||
|
||||
// Handles the special case for duration
|
||||
|
||||
@@ -2,6 +2,8 @@ import { messageService } from '../services/message-service/MessageService.js';
|
||||
import { PlaybackService } from '../services/PlaybackService.js';
|
||||
import { eventStore } from '../stores/EventStore.js';
|
||||
import { parse, updateEvent } from './integrationController.config.js';
|
||||
import { isKeyOfType } from 'ontime-types/src/utils/guards.js';
|
||||
import { event } from '../models/eventsDefinition.js';
|
||||
|
||||
export type ChangeOptions = {
|
||||
eventId: string;
|
||||
@@ -270,8 +272,11 @@ export function dispatchFromAdapter(
|
||||
// WS: {type: 'change', payload: { eventId, property, value } }
|
||||
case 'change': {
|
||||
const { eventId, property, value } = payload as ChangeOptions;
|
||||
const { parsedPayload, parsedProperty } = parse(property, value);
|
||||
return updateEvent(eventId, parsedProperty, parsedPayload);
|
||||
if (!isKeyOfType(property, event)) {
|
||||
throw new Error(`Cannot update unknown event property ${property}`);
|
||||
}
|
||||
const parsedPayload = parse(property, value);
|
||||
return updateEvent(eventId, property, parsedPayload);
|
||||
}
|
||||
|
||||
default: {
|
||||
|
||||
@@ -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, getExpectedFinish, skippedOutOfEvent } from './timerUtils.js';
|
||||
import { getCurrent, getExpectedFinish } from './timerUtils.js';
|
||||
import { clock } from './Clock.js';
|
||||
import { logger } from '../classes/Logger.js';
|
||||
import type { RestorePoint } from './RestoreService.js';
|
||||
@@ -18,13 +18,10 @@ type initialLoadingData = {
|
||||
|
||||
type RestoreCallback = (newState: RestorePoint) => Promise<void>;
|
||||
|
||||
export const timeSkipLimit = 3 * 32;
|
||||
|
||||
export class TimerService {
|
||||
private readonly _interval: NodeJS.Timer;
|
||||
private _updateInterval: number;
|
||||
private _lastUpdate: number | null;
|
||||
private _skipThreshold: number;
|
||||
|
||||
playback: Playback;
|
||||
timer: TimerState;
|
||||
@@ -43,13 +40,11 @@ export class TimerService {
|
||||
* @param {object} [timerConfig]
|
||||
* @param {number} [timerConfig.refresh]
|
||||
* @param {number} [timerConfig.updateInterval]
|
||||
* @param {number} [timerConfig.skipThreshold]
|
||||
*/
|
||||
constructor(timerConfig: { refresh: number; updateInterval: number; skipThreshold: number }) {
|
||||
constructor(timerConfig: { refresh?: number; updateInterval?: number } = {}) {
|
||||
this._clear();
|
||||
this._interval = setInterval(() => this.update(), timerConfig.refresh);
|
||||
this._updateInterval = timerConfig.updateInterval;
|
||||
this._skipThreshold = timerConfig.skipThreshold;
|
||||
this._interval = setInterval(() => this.update(), timerConfig?.refresh ?? 1000);
|
||||
this._updateInterval = timerConfig?.updateInterval ?? 1000;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -344,6 +339,7 @@ export class TimerService {
|
||||
this.timer.expectedFinish >= this.timer.startedAt
|
||||
? this.timer.expectedFinish
|
||||
: this.timer.expectedFinish + dayInMs,
|
||||
|
||||
clock: this.timer.clock,
|
||||
secondaryTimer: this.timer.secondaryTimer,
|
||||
secondaryTarget: this.secondaryTarget,
|
||||
@@ -409,19 +405,7 @@ export class TimerService {
|
||||
let shouldNotify = false;
|
||||
if (this.playback === Playback.Roll) {
|
||||
shouldNotify = true;
|
||||
if (
|
||||
skippedOutOfEvent(
|
||||
previousTime,
|
||||
this.timer.clock,
|
||||
this.timer.startedAt,
|
||||
this.timer.expectedFinish,
|
||||
this._skipThreshold,
|
||||
)
|
||||
) {
|
||||
PlaybackService.roll();
|
||||
} else {
|
||||
this.updateRoll();
|
||||
}
|
||||
this.updateRoll();
|
||||
} else if (this.timer.startedAt !== null) {
|
||||
// we only update timer if a timer has been started
|
||||
shouldNotify = true;
|
||||
@@ -521,5 +505,4 @@ export class TimerService {
|
||||
}
|
||||
|
||||
// calculate at 30fps, refresh at 1fps
|
||||
// we consider a skip at 3 lost updates
|
||||
export const eventTimer = new TimerService({ refresh: 32, updateInterval: 1000, skipThreshold: 32 * 3 });
|
||||
export const eventTimer = new TimerService({ refresh: 32, updateInterval: 1000 });
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { dayInMs } from 'ontime-utils';
|
||||
import { TimerType } from 'ontime-types';
|
||||
|
||||
import { getCurrent, getExpectedFinish, skippedOutOfEvent } from '../timerUtils.js';
|
||||
import { getCurrent, getExpectedFinish } from '../timerUtils.js';
|
||||
|
||||
describe('getExpectedFinish()', () => {
|
||||
it('is null if we havent started', () => {
|
||||
@@ -354,106 +354,3 @@ describe('getExpectedFinish() and getCurrentTime() combined', () => {
|
||||
expect(current).toBe(8);
|
||||
});
|
||||
});
|
||||
|
||||
describe('skippedOutOfEvent()', () => {
|
||||
const testSkipLimit = 32;
|
||||
it('does not consider an event end as a skip', () => {
|
||||
const startedAt = 1000;
|
||||
const duration = 1000;
|
||||
const expectedFinish = startedAt + duration;
|
||||
const previousTime = expectedFinish - testSkipLimit / 2;
|
||||
|
||||
let clock = previousTime;
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(false);
|
||||
|
||||
clock += testSkipLimit;
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(false);
|
||||
});
|
||||
|
||||
it('allows rolling backwards in an event', () => {
|
||||
const startedAt = 1000;
|
||||
const duration = 1000;
|
||||
const expectedFinish = startedAt + duration;
|
||||
const previousTime = startedAt + testSkipLimit / 2;
|
||||
|
||||
let clock = previousTime;
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(false);
|
||||
|
||||
clock -= testSkipLimit;
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(false);
|
||||
});
|
||||
|
||||
it('accounts for crossing midnight', () => {
|
||||
const startedAt = dayInMs - testSkipLimit;
|
||||
const expectedFinish = 10;
|
||||
const previousTime = dayInMs - 1;
|
||||
|
||||
let clock = previousTime;
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(false);
|
||||
|
||||
clock = testSkipLimit - 2;
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(false);
|
||||
});
|
||||
|
||||
it('allows rolling backwards in an event across midnight', () => {
|
||||
const startedAt = dayInMs - testSkipLimit;
|
||||
const expectedFinish = 10;
|
||||
const previousTime = startedAt + 1;
|
||||
|
||||
let clock = previousTime;
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(false);
|
||||
|
||||
clock -= testSkipLimit;
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(false);
|
||||
});
|
||||
|
||||
it('finds skip forwards out of event', () => {
|
||||
const startedAt = 1000;
|
||||
const duration = 1000;
|
||||
const expectedFinish = startedAt + duration;
|
||||
const previousTime = expectedFinish - testSkipLimit / 2;
|
||||
|
||||
let clock = previousTime;
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(false);
|
||||
|
||||
clock += testSkipLimit + 1;
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(true);
|
||||
});
|
||||
|
||||
it('finds skip backwards out of event', () => {
|
||||
const startedAt = 1000;
|
||||
const duration = 1000;
|
||||
const expectedFinish = startedAt + duration;
|
||||
const previousTime = startedAt + testSkipLimit / 2;
|
||||
|
||||
let clock = previousTime;
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(false);
|
||||
|
||||
clock -= testSkipLimit + 1;
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(true);
|
||||
});
|
||||
|
||||
it('finds skip forwards out of event across midnight', () => {
|
||||
const startedAt = dayInMs - testSkipLimit;
|
||||
const expectedFinish = 10;
|
||||
const previousTime = dayInMs - 3;
|
||||
|
||||
let clock = previousTime;
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(false);
|
||||
|
||||
clock = testSkipLimit - 2;
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(true);
|
||||
});
|
||||
|
||||
it('finds skip backwards out of event across midnight', () => {
|
||||
const startedAt = dayInMs - testSkipLimit;
|
||||
const expectedFinish = 10;
|
||||
const previousTime = startedAt + 1;
|
||||
|
||||
let clock = previousTime;
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(false);
|
||||
|
||||
clock -= testSkipLimit + 1;
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15,8 +15,11 @@ type Action = TimerLifeCycleKey | string;
|
||||
* @class
|
||||
*/
|
||||
export class HttpIntegration implements IIntegration<HttpSubscriptionOptions> {
|
||||
// protected httpAgent: null | http.Agent;
|
||||
subscriptions: HttpSubscription;
|
||||
|
||||
constructor() {
|
||||
// this.httpAgent = null;
|
||||
this.subscriptions = dbModel.http.subscriptions;
|
||||
}
|
||||
|
||||
@@ -27,6 +30,7 @@ export class HttpIntegration implements IIntegration<HttpSubscriptionOptions> {
|
||||
const { subscriptions, enabledOut } = config;
|
||||
|
||||
if (!enabledOut) {
|
||||
// this.httpAgent?.destroy();
|
||||
return {
|
||||
success: false,
|
||||
message: 'HTTP output disabled',
|
||||
@@ -36,6 +40,9 @@ export class HttpIntegration implements IIntegration<HttpSubscriptionOptions> {
|
||||
this.initSubscriptions(subscriptions);
|
||||
|
||||
try {
|
||||
// this allows re-calling the init function during runtime
|
||||
// this.httpAgent?.destroy();
|
||||
// this.httpAgent = new http.Agent({ keepAlive: true, timeout: 2000 });
|
||||
return {
|
||||
success: true,
|
||||
message: `HTTP integration client ready`,
|
||||
@@ -55,6 +62,13 @@ export class HttpIntegration implements IIntegration<HttpSubscriptionOptions> {
|
||||
}
|
||||
|
||||
dispatch(action: Action, state?: object) {
|
||||
// if (!this.httpAgent) {
|
||||
// return {
|
||||
// success: false,
|
||||
// message: 'Client not initialised',
|
||||
// };
|
||||
// }
|
||||
|
||||
if (!action) {
|
||||
return {
|
||||
success: false,
|
||||
@@ -70,7 +84,14 @@ export class HttpIntegration implements IIntegration<HttpSubscriptionOptions> {
|
||||
if (enabled && message) {
|
||||
const parsedMessage = parseTemplateNested(message, state || {});
|
||||
try {
|
||||
const parsedUrl = new URL(parsedMessage);
|
||||
const parsedUrl = new globalThis.URL(parsedMessage);
|
||||
// if (parsedUrl.protocol != 'http:') {
|
||||
// logger.error(LogOrigin.Tx, `HTTP Integration: Only HTTP allowed, got ${parsedUrl.protocol}`);
|
||||
// return {
|
||||
// success: false,
|
||||
// message: `Only HTTP allowed, got ${parsedUrl.protocol}`,
|
||||
// };
|
||||
// }
|
||||
this.emit(parsedUrl);
|
||||
} catch (err) {
|
||||
logger.error(LogOrigin.Tx, `HTTP Integration: ${err}`);
|
||||
@@ -83,7 +104,7 @@ export class HttpIntegration implements IIntegration<HttpSubscriptionOptions> {
|
||||
});
|
||||
}
|
||||
|
||||
async emit(path: URL) {
|
||||
async emit(path: globalThis.URL) {
|
||||
try {
|
||||
await got.get(path, {
|
||||
retry: { limit: 0 },
|
||||
@@ -91,9 +112,24 @@ export class HttpIntegration implements IIntegration<HttpSubscriptionOptions> {
|
||||
} catch (err) {
|
||||
logger.error(LogOrigin.Tx, `HTTP integration: ${err}`);
|
||||
}
|
||||
// http
|
||||
// .get(path, { agent: this.httpAgent }, (res) => {
|
||||
// if (res.statusCode !== 200) {
|
||||
// logger.error(LogOrigin.Tx, `HTTP Error: ${res.statusCode}`);
|
||||
// }
|
||||
// res.resume();
|
||||
// })
|
||||
// .on('error', (err) => {
|
||||
// logger.error(LogOrigin.Tx, `HTTP integration: ${err}`);
|
||||
// });
|
||||
}
|
||||
|
||||
shutdown() {}
|
||||
shutdown() {
|
||||
// if (this.httpAgent) {
|
||||
// this.httpAgent?.destroy();
|
||||
// this.httpAgent = null;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
export const httpIntegration = new HttpIntegration();
|
||||
|
||||
@@ -64,20 +64,3 @@ export function getCurrent(
|
||||
}
|
||||
return startedAt + duration + addedTime + pausedTime - clock;
|
||||
}
|
||||
|
||||
export function skippedOutOfEvent(
|
||||
previousTime: number,
|
||||
clock: number,
|
||||
startedAt: number,
|
||||
expectedFinish: number,
|
||||
skipLimit: number,
|
||||
): boolean {
|
||||
const hasPassedMidnight = previousTime > dayInMs - skipLimit && clock < skipLimit;
|
||||
const adjustedClock = hasPassedMidnight ? clock + dayInMs : clock;
|
||||
|
||||
const timeDifference = previousTime - adjustedClock;
|
||||
const hasSkipped = Math.abs(timeDifference) > skipLimit;
|
||||
const adjustedExpectedFinish = expectedFinish >= startedAt ? expectedFinish : expectedFinish + dayInMs;
|
||||
|
||||
return hasSkipped && (adjustedClock > adjustedExpectedFinish || adjustedClock < startedAt);
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
import { coerceColour } from '../coerceType.js';
|
||||
|
||||
describe('parses a colour string that is', () => {
|
||||
it('valid hex', () => {
|
||||
const color = coerceColour('#000');
|
||||
expect(color).toBe('#000');
|
||||
});
|
||||
it('valid name', () => {
|
||||
const color = coerceColour('darkgoldenrod');
|
||||
expect(color).toBe('darkgoldenrod');
|
||||
});
|
||||
it('invalid hex', () => {
|
||||
expect(() => coerceColour('#not a hex color')).toThrowError(Error('Invalid hex colour received'));
|
||||
});
|
||||
it('invalid name', () => {
|
||||
expect(() => coerceColour('bad name')).toThrowError(Error('Invalid colour name received'));
|
||||
});
|
||||
it('not a string', () => {
|
||||
expect(() => coerceColour(5)).toThrowError(Error('Invalid colour value received'));
|
||||
});
|
||||
});
|
||||
@@ -93,10 +93,10 @@ describe('validateHttpSubscriptionCycle()', () => {
|
||||
});
|
||||
it('should return true when given an HttpSubscription matches definition', () => {
|
||||
const validHttp = [{ message: 'http://', enabled: true }];
|
||||
const invalidHttps = [{ message: 'https://', enabled: true }];
|
||||
const validHttps = [{ message: 'https://', enabled: true }];
|
||||
|
||||
expect(validateHttpSubscriptionCycle(validHttp)).toBe(true);
|
||||
expect(validateHttpSubscriptionCycle(invalidHttps)).toBe(false);
|
||||
expect(validateHttpSubscriptionCycle(validHttps)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import { isColourHex } from 'ontime-utils';
|
||||
|
||||
//TODO: write tests
|
||||
/**
|
||||
* @description Converts a value to a string if possible, throws otherwise
|
||||
* @description Converts a value to a number if possible, throws otherwise
|
||||
* @param {unknown} value - Value to be converted to a string.
|
||||
* @returns {string} - The converted value as a string.
|
||||
* @throws {Error} Throws an error if the value is null or undefined.
|
||||
@@ -14,9 +11,8 @@ export function coerceString(value: unknown): string {
|
||||
return String(value);
|
||||
}
|
||||
|
||||
//TODO: write tests
|
||||
/**
|
||||
* @description Converts a value to a boolean if possible, throws otherwise
|
||||
* @description Converts a value to a number if possible, throws otherwise
|
||||
* @param {unknown} value - Value to be converted to a boolean.
|
||||
* @returns {boolean} - The converted value as a boolean.
|
||||
* @throws {Error} Throws an error if the value is null or undefined.
|
||||
@@ -25,26 +21,9 @@ export function coerceBoolean(value: unknown): boolean {
|
||||
if (value == null) {
|
||||
throw new Error('Invalid value received');
|
||||
}
|
||||
if (typeof value === 'string') {
|
||||
const lowerCaseValue = value.toLocaleLowerCase();
|
||||
switch (lowerCaseValue) {
|
||||
case 'true':
|
||||
case '1':
|
||||
case 'yes':
|
||||
return true;
|
||||
case 'false':
|
||||
case '0':
|
||||
case 'no':
|
||||
case '':
|
||||
return false;
|
||||
default:
|
||||
throw new Error('Invalid value received');
|
||||
}
|
||||
}
|
||||
return Boolean(value);
|
||||
}
|
||||
|
||||
//TODO: write tests
|
||||
/**
|
||||
* @description Converts a value to a number if possible, throws otherwise
|
||||
* @param {unknown} value - Value to be converted to a number.
|
||||
@@ -61,176 +40,3 @@ export function coerceNumber(value: unknown): number {
|
||||
}
|
||||
return parsedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Converts a value to a colour if possible, throws otherwise
|
||||
* @param {unknown} value - Value to be converted to a colour.
|
||||
* @returns {string} - The converted value as a string.
|
||||
* @throws {Error} Throws an error if the value is null or undefined.
|
||||
*/
|
||||
export function coerceColour(value: unknown): string {
|
||||
if (typeof value !== 'string') {
|
||||
throw new Error('Invalid colour value received');
|
||||
}
|
||||
const lowerCaseValue = value.toLocaleLowerCase();
|
||||
if (lowerCaseValue.startsWith('#')) {
|
||||
if (!isColourHex(lowerCaseValue)) {
|
||||
throw new Error('Invalid hex colour received');
|
||||
}
|
||||
} else if (!(lowerCaseValue in cssColours)) {
|
||||
throw new Error('Invalid colour name received');
|
||||
}
|
||||
return lowerCaseValue;
|
||||
}
|
||||
|
||||
//https://developer.mozilla.org/en-US/docs/Web/CSS/named-color
|
||||
const cssColours = {
|
||||
aliceblue: '#f0f8ff',
|
||||
antiquewhite: '#faebd7',
|
||||
aqua: '#00ffff',
|
||||
aquamarine: '#7fffd4',
|
||||
azure: '#f0ffff',
|
||||
beige: '#f5f5dc',
|
||||
bisque: '#ffe4c4',
|
||||
black: '#000000',
|
||||
blanchedalmond: '#ffebcd',
|
||||
blue: '#0000ff',
|
||||
blueviolet: '#8a2be2',
|
||||
brown: '#a52a2a',
|
||||
burlywood: '#deb887',
|
||||
cadetblue: '#5f9ea0',
|
||||
chartreuse: '#7fff00',
|
||||
chocolate: '#d2691e',
|
||||
coral: '#ff7f50',
|
||||
cornflowerblue: '#6495ed',
|
||||
cornsilk: '#fff8dc',
|
||||
crimson: '#dc143c',
|
||||
cyan: '#00ffff',
|
||||
darkblue: '#00008b',
|
||||
darkcyan: '#008b8b',
|
||||
darkgoldenrod: '#b8860b',
|
||||
darkgray: '#a9a9a9',
|
||||
darkgreen: '#006400',
|
||||
darkgrey: '#a9a9a9',
|
||||
darkkhaki: '#bdb76b',
|
||||
darkmagenta: '#8b008b',
|
||||
darkolivegreen: '#556b2f',
|
||||
darkorange: '#ff8c00',
|
||||
darkorchid: '#9932cc',
|
||||
darkred: '#8b0000',
|
||||
darksalmon: '#e9967a',
|
||||
darkseagreen: '#8fbc8f',
|
||||
darkslateblue: '#483d8b',
|
||||
darkslategray: '#2f4f4f',
|
||||
darkslategrey: '#2f4f4f',
|
||||
darkturquoise: '#00ced1',
|
||||
darkviolet: '#9400d3',
|
||||
deeppink: '#ff1493',
|
||||
deepskyblue: '#00bfff',
|
||||
dimgray: '#696969',
|
||||
dimgrey: '#696969',
|
||||
dodgerblue: '#1e90ff',
|
||||
firebrick: '#b22222',
|
||||
floralwhite: '#fffaf0',
|
||||
forestgreen: '#228b22',
|
||||
fuchsia: '#ff00ff',
|
||||
gainsboro: '#dcdcdc',
|
||||
ghostwhite: '#f8f8ff',
|
||||
goldenrod: '#daa520',
|
||||
gold: '#ffd700',
|
||||
gray: '#808080',
|
||||
green: '#008000',
|
||||
greenyellow: '#adff2f',
|
||||
grey: '#808080',
|
||||
honeydew: '#f0fff0',
|
||||
hotpink: '#ff69b4',
|
||||
indianred: '#cd5c5c',
|
||||
indigo: '#4b0082',
|
||||
ivory: '#fffff0',
|
||||
khaki: '#f0e68c',
|
||||
lavenderblush: '#fff0f5',
|
||||
lavender: '#e6e6fa',
|
||||
lawngreen: '#7cfc00',
|
||||
lemonchiffon: '#fffacd',
|
||||
lightblue: '#add8e6',
|
||||
lightcoral: '#f08080',
|
||||
lightcyan: '#e0ffff',
|
||||
lightgoldenrodyellow: '#fafad2',
|
||||
lightgray: '#d3d3d3',
|
||||
lightgreen: '#90ee90',
|
||||
lightgrey: '#d3d3d3',
|
||||
lightpink: '#ffb6c1',
|
||||
lightsalmon: '#ffa07a',
|
||||
lightseagreen: '#20b2aa',
|
||||
lightskyblue: '#87cefa',
|
||||
lightslategray: '#778899',
|
||||
lightslategrey: '#778899',
|
||||
lightsteelblue: '#b0c4de',
|
||||
lightyellow: '#ffffe0',
|
||||
lime: '#00ff00',
|
||||
limegreen: '#32cd32',
|
||||
linen: '#faf0e6',
|
||||
magenta: '#ff00ff',
|
||||
maroon: '#800000',
|
||||
mediumaquamarine: '#66cdaa',
|
||||
mediumblue: '#0000cd',
|
||||
mediumorchid: '#ba55d3',
|
||||
mediumpurple: '#9370db',
|
||||
mediumseagreen: '#3cb371',
|
||||
mediumslateblue: '#7b68ee',
|
||||
mediumspringgreen: '#00fa9a',
|
||||
mediumturquoise: '#48d1cc',
|
||||
mediumvioletred: '#c71585',
|
||||
midnightblue: '#191970',
|
||||
mintcream: '#f5fffa',
|
||||
mistyrose: '#ffe4e1',
|
||||
moccasin: '#ffe4b5',
|
||||
navajowhite: '#ffdead',
|
||||
navy: '#000080',
|
||||
oldlace: '#fdf5e6',
|
||||
olive: '#808000',
|
||||
olivedrab: '#6b8e23',
|
||||
orange: '#ffa500',
|
||||
orangered: '#ff4500',
|
||||
orchid: '#da70d6',
|
||||
palegoldenrod: '#eee8aa',
|
||||
palegreen: '#98fb98',
|
||||
paleturquoise: '#afeeee',
|
||||
palevioletred: '#db7093',
|
||||
papayawhip: '#ffefd5',
|
||||
peachpuff: '#ffdab9',
|
||||
peru: '#cd853f',
|
||||
pink: '#ffc0cb',
|
||||
plum: '#dda0dd',
|
||||
powderblue: '#b0e0e6',
|
||||
purple: '#800080',
|
||||
rebeccapurple: '#663399',
|
||||
red: '#ff0000',
|
||||
rosybrown: '#bc8f8f',
|
||||
royalblue: '#4169e1',
|
||||
saddlebrown: '#8b4513',
|
||||
salmon: '#fa8072',
|
||||
sandybrown: '#f4a460',
|
||||
seagreen: '#2e8b57',
|
||||
seashell: '#fff5ee',
|
||||
sienna: '#a0522d',
|
||||
silver: '#c0c0c0',
|
||||
skyblue: '#87ceeb',
|
||||
slateblue: '#6a5acd',
|
||||
slategray: '#708090',
|
||||
slategrey: '#708090',
|
||||
snow: '#fffafa',
|
||||
springgreen: '#00ff7f',
|
||||
steelblue: '#4682b4',
|
||||
tan: '#d2b48c',
|
||||
teal: '#008080',
|
||||
thistle: '#d8bfd8',
|
||||
tomato: '#ff6347',
|
||||
turquoise: '#40e0d0',
|
||||
violet: '#ee82ee',
|
||||
wheat: '#f5deb3',
|
||||
white: '#ffffff',
|
||||
whitesmoke: '#f5f5f5',
|
||||
yellow: '#ffff00',
|
||||
yellowgreen: '#9acd3',
|
||||
} as const;
|
||||
|
||||
@@ -227,7 +227,8 @@ export const parseOsc = (data: { osc?: Partial<OSCSettings> }): OSCSettings => {
|
||||
*/
|
||||
export const validateHttpSubscriptionCycle = (data: HttpSubscriptionOptions[]): boolean => {
|
||||
for (const subscriptionOption of data) {
|
||||
const isHttp = subscriptionOption.message?.startsWith('http://');
|
||||
const isHttp =
|
||||
subscriptionOption.message?.startsWith('http://') || subscriptionOption.message?.startsWith('https://');
|
||||
if (typeof subscriptionOption.message !== 'string' || !isHttp || typeof subscriptionOption.enabled !== 'boolean') {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@
|
||||
"user9": "",
|
||||
"type": "event",
|
||||
"revision": 0,
|
||||
"cue": "1",
|
||||
"id": "aa42f"
|
||||
"id": "aa42f",
|
||||
"cue": "1"
|
||||
},
|
||||
{
|
||||
"title": "title 2",
|
||||
@@ -57,8 +57,8 @@
|
||||
"user9": "",
|
||||
"type": "event",
|
||||
"revision": 0,
|
||||
"cue": "2",
|
||||
"id": "d71bc"
|
||||
"id": "d71bc",
|
||||
"cue": "2"
|
||||
},
|
||||
{
|
||||
"title": "title 3",
|
||||
@@ -85,8 +85,8 @@
|
||||
"user9": "",
|
||||
"type": "event",
|
||||
"revision": 0,
|
||||
"cue": "3",
|
||||
"id": "da5b4"
|
||||
"id": "da5b4",
|
||||
"cue": "3"
|
||||
}
|
||||
],
|
||||
"project": {
|
||||
@@ -99,7 +99,7 @@
|
||||
},
|
||||
"settings": {
|
||||
"app": "ontime",
|
||||
"version": "2.24.8",
|
||||
"version": "2.0.0",
|
||||
"serverPort": 4001,
|
||||
"editorKey": null,
|
||||
"operatorKey": null,
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"name": "ontime",
|
||||
"version": "2.24.8",
|
||||
"version": "2.21.3",
|
||||
"description": "Time keeping for live events",
|
||||
"keywords": [
|
||||
"lightdev",
|
||||
"lighdev",
|
||||
"ontime",
|
||||
"timer",
|
||||
"rundown"
|
||||
|
||||
@@ -15,7 +15,6 @@ export { formatDisplay } from './src/date-utils/formatDisplay.js';
|
||||
export { formatFromMillis } from './src/date-utils/formatFromMillis.js';
|
||||
export { isTimeString } from './src/date-utils/isTimeString.js';
|
||||
export { millisToString } from './src/date-utils/millisToString.js';
|
||||
export { isColourHex } from './src/regex-utils/isColourHex.js';
|
||||
|
||||
// time utils
|
||||
export { dayInMs, mts } from './src/timeConstants.js';
|
||||
|
||||
@@ -28,6 +28,5 @@
|
||||
"prettier": "^3.0.3",
|
||||
"typescript": "^5.2.2",
|
||||
"vitest": "^0.30.1"
|
||||
},
|
||||
"sideEffects": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
import { isColourHex } from './isColourHex';
|
||||
|
||||
describe('test isColourHex() function', () => {
|
||||
it('it validates colour hex strings', () => {
|
||||
const ts = ['#FFF', '#FFFF', '#FFFFFF', '#FFFFFFFF'];
|
||||
for (const s of ts) {
|
||||
expect(isColourHex(s)).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it('it validates colour hex strings', () => {
|
||||
const ts = ['#F90', '#1234', '#56789A', '#BCDEF012'];
|
||||
for (const s of ts) {
|
||||
expect(isColourHex(s)).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it('it validates colour hex strings', () => {
|
||||
const ts = ['#f90', '#1234', '#56789a', '#bcdef012'];
|
||||
for (const s of ts) {
|
||||
expect(isColourHex(s)).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it('it fails digits bigger than F', () => {
|
||||
const ts = ['#FFG'];
|
||||
for (const s of ts) {
|
||||
expect(isColourHex(s)).toBe(false);
|
||||
}
|
||||
});
|
||||
|
||||
it('it fails incorect amout of digits', () => {
|
||||
const ts = ['#F', '#FF', '#FFFFF', '#FFFFFFF', '#FFFFFFFFF'];
|
||||
for (const s of ts) {
|
||||
expect(isColourHex(s)).toBe(false);
|
||||
}
|
||||
});
|
||||
|
||||
it('it fails missing #', () => {
|
||||
const ts = ['FFF', 'FFFF', 'FFFFFF', 'FFFFFFFF'];
|
||||
for (const s of ts) {
|
||||
expect(isColourHex(s)).toBe(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,10 +0,0 @@
|
||||
/**
|
||||
* @description Validates a colour hex string
|
||||
* @param {string} text - colour hex string "#FFF" | "#FFFF" | "#FFFFFF" | "#FFFFFFFF"
|
||||
* @returns {boolean} string represents time
|
||||
*/
|
||||
export const isColourHex = (text: string): boolean => {
|
||||
const regexS = /^#((?:[a-f\d]{1}){3,4})$/i;
|
||||
const regexD = /^#((?:[a-f\d]{2}){3,4})$/i;
|
||||
return regexS.test(text) || regexD.test(text);
|
||||
};
|
||||
Reference in New Issue
Block a user