28 lines
695 B
JavaScript
28 lines
695 B
JavaScript
import { effect } from '@preact/signals-core'
|
|
import serial from '../serial/serial.mjs'
|
|
import encoder from '../encoder/encoder.mjs'
|
|
|
|
export default class HealthRoutes {
|
|
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 {
|
|
serial_running: Boolean(serial.serial.value),
|
|
serial_display: serial.currentDisplay.value,
|
|
encoder_running: Boolean(encoder.encoder.value),
|
|
encoder_starting: Boolean(encoder.attempting.value),
|
|
}
|
|
}
|
|
}
|