Skip to content

Commit 399c3af

Browse files
fix: handle future rounds of broadcasts
1 parent 3d1110c commit 399c3af

2 files changed

Lines changed: 40 additions & 4 deletions

File tree

src/components/Analysis/BroadcastGameList.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ export const BroadcastGameList: React.FC<BroadcastGameListProps> = ({
121121
<p className="text-xs text-secondary">
122122
{broadcastController.broadcastState.isConnecting
123123
? 'Loading games...'
124-
: 'No games available'}
124+
: broadcastController.currentRound?.ongoing
125+
? 'No games available'
126+
: 'Round not started yet'}
125127
</p>
126128
</div>
127129
</div>

src/hooks/useBroadcastController.ts

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -587,15 +587,49 @@ export const useBroadcastController = (): BroadcastStreamController => {
587587
error: null,
588588
}))
589589

590+
// Set up a timeout to handle rounds with no data (future rounds)
591+
const timeoutId = setTimeout(() => {
592+
console.log(
593+
'Stream timeout - no data received, likely future/empty round',
594+
)
595+
if (abortController.current && currentRoundId.current === roundId) {
596+
// Set empty round data instead of staying in connecting state
597+
setRoundData({
598+
roundId: roundId,
599+
broadcastId: currentBroadcast?.tour.id || '',
600+
games: new Map(),
601+
lastUpdate: Date.now(),
602+
})
603+
604+
setBroadcastState({
605+
isConnected: true,
606+
isConnecting: false,
607+
isLive: false,
608+
error: null,
609+
roundStarted: true,
610+
roundEnded: false,
611+
gameEnded: false,
612+
})
613+
}
614+
}, 5000) // 5 second timeout
615+
590616
try {
591617
// Start streaming - this will send all games initially, then updates
592618
await streamBroadcastRound(
593619
roundId,
594-
handlePGNUpdate,
595-
handleStreamComplete,
620+
(pgnData) => {
621+
// Clear timeout if we receive data
622+
clearTimeout(timeoutId)
623+
handlePGNUpdate(pgnData)
624+
},
625+
() => {
626+
clearTimeout(timeoutId)
627+
handleStreamComplete()
628+
},
596629
abortController.current.signal,
597630
)
598631
} catch (error) {
632+
clearTimeout(timeoutId)
599633
console.error('Round stream error:', error)
600634

601635
const errorMessage =
@@ -614,7 +648,7 @@ export const useBroadcastController = (): BroadcastStreamController => {
614648
abortController.current = null
615649
}
616650
},
617-
[handlePGNUpdate, handleStreamComplete],
651+
[handlePGNUpdate, handleStreamComplete, currentBroadcast],
618652
)
619653

620654
const reconnect = useCallback(() => {

0 commit comments

Comments
 (0)