filo_caspar/api/io/helper.mjs

20 lines
420 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) => {
2016-04-14 04:01:51 +00:00
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}`)
}
})
}