filo_caspar/api/io/helper.mjs

24 lines
564 B
JavaScript
Raw Normal View History

2016-04-10 08:37:05 +00:00
export function register(ctx, name, method) {
if (typeof(method) === 'object') {
2016-04-10 08:37:05 +00:00
Object.keys(method).forEach(key => {
register(ctx, [name, key].join('.'), method[key])
})
return
}
ctx.socket.on(name, async (data) => {
2020-12-08 11:09:46 +00:00
if (name.indexOf('list') > 0 || name.indexOf('all') || name.indexOf('total')) {
ctx.log.debug('Got event', name)
} else {
ctx.log.info('Got event', name)
}
2016-04-10 08:37:05 +00:00
try {
await method(ctx, data)
}
catch (error) {
ctx.log.error(error, `Error processing ${name}`)
}
})
}