File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -47,8 +47,13 @@ export function createRadioRouter() {
4747 res . setHeader ( "Content-Type" , "text/event-stream" ) ;
4848 res . setHeader ( "Cache-Control" , "no-cache, no-transform" ) ;
4949 res . setHeader ( "Connection" , "keep-alive" ) ;
50+ res . setHeader ( "X-Accel-Buffering" , "no" ) ;
5051 res . flushHeaders ?.( ) ;
5152 addRadioClient ( tenantId , res ) ;
53+ const heartbeat = setInterval ( ( ) => {
54+ res . write ( ": heartbeat\n\n" ) ;
55+ } , 25_000 ) ;
56+ res . on ( "close" , ( ) => clearInterval ( heartbeat ) ) ;
5257 const state = await getRadioState ( { tenantId : baseTenantId , station } ) ;
5358 res . write ( `event: state\n` ) ;
5459 res . write ( `data: ${ JSON . stringify ( state ) } \n\n` ) ;
Original file line number Diff line number Diff line change @@ -369,6 +369,16 @@ export async function getRadioState({
369369} ) {
370370 const normalizedTenantId = resolvedTenantId ( tenantId ) ;
371371 const session = await ensureRadioSession ( normalizedTenantId , station ) ;
372+ const startedAtMs = session . startedAt ?. getTime ( ) ?? 0 ;
373+ if (
374+ session . currentTrackId &&
375+ startedAtMs > 0 &&
376+ Date . now ( ) >= startedAtMs + session . durationSeconds * 1000
377+ ) {
378+ await advanceRadioIfNeeded ( normalizedTenantId , false , station ) ;
379+ const advancedSession = await ensureRadioSession ( normalizedTenantId , station ) ;
380+ return presentRadioState ( advancedSession , actor ) ;
381+ }
372382 return presentRadioState ( session , actor ) ;
373383}
374384
You can’t perform that action at this time.
0 commit comments