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), } } }