church_streamer/api/encoder/routes.mjs

53 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

import encoder from './encoder.mjs'
import { runCommand } from './runner.mjs'
2024-02-13 23:54:45 +00:00
export default class EncoderRoutes {
constructor() {
this.core = null
}
registerGlobalIo(io, server) {
this.core = server.core
encoder.init(server.core, io)
2024-02-13 23:54:45 +00:00
}
registerIo(server, ctx) {
ctx.socket.safeOn('encoder.status', this.status.bind(this))
ctx.socket.safeOn('encoder.stop', this.stop.bind(this))
ctx.socket.safeOn('encoder.start', this.start.bind(this))
ctx.socket.safeOn('encoder.run', this.run.bind(this))
ctx.socket.safeOn('encoder.settings', this.settings.bind(this))
2024-02-13 23:54:45 +00:00
}
status(ctx) {
ctx.socket.emit('encoder.status', encoder.status())
}
stop(ctx) {
encoder.safeStop()
}
start(ctx) {
encoder.safeStart()
}
settings(ctx, data) {
this.core.db.data.encoder_settings = {
device: data.device,
format_code: data.format_code,
command: data.command,
}
this.core.db.write()
}
run(ctx, data) {
return runCommand(data.command, data.arguments, (msg, source) => {
encoder.log('info', msg.replace(/\n/g, ''), 'RUN')
})
.then(
code => encoder.log('info', 'Program returned successfully', 'RUN'),
err => encoder.log('error', err.message, 'RUN')
)
2024-02-13 23:54:45 +00:00
}
}