playlist schedule solution

This commit is contained in:
Evert Prants 2019-01-11 14:56:26 +02:00
parent b8cc526aad
commit f7b9117013
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
4 changed files with 8 additions and 27 deletions

View File

@ -10,13 +10,7 @@ liq.start()
let scheduler = new Scheduler(config.calendar) let scheduler = new Scheduler(config.calendar)
scheduler.startTimers() scheduler.startTimers()
scheduler.runner = function (event) { scheduler.on('event-start', (event) => liq.queue(event.descriptor))
liq.queue(event.descriptor)
}
scheduler.reload = function (calendar) {
liq.sendCommand('schedule.reload').catch((e) => console.error('Failed to reload schedule:', e.message))
}
// User input handler // User input handler
rl.on('line', function (line) { rl.on('line', function (line) {

View File

@ -1,6 +1,7 @@
const fs = require('fs') const fs = require('fs')
const path = require('path') const path = require('path')
const c = require('canvas') const c = require('canvas')
const EventEmitter = require('events').EventEmitter
const config = require(path.join(__dirname, 'config.js')) const config = require(path.join(__dirname, 'config.js'))
const request = require(path.join(__dirname, 'request.js')) const request = require(path.join(__dirname, 'request.js'))
@ -93,26 +94,21 @@ class Drawer {
} }
} }
class Calendar { class Calendar extends EventEmitter {
constructor (conf) { constructor (conf) {
super()
this.events = [] this.events = []
this.config = conf this.config = conf
this.drawer = new Drawer() this.drawer = new Drawer()
this.schedRunner = null
this.schedReload = null
this.started = [] this.started = []
this.timers = { a: null, b: null, c: null } this.timers = { a: null, b: null, c: null }
} }
update () { update () {
this.drawer.draw(this).then(() => { this.drawer.draw(this).then(() => this.emit('reload'))
setTimeout(() => {
this.schedReload && this.schedReload.call(this, this)
}, 1000)
})
} }
startTimers () { startTimers () {
@ -204,18 +200,10 @@ class Calendar {
console.log(`[schedule] Calendar fetched successfully!`) console.log(`[schedule] Calendar fetched successfully!`)
this.events = results.sort(Calendar.sortStartTime) this.events = results.sort(Calendar.sortStartTime)
} this.emit('events', this.events)
set runner (runner) {
this.schedRunner = runner
}
set reload (reload) {
this.schedReload = reload
} }
runners () { runners () {
if (!this.schedRunner) return
for (let i in this.events) { for (let i in this.events) {
let ev = this.events[i] let ev = this.events[i]
if (!ev.descriptor) continue if (!ev.descriptor) continue
@ -224,7 +212,7 @@ class Calendar {
console.log(`[schedule] Starting event ${ev.eventName}..`) console.log(`[schedule] Starting event ${ev.eventName}..`)
this.started.push(ev.id) this.started.push(ev.id)
this.schedRunner.call(this, ev) this.emit('event-start', ev)
} }
} }
} }

View File

@ -1 +1 @@
annotate:width=300,height=400,x=900,y=80:schedule.png annotate:width=300,height=400,x=900,y=80,duration=120.:schedule.png

View File

@ -17,7 +17,6 @@ video_no_queue = single(confstr("liquidsoap.fallback",""), conservative=true)
image_schedule = playlist("schedule.pls",reload_mode="watch") image_schedule = playlist("schedule.pls",reload_mode="watch")
image_schedule = mux_audio(audio=blank(),image_schedule) image_schedule = mux_audio(audio=blank(),image_schedule)
add_skip_command(command="schedule.reload", image_schedule)
video_base = add([video_no_queue,image_schedule]) video_base = add([video_no_queue,image_schedule])