@@ -70,6 +70,7 @@ const TIME_OF_DAY_SPAN_ID = 'time-of-day'
7070const SEGMENT_DURATION_SPAN_CLASS = 'segment-duration'
7171const SEGMENT_REMAINIG_SPAN_ID = 'segment-remaining'
7272const PART_REMAINIG_SPAN_ID = 'part-remaining'
73+ const T_TIMERS_DIV_ID = 't-timers'
7374const ACTIVE_PIECES_SPAN_ID = 'active-pieces'
7475const NEXT_PIECES_SPAN_ID = 'next-pieces'
7576const SEGMENTS_DIV_ID = 'segments'
@@ -86,6 +87,8 @@ function handleActivePlaylist(data) {
8687 '<ul><li>' +
8788 activePlaylist . nextPart . pieces . map ( ( p ) => `${ p . name } [${ p . tags || [ ] } ]` ) . join ( '</li><li>' ) +
8889 '</li><ul>'
90+
91+ handleTTimers ( data . tTimers )
8992}
9093let activePieces = { }
9194function handleActivePieces ( data ) {
@@ -124,6 +127,7 @@ setInterval(() => {
124127 if ( partEndTime ) partRemainingEl . textContent = formatMillisecondsToTime ( Math . ceil ( partEndTime / 1000 ) * 1000 - now )
125128
126129 updateClock ( )
130+ updateTTimers ( activePlaylist . tTimers )
127131} , 100 )
128132
129133function updateClock ( ) {
@@ -182,3 +186,96 @@ function formatMillisecondsToTime(milliseconds) {
182186
183187 return `${ isNegative ? '+' : '' } ${ formattedHours } :${ formattedMinutes } :${ formattedSeconds } `
184188}
189+
190+ function handleTTimers ( tTimers ) {
191+ const tTimersDiv = document . getElementById ( T_TIMERS_DIV_ID )
192+ if ( ! tTimersDiv || ! tTimers ) return
193+
194+ const ul = document . createElement ( 'ul' )
195+
196+ tTimers . forEach ( ( timer ) => {
197+ const li = document . createElement ( 'li' )
198+ li . id = `t-timer-${ timer . index } `
199+ li . textContent = `Timer ${ timer . index } :`
200+
201+ const detailUl = document . createElement ( 'ul' )
202+
203+ if ( timer . configured ) {
204+ // Type
205+ const typeLi = document . createElement ( 'li' )
206+ typeLi . textContent = `Type: "${ timer . mode . type } "`
207+ detailUl . appendChild ( typeLi )
208+
209+ // Label
210+ const labelLi = document . createElement ( 'li' )
211+ labelLi . textContent = `Label: ${ timer . label ? JSON . stringify ( timer . label ) : '(no label)' } `
212+ detailUl . appendChild ( labelLi )
213+
214+ // Value
215+ const valueLi = document . createElement ( 'li' )
216+ valueLi . appendChild ( document . createTextNode ( 'Value: ' ) )
217+ const valueSpan = document . createElement ( 'span' )
218+ valueSpan . id = `t-timer-value-${ timer . index } `
219+ valueLi . appendChild ( valueSpan )
220+ detailUl . appendChild ( valueLi )
221+
222+ // Projected (if available)
223+ if ( timer . projected && timer . anchorPartId ) {
224+ const projectedLi = document . createElement ( 'li' )
225+ projectedLi . id = `t-timer-projected-${ timer . index } `
226+ detailUl . appendChild ( projectedLi )
227+ }
228+ } else {
229+ // Show "Not set" for unconfigured timers
230+ const notSetLi = document . createElement ( 'li' )
231+ notSetLi . textContent = 'Not set'
232+ detailUl . appendChild ( notSetLi )
233+ }
234+
235+ li . appendChild ( detailUl )
236+ ul . appendChild ( li )
237+ } )
238+
239+ tTimersDiv . innerHTML = ''
240+ tTimersDiv . appendChild ( ul )
241+ }
242+
243+ function updateTTimers ( tTimers ) {
244+ if ( ! tTimers ) return
245+
246+ const now = ENABLE_SYNCED_TICKS ? Math . floor ( Date . now ( ) / 1000 ) * 1000 : Date . now ( )
247+
248+ tTimers . forEach ( ( timer ) => {
249+ if ( ! timer . configured ) return
250+
251+ const valueSpan = document . getElementById ( `t-timer-value-${ timer . index } ` )
252+ if ( ! valueSpan ) return
253+
254+ // Calculate current timer value
255+ let currentTime
256+ if ( timer . state . paused ) {
257+ currentTime = timer . state . duration
258+ } else {
259+ currentTime = timer . state . zeroTime - now
260+ }
261+
262+ valueSpan . textContent = formatMillisecondsToTime ( currentTime )
263+
264+ // Update projected time if available
265+ const projectedLi = document . getElementById ( `t-timer-projected-${ timer . index } ` )
266+ if ( projectedLi && timer . projected ) {
267+ let projectedTime
268+ if ( timer . projected . paused ) {
269+ projectedTime = timer . projected . duration
270+ } else {
271+ projectedTime = timer . projected . zeroTime - now
272+ }
273+
274+ const diff = currentTime - projectedTime
275+ const diffStr = formatMillisecondsToTime ( Math . abs ( diff ) )
276+ const status = diff > 0 ? 'under' : 'over'
277+
278+ projectedLi . textContent = `Projected: ${ formatMillisecondsToTime ( projectedTime ) } (${ diffStr } ${ status } )`
279+ }
280+ } )
281+ }
0 commit comments