Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add relevantBlock function #1100

Merged
merged 26 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a377e92
add relevantBlock function and test
alex-Arc Jun 23, 2024
e1c3f2a
rename to getRelevantBlock
alex-Arc Jun 23, 2024
4bc6b4c
use OntimeRundown not Normalized
alex-Arc Jun 23, 2024
b54589d
add block now to runtime state
alex-Arc Jun 23, 2024
4408690
filter in cusheet with currentBlockId
alex-Arc Jun 23, 2024
a173c27
do in only 1 iteration
alex-Arc Jun 25, 2024
9852190
fix test
alex-Arc Jun 25, 2024
6f47f33
Merge remote-tracking branch 'org/master' into relevantBlock
alex-Arc Jun 25, 2024
62cf573
0 index case
alex-Arc Jun 25, 2024
9df62dc
create block state object
alex-Arc Jun 29, 2024
e36aa4b
Merge branch 'master' into relevantBlock
alex-Arc Jul 11, 2024
83098ef
rename to currentBlock
alex-Arc Jul 17, 2024
1317e95
Merge branch 'master' into relevantBlock
alex-Arc Jul 17, 2024
92580d8
slight rename
alex-Arc Jul 17, 2024
1aaa07b
rename to CurrentBlockState
alex-Arc Jul 17, 2024
a6b6657
remove console.log
alex-Arc Jul 17, 2024
d9a139e
typo
alex-Arc Jul 17, 2024
dd5ec5f
Merge branch 'master' into relevantBlock
alex-Arc Jul 19, 2024
3cb3093
unused import
alex-Arc Jul 19, 2024
d0db8f3
lost in Merge
alex-Arc Jul 19, 2024
8c95019
filter events
alex-Arc Jul 19, 2024
75fc00d
pass full rundown to functions and use filter utils
alex-Arc Jul 19, 2024
84beba1
Merge branch 'master' into relevantBlock
alex-Arc Jul 22, 2024
0c51f2f
save to previousState to avoid constant update
alex-Arc Jul 22, 2024
b0385e4
in the same block keep the startedAt time
alex-Arc Jul 22, 2024
61a7d10
null chaining
alex-Arc Jul 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/client/src/common/hooks/useSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export const setAuxTimer = {
export const useCuesheet = () => {
const featureSelector = (state: RuntimeStore) => ({
playback: state.timer.playback,
currentBlockId: state.blockState.block?.id ?? null,
selectedEventId: state.eventNow?.id ?? null,
selectedEventIndex: state.runtime.selectedEventIndex,
numEvents: state.runtime.numEvents,
Expand Down
4 changes: 4 additions & 0 deletions apps/client/src/common/stores/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export const runtimeStorePlaceholder: RuntimeStore = {
actualStart: null,
expectedEnd: null,
},
blockState: {
alex-Arc marked this conversation as resolved.
Show resolved Hide resolved
block: null,
startedAt: null,
},
eventNow: null,
eventNext: null,
publicEventNow: null,
Expand Down
6 changes: 6 additions & 0 deletions apps/client/src/common/utils/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ export const connectSocket = () => {
updateDevTools({ eventNow: payload });
break;
}
case 'ontime-blockState': {
console.log(payload)
alex-Arc marked this conversation as resolved.
Show resolved Hide resolved
patchRuntime('blockState', payload);
updateDevTools({ blockState: payload });
break;
}
case 'ontime-publicEventNow': {
patchRuntime('publicEventNow', payload);
updateDevTools({ publicEventNow: payload });
Expand Down
15 changes: 9 additions & 6 deletions apps/client/src/features/cuesheet/Cuesheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ interface CuesheetProps {
columns: ColumnDef<OntimeRundownEntry>[];
handleUpdate: (rowIndex: number, accessor: keyof OntimeRundownEntry, payload: unknown) => void;
selectedId: string | null;
currentBlockId: string | null;
}

export default function Cuesheet({ data, columns, handleUpdate, selectedId }: CuesheetProps) {
export default function Cuesheet({ data, columns, handleUpdate, selectedId, currentBlockId }: CuesheetProps) {
const { followSelected, showSettings, showDelayBlock, showPrevious, showIndexColumn } = useCuesheetSettings();

const {
columnVisibility,
columnOrder,
Expand Down Expand Up @@ -91,6 +91,7 @@ export default function Cuesheet({ data, columns, handleUpdate, selectedId }: Cu

let eventIndex = 0;
let isPast = Boolean(selectedId);
console.log(currentBlockId);

return (
<>
Expand All @@ -114,11 +115,16 @@ export default function Cuesheet({ data, columns, handleUpdate, selectedId }: Cu
}

if (isOntimeBlock(row.original)) {
if (isPast && !showPrevious && key !== currentBlockId) {
return null;
}
return <BlockRow key={key} title={row.original.title} />;
}
if (isOntimeDelay(row.original)) {
if (isPast && !showPrevious) {
return null;
}
const delayVal = row.original.duration;

if (!showDelayBlock || delayVal === 0) {
return null;
}
Expand All @@ -128,9 +134,6 @@ export default function Cuesheet({ data, columns, handleUpdate, selectedId }: Cu
if (isOntimeEvent(row.original)) {
eventIndex++;
const isSelected = key === selectedId;
if (isSelected) {
isPast = false;
}

if (isPast && !showPrevious) {
return null;
Expand Down
1 change: 1 addition & 0 deletions apps/client/src/features/cuesheet/CuesheetWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export default function CuesheetWrapper() {
columns={columns}
handleUpdate={handleUpdate}
selectedId={featureData.selectedEventId}
currentBlockId={featureData.currentBlockId}
/>
</div>
);
Expand Down
4 changes: 4 additions & 0 deletions apps/server/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ export const startServer = async (
message: messageService.getState(),
runtime: state.runtime,
eventNow: state.eventNow,
blockState: {
block: null,
startedAt: null,
},
publicEventNow: state.publicEventNow,
eventNext: state.eventNext,
publicEventNext: state.publicEventNext,
Expand Down
6 changes: 3 additions & 3 deletions apps/server/src/services/TimerService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OntimeEvent } from 'ontime-types';
import { OntimeEvent, OntimeRundown } from 'ontime-types';

import * as runtimeState from '../stores/runtimeState.js';
import type { UpdateResult } from '../stores/runtimeState.js';
Expand Down Expand Up @@ -96,8 +96,8 @@ export class TimerService {
* Loads roll information into timer service
* @param {OntimeEvent[]} rundown -- list of events to run
*/
roll(rundown: OntimeEvent[]) {
runtimeState.roll(rundown);
roll(playableEvents: OntimeEvent[], rundown: OntimeRundown) {
alex-Arc marked this conversation as resolved.
Show resolved Hide resolved
runtimeState.roll(playableEvents, rundown);
}

shutdown() {
Expand Down
27 changes: 19 additions & 8 deletions apps/server/src/services/runtime-service/RuntimeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
getNextEventWithCue,
getEventWithId,
getPlayableEvents,
getRundown,
} from '../rundown-service/rundownUtils.js';
import { integrationService } from '../integration-service/IntegrationService.js';
import { getForceUpdate, getShouldClockUpdate, getShouldTimerUpdate } from './rundownService.utils.js';
Expand Down Expand Up @@ -100,8 +101,9 @@ class RuntimeService {

if (shouldCallRoll) {
// we dont call this.roll because we need to bypass the checks
const rundown = getPlayableEvents();
this.eventTimer.roll(rundown);
const playableEvents = getPlayableEvents();
const rundown = getRundown();
this.eventTimer.roll(playableEvents, rundown);
}

const timerPhaseChanged = RuntimeService.previousState.timer?.phase !== newState.timer.phase;
Expand Down Expand Up @@ -233,7 +235,8 @@ class RuntimeService {
if (onlyChangedNow) {
runtimeState.reload(eventNow);
} else {
runtimeState.reloadAll(eventNow, playableEvents);
const rundown = getRundown();
runtimeState.reloadAll(eventNow, playableEvents, rundown);
}
return;
}
Expand All @@ -257,8 +260,9 @@ class RuntimeService {
return false;
}

const timedEvents = getPlayableEvents();
const success = runtimeState.load(event, timedEvents);
const playableEvents = getPlayableEvents();
const rundown = getRundown();
const success = runtimeState.load(event, playableEvents, rundown);

if (success) {
logger.info(LogOrigin.Playback, `Loaded event with ID ${event.id}`);
Expand Down Expand Up @@ -507,7 +511,9 @@ class RuntimeService {
return;
}

this.eventTimer.roll(playableEvents);
const rundown = getRundown();

this.eventTimer.roll(playableEvents, rundown);

const state = runtimeState.getState();
const newState = state.timer.playback;
Expand Down Expand Up @@ -537,8 +543,9 @@ class RuntimeService {
return;
}

const timedEvents = getPlayableEvents();
runtimeState.resume(restorePoint, event, timedEvents);
const playableEvents = getPlayableEvents();
const rundown = getRundown();
runtimeState.resume(restorePoint, event, playableEvents, rundown);
logger.info(LogOrigin.Playback, 'Resuming playback');
}

Expand Down Expand Up @@ -600,6 +607,10 @@ function broadcastResult(_target: any, _propertyKey: string, descriptor: Propert
updateEventIfChanged('eventNext', state);
updateEventIfChanged('publicEventNext', state);

if (!deepEqual(RuntimeService?.previousState.blockState, state.blockState)) {
eventStore.set('blockState', state.blockState);
}

if (shouldUpdateClock) {
RuntimeService.previousClockUpdate = state.clock;
eventStore.set('clock', state.clock);
Expand Down
9 changes: 6 additions & 3 deletions apps/server/src/stores/__tests__/runtimeState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ describe('mutation on runtimeState', () => {
});
test('normal playback cycle', () => {
// 1. Load event
load(mockEvent, [mockEvent]);
load(mockEvent, [mockEvent], [mockEvent]);
let newState = getState();
expect(newState.eventNow?.id).toBe(mockEvent.id);
expect(newState.timer.playback).toBe(Playback.Armed);
expect(newState.clock).not.toBe(666);
expect(newState.blockState.block).toBeNull();

// 2. Start event
let success = start();
Expand Down Expand Up @@ -163,11 +164,12 @@ describe('mutation on runtimeState', () => {
initRundown([event1, event2], {});
test('runtime offset', () => {
// 1. Load event
load(event1, [event1, event2]);
load(event1, [event1, event2], [event1, event2]);
let newState = getState();
expect(newState.runtime.actualStart).toBeNull();
expect(newState.runtime.plannedStart).toBe(0);
expect(newState.runtime.plannedEnd).toBe(1500);
expect(newState.blockState.block).toBeNull();

// 2. Start event
start();
Expand All @@ -182,7 +184,7 @@ describe('mutation on runtimeState', () => {
expect(newState.runtime.expectedEnd).toBe(event2.timeEnd - newState.runtime.offset);

// 3. Next event
load(event2, [event1, event2]);
load(event2, [event1, event2], [event1, event2]);
start();

newState = getState();
Expand All @@ -199,6 +201,7 @@ describe('mutation on runtimeState', () => {
expect(newState.runtime.offset).toBe(delayBefore);
// finish is the difference between the runtime and the schedule
expect(newState.runtime.expectedEnd).toBe(event2.timeEnd - newState.runtime.offset);
expect(newState.blockState.block).toBeNull();

// 4. Add time
addTime(10);
Expand Down
Loading