church_streamer/api/serial/routes.mjs

26 lines
580 B
JavaScript
Raw Normal View History

import serial from './serial.mjs'
export default class SerialRoutes {
registerGlobalIo(io, server) {
serial.init(server.core, io)
}
registerIo(server, ctx) {
ctx.socket.safeOn('serial.status', this.status.bind(this))
ctx.socket.safeOn('serial.restart', this.restart.bind(this))
ctx.socket.safeOn('serial.display', this.display.bind(this))
}
status(ctx) {
ctx.socket.emit('serial.status', serial.status())
}
display(ctx) {
ctx.socket.emit('serial.display', serial.getDisplay())
}
restart(ctx) {
serial.serial.value?.close()
}
}