Refactor event handling in EventsController and App.vue

This commit is contained in:
Douglas Barone 2024-01-24 15:50:27 -04:00
parent 69b6953cf8
commit f5f3376aea
3 changed files with 5 additions and 5 deletions

View File

@ -36,13 +36,13 @@ export class EventsController {
})
}
static async sendEvent(event: string, data: any = null) {
static async sendEvent(data: any = null) {
this.clients.forEach(client => {
log.info(
new Date().toLocaleString(),
`Sending event ${event} to ${client.id}`
`Sending event message to ${client.id}`
)
client.res.write(`event: ${event}\n`)
client.res.write(`event: message\n`)
client.res.write(`data: ${JSON.stringify(data)}\n\n`)
})
}

View File

@ -23,5 +23,5 @@ export const jobs = new Bree({
jobs.on('worker deleted', name => {
if (name == 'updatePrinterStatus')
EventsController.sendEvent('printerStatusUpdated', { status: 'success' })
EventsController.sendEvent({ status: 'success' })
})

View File

@ -36,8 +36,8 @@ onBeforeMount(async () => {
const events = new EventSource(eventURI)
events.onmessage = async event => {
await appStore.fetchPrinters()
console.log('Event:', event)
await appStore.fetchPrinters()
}
})
</script>