Skip to content

Commit 6ad1bca

Browse files
authored
fix(webui): Use synced time for T-Timers (Sofie-Automation#1771)
1 parent 5fe6213 commit 6ad1bca

5 files changed

Lines changed: 15 additions & 20 deletions

File tree

packages/webui/src/client/ui/ClockView/TTimerDisplay.tsx

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,22 @@ import { calculateTTimerDiff, calculateTTimerOverUnder } from '../../lib/tTimerU
44
import { useTiming } from '../RundownView/RundownTiming/withTiming.js'
55
import { OverUnderChip } from '../../lib/Components/OverUnderChip.js'
66
import { Countdown } from '../RundownView/RundownHeader/Countdown.js'
7+
import { getCurrentTime } from '../../lib/systemTime.js'
78

89
interface TTimerDisplayProps {
910
timer: RundownTTimer
1011
}
1112

1213
export function TTimerDisplay({ timer }: Readonly<TTimerDisplayProps>): JSX.Element | null {
13-
useTiming()
14+
const timing = useTiming()
1415

1516
if (!timer.mode) return null
1617

17-
const now = Date.now()
18+
const now = timing.currentTime ?? getCurrentTime()
1819

1920
const diff = calculateTTimerDiff(timer, now)
2021
const overUnder = calculateTTimerOverUnder(timer, now)
21-
const timeStr = RundownUtils.formatDiffToTimecode(
22-
Math.abs(diff),
23-
false,
24-
true,
25-
true,
26-
false,
27-
true,
28-
undefined,
29-
true,
30-
true
31-
)
22+
const timeStr = RundownUtils.formatDiffToTimecode(Math.abs(diff), false, true, true, false, true)
3223
const timerSign = diff >= 0 ? '' : '-'
3324

3425
return (

packages/webui/src/client/ui/RundownView/RundownHeader/RundownHeaderDurations.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Countdown } from './Countdown'
44
import { useTiming } from '../RundownTiming/withTiming'
55
import { RundownUtils } from '../../../lib/rundown.js'
66
import { PlaylistTiming } from '@sofie-automation/corelib/dist/playout/rundownTiming'
7+
import { getCurrentTime } from '../../../lib/systemTime'
78

89
export function RundownHeaderDurations({
910
playlist,
@@ -21,7 +22,7 @@ export function RundownHeaderDurations({
2122

2223
const estDuration = PlaylistTiming.getRemainingDuration(
2324
playlist.timing,
24-
timingDurations.currentTime ?? Date.now(),
25+
timingDurations.currentTime ?? getCurrentTime(),
2526
timingDurations.remainingPlaylistDuration,
2627
startedPlayback
2728
)

packages/webui/src/client/ui/RundownView/RundownHeader/RundownHeaderExpectedEnd.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { PlaylistTiming } from '@sofie-automation/corelib/dist/playout/rundownTi
33
import { useTranslation } from 'react-i18next'
44
import { Countdown } from './Countdown'
55
import { useTiming } from '../RundownTiming/withTiming'
6+
import { getCurrentTime } from '../../../lib/systemTime'
67

78
export function RundownHeaderExpectedEnd({
89
playlist,
@@ -14,7 +15,7 @@ export function RundownHeaderExpectedEnd({
1415
const { t } = useTranslation()
1516
const timingDurations = useTiming()
1617

17-
const now = timingDurations.currentTime ?? Date.now()
18+
const now = timingDurations.currentTime ?? getCurrentTime()
1819
const expectedEnd = PlaylistTiming.getExpectedEnd(playlist.timing)
1920
const startedPlayback = playlist.activationId ? playlist.startedPlayback : undefined
2021
const estEnd = PlaylistTiming.getEstimatedEnd(

packages/webui/src/client/ui/RundownView/RundownHeader/RundownHeaderPlannedStart.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next'
44
import { Countdown } from './Countdown'
55
import { useTiming } from '../RundownTiming/withTiming'
66
import { RundownUtils } from '../../../lib/rundown.js'
7+
import { getCurrentTime } from '../../../lib/systemTime'
78

89
export function RundownHeaderPlannedStart({
910
playlist,
@@ -16,7 +17,7 @@ export function RundownHeaderPlannedStart({
1617
const timingDurations = useTiming()
1718
const expectedStart = PlaylistTiming.getExpectedStart(playlist.timing)
1819

19-
const now = timingDurations.currentTime ?? Date.now()
20+
const now = timingDurations.currentTime ?? getCurrentTime()
2021
const startsIn = now - (expectedStart ?? 0)
2122
const startedPlayback = playlist.activationId ? playlist.startedPlayback : undefined
2223

packages/webui/src/client/ui/RundownView/RundownHeader/RundownHeaderTimers.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ interface IProps {
1212
}
1313

1414
export const RundownHeaderTimers: React.FC<IProps> = ({ tTimers }) => {
15-
useTiming()
15+
const timing = useTiming()
16+
const now = timing.currentTime ?? getCurrentTime()
1617

1718
const activeTimers = tTimers.filter((t) => t.mode).slice(0, 2)
1819
if (activeTimers.length == 0) return null
@@ -21,7 +22,7 @@ export const RundownHeaderTimers: React.FC<IProps> = ({ tTimers }) => {
2122
<div className="rundown-header__clocks-timers">
2223
{activeTimers.map((timer) => (
2324
<div key={timer.index} className="rundown-header__clocks-timers__row">
24-
<SingleTimer timer={timer} />
25+
<SingleTimer timer={timer} now={now} />
2526
</div>
2627
))}
2728
</div>
@@ -30,10 +31,10 @@ export const RundownHeaderTimers: React.FC<IProps> = ({ tTimers }) => {
3031

3132
interface ISingleTimerProps {
3233
timer: RundownTTimer
34+
now: number
3335
}
3436

35-
function SingleTimer({ timer }: Readonly<ISingleTimerProps>) {
36-
const now = getCurrentTime()
37+
function SingleTimer({ timer, now }: Readonly<ISingleTimerProps>) {
3738
const mode = timer.mode
3839
if (!mode) return null
3940
const isRunning = !!timer.state && !timer.state.paused

0 commit comments

Comments
 (0)