()
| 471 | } |
| 472 | |
| 473 | function queueNextProgramming() { |
| 474 | if ( logLevel >= 2 ) console.log( "queueNextProgramming()" ); |
| 475 | |
| 476 | clearTimeout( nextProgrammingTimerId ); |
| 477 | |
| 478 | let now = new Date(); |
| 479 | |
| 480 | let secondsUntilNextMinute = ( 60 - now.getSeconds() ); |
| 481 | |
| 482 | if ( programmingQueue.length > 0 ) { |
| 483 | if ( logLevel >= 2 ) console.log( "Choosing from the programming queue:", programmingQueue ); |
| 484 | |
| 485 | let nextProgram = programmingQueue.shift(); |
| 486 | |
| 487 | let nextFileToPlay = nextProgram.src; |
| 488 | let cron = nextProgram.cron; |
| 489 | |
| 490 | saveLastPlay( cron, nextFileToPlay ); |
| 491 | |
| 492 | tv.data( 'cron', cron ); |
| 493 | play( nextFileToPlay ); |
| 494 | |
| 495 | // If this cron pattern matches every minute, this content should end if something else should be run. |
| 496 | if ( cron.indexOf( '* ' ) === 0 ) { |
| 497 | if ( logLevel >= 2 ) console.log( "Wildcard programming is playing; checking for more important content in " + secondsUntilNextMinute + " seconds." ); |
| 498 | |
| 499 | // We could skip setting this timer if the content duration is less than a minute, but |
| 500 | // I think it simplifies the logic if there's always a timer waiting during wildcard programming. |
| 501 | nextProgrammingTimerId = setTimeout( queueNextProgramming, ( secondsUntilNextMinute + 1 ) * 1000 ); |
| 502 | } |
| 503 | |
| 504 | return; |
| 505 | } |
| 506 | |
| 507 | let cronForThisMinute = false; |
| 508 | |
| 509 | for ( cron in programming.schedule ) { |
| 510 | if ( Cron.timeMatchesCron( now, cron ) ) { |
| 511 | if ( cron.indexOf( '* ' ) === 0 && tv.data( 'cron' ) && ! tvElement.ended ) { |
| 512 | if ( logLevel >= 2 ) console.log( "Found matching wildcard cron (" + cron + ") but skipping because something is playing." ); |
| 513 | } else { |
| 514 | if ( logLevel >= 2 ) console.log( "Found matching cron: " + cron, programming.schedule[cron] ); |
| 515 | |
| 516 | cronForThisMinute = cron; |
| 517 | break; |
| 518 | } |
| 519 | } else { |
| 520 | if ( logLevel >= 2 ) console.log( cron + " doesn't match this minute (" + now + ")" ); |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | let nextFileToPlay = false; |
| 525 | |
| 526 | if ( cronForThisMinute ) { |
| 527 | nextFileToPlay = getNextContentFromCron( cron ); |
| 528 | |
| 529 | if ( tv.attr( 'src' ) && nextFileToPlay ) { |
| 530 | if ( tv.attr( 'src' ).indexOf( nextFileToPlay ) == 0 ) { |
no test coverage detected