diff --git a/lib/base.js b/lib/base.js index 5475e13..f4d88c6 100644 --- a/lib/base.js +++ b/lib/base.js @@ -47,13 +47,17 @@ class Brid { return this.findMethod({method, direction: false, channel: 'external', meta}); } - registerMethod({method, channel, fn, meta}) { - this.log('info', {in: 'base.registerMethod', description: `register method: ${channel}.${method}`, method, channel, meta}); + callRegisteredMethod(fn, ctx, ...args) { + return fn.call(ctx, ...args); + } + + registerMethod({method, channel, fn, meta: metaOld}) { + this.log('info', {in: 'base.registerMethod', description: `register method: ${channel}.${method}`, method, channel, meta: metaOld}); !this.apiMethods[channel] && (this.apiMethods[channel] = {}); this.apiMethods[channel][method] = async(ctx, ...args) => { let [message, meta] = args; this.log('trace', {in: 'base.registerMethod', description: `exec method: ${channel}.${method}`, message, meta}); - return fn.call(ctx, ...args); + return this.callRegisteredMethod(fn, ctx, message, {...metaOld, ...meta, channel, method}); }; }