Refactor event handling in EventsController and App.vue
This commit is contained in:
parent
69b6953cf8
commit
f5f3376aea
|
@ -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`)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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' })
|
||||
})
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue
Block a user