11import React , { PropsWithChildren } from 'react'
22import { Meteor } from 'meteor/meteor'
3- import * as PropTypes from 'prop-types'
43import { withTracker } from '../../../lib/ReactMeteorData/react-meteor-data'
54import { protectString } from '../../../lib/tempLib'
65import { DBRundownPlaylist } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist'
@@ -21,6 +20,7 @@ import { sortPartInstancesInSortedSegments } from '@sofie-automation/corelib/dis
2120import { RundownUtils } from '../../../lib/rundown'
2221import { RundownPlaylistClientUtil } from '../../../lib/rundownPlaylistUtil'
2322import { getCurrentTime } from '../../../lib/systemTime'
23+ import { IRundownTimingProviderValues , RundownTimingProviderContext } from './withTiming'
2424
2525const TIMING_DEFAULT_REFRESH_INTERVAL = 1000 / 60 // the interval for high-resolution events (timeupdateHR)
2626const LOW_RESOLUTION_TIMING_DECIMATOR = 15
@@ -44,10 +44,7 @@ interface IRundownTimingProviderProps {
4444 /** Fallback duration for Parts that have no as-played duration of their own. */
4545 defaultDuration ?: number
4646}
47- interface IRundownTimingProviderChildContext {
48- durations : RundownTimingContext
49- syncedDurations : RundownTimingContext
50- }
47+
5148interface IRundownTimingProviderState { }
5249interface IRundownTimingProviderTrackedProps {
5350 rundowns : Array < Rundown >
@@ -156,27 +153,28 @@ export const RundownTimingProvider = withTracker<
156153 partsInQuickLoop,
157154 }
158155} ) (
159- class RundownTimingProvider
160- extends React . Component <
161- PropsWithChildren < IRundownTimingProviderProps > & IRundownTimingProviderTrackedProps ,
162- IRundownTimingProviderState
163- >
164- implements React . ChildContextProvider < IRundownTimingProviderChildContext >
165- {
166- static childContextTypes = {
167- durations : PropTypes . object . isRequired ,
168- syncedDurations : PropTypes . object . isRequired ,
169- }
170-
171- durations : RundownTimingContext = {
156+ class RundownTimingProvider extends React . Component <
157+ PropsWithChildren < IRundownTimingProviderProps > & IRundownTimingProviderTrackedProps ,
158+ IRundownTimingProviderState
159+ > {
160+ private durations : RundownTimingContext = {
172161 isLowResolution : false ,
173162 }
174- syncedDurations : RundownTimingContext = {
163+ private syncedDurations : RundownTimingContext = {
175164 isLowResolution : true ,
176165 }
177- refreshTimer : number | undefined
178- refreshTimerInterval : number
179- refreshDecimator : number
166+ /**
167+ * This context works in an unusual way.
168+ * It contains a constant value which gets mutated in place, with the consumer expected to setup a timer to poll for changes.
169+ */
170+ private childContextValue : IRundownTimingProviderValues = {
171+ durations : this . durations ,
172+ syncedDurations : this . syncedDurations ,
173+ }
174+
175+ private refreshTimer : number | undefined
176+ private refreshTimerInterval : number
177+ private refreshDecimator : number
180178
181179 private timingCalculator : RundownTimingCalculator = new RundownTimingCalculator ( )
182180 /** last time (ms rounded down to full seconds) for which the timeupdateSynced event was dispatched */
@@ -190,18 +188,11 @@ export const RundownTimingProvider = withTracker<
190188 this . refreshDecimator = 0
191189 }
192190
193- getChildContext ( ) : IRundownTimingProviderChildContext {
194- return {
195- durations : this . durations ,
196- syncedDurations : this . syncedDurations ,
197- }
198- }
199-
200- calmDownTiming = ( time : number ) => {
191+ private calmDownTiming = ( time : number ) => {
201192 return Math . round ( time / CURRENT_TIME_GRANULARITY ) * CURRENT_TIME_GRANULARITY
202193 }
203194
204- onRefreshTimer = ( ) => {
195+ private onRefreshTimer = ( ) => {
205196 const now = getCurrentTime ( )
206197 const calmedDownNow = this . calmDownTiming ( now )
207198 this . updateDurations ( calmedDownNow , false )
@@ -252,7 +243,7 @@ export const RundownTimingProvider = withTracker<
252243 if ( this . refreshTimer !== undefined ) Meteor . clearInterval ( this . refreshTimer )
253244 }
254245
255- dispatchHREvent ( now : number ) {
246+ private dispatchHREvent ( now : number ) {
256247 const event = new CustomEvent < TimeEventArgs > ( RundownTiming . Events . timeupdateHighResolution , {
257248 detail : {
258249 currentTime : now ,
@@ -262,7 +253,7 @@ export const RundownTimingProvider = withTracker<
262253 window . dispatchEvent ( event )
263254 }
264255
265- dispatchLREvent ( now : number ) {
256+ private dispatchLREvent ( now : number ) {
266257 const event = new CustomEvent < TimeEventArgs > ( RundownTiming . Events . timeupdateLowResolution , {
267258 detail : {
268259 currentTime : now ,
@@ -272,7 +263,7 @@ export const RundownTimingProvider = withTracker<
272263 window . dispatchEvent ( event )
273264 }
274265
275- dispatchSyncedEvent ( now : number ) {
266+ private dispatchSyncedEvent ( now : number ) {
276267 const event = new CustomEvent < TimeEventArgs > ( RundownTiming . Events . timeupdateSynced , {
277268 detail : {
278269 currentTime : now ,
@@ -282,7 +273,7 @@ export const RundownTimingProvider = withTracker<
282273 window . dispatchEvent ( event )
283274 }
284275
285- updateDurations ( now : number , isSynced : boolean ) {
276+ private updateDurations ( now : number , isSynced : boolean ) {
286277 const { playlist, rundowns, currentRundown, partInstances, partInstancesMap, segmentsMap } = this . props
287278
288279 const updatedDurations = this . timingCalculator . updateDurations (
@@ -305,7 +296,11 @@ export const RundownTimingProvider = withTracker<
305296 }
306297
307298 render ( ) : React . ReactNode {
308- return this . props . children
299+ return (
300+ < RundownTimingProviderContext . Provider value = { this . childContextValue } >
301+ { this . props . children }
302+ </ RundownTimingProviderContext . Provider >
303+ )
309304 }
310305 }
311306)
0 commit comments