church_streamer/api/health/routes.mjs
Jonatan Nilsson 91e7395046
All checks were successful
/ deploy (push) Successful in -2040h37m48s
Automatically refresh app when version updates
2024-02-25 22:01:37 +00:00

33 lines
786 B
JavaScript

import { effect } from '@preact/signals-core'
import serial from '../serial/serial.mjs'
import encoder from '../encoder/encoder.mjs'
export default class HealthRoutes {
constructor(opts = {}) {
Object.assign(this, opts)
}
registerGlobalIo(io, server) {
effect(() => {
io.io.emit('status', this.getStatus())
})
}
registerIo(server, ctx) {
ctx.socket.safeOn('status', this.status.bind(this))
}
status(ctx) {
ctx.socket.emit('status', this.getStatus())
}
getStatus() {
return {
version: this.version,
serial_running: Boolean(serial.serial.value),
serial_display: serial.currentDisplay.value,
encoder_running: Boolean(encoder.encoder.value),
encoder_starting: Boolean(encoder.attempting.value),
}
}
}