2016-04-10 08:37:05 +00:00
|
|
|
export function register(ctx, name, method) {
|
2020-04-06 22:47:58 +00:00
|
|
|
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}`)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|