2024-02-20 04:57:49 +00:00
|
|
|
import { effect } from '@preact/signals-core'
|
|
|
|
import serial from '../serial/serial.mjs'
|
|
|
|
import encoder from '../encoder/encoder.mjs'
|
|
|
|
|
|
|
|
export default class HealthRoutes {
|
2024-02-25 22:01:37 +00:00
|
|
|
constructor(opts = {}) {
|
|
|
|
Object.assign(this, opts)
|
|
|
|
}
|
|
|
|
|
2024-02-20 04:57:49 +00:00
|
|
|
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 {
|
2024-02-25 22:01:37 +00:00
|
|
|
version: this.version,
|
2024-02-20 04:57:49 +00:00
|
|
|
serial_running: Boolean(serial.serial.value),
|
|
|
|
serial_display: serial.currentDisplay.value,
|
|
|
|
encoder_running: Boolean(encoder.encoder.value),
|
|
|
|
encoder_starting: Boolean(encoder.attempting.value),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|