diff --git a/lib/adapter/0_x.js b/lib/adapter/0_x.js index 0d22f8c..ea67d79 100644 --- a/lib/adapter/0_x.js +++ b/lib/adapter/0_x.js @@ -34,7 +34,7 @@ class Adapter { }); } - send(protocol, command, payload) { + send(protocol, command, payload, secret) { return new Promise((resolve, reject) => { const isAcceptedResponse = (response) => { if (response.protocol !== protocol) { @@ -134,7 +134,9 @@ class Adapter { }); }; debugRequest(`${protocol}:${command}`); - this.client.transport.send(protocol, command, payload); + const withSecret = payload; + withSecret.secret = secret; + this.client.transport.send(protocol, command, withSecret); if (protocol === 'component') { // Component protocol messages can do lots of I/O, set no timeout diff --git a/lib/client.js b/lib/client.js index f7fbe4f..9fad41d 100644 --- a/lib/client.js +++ b/lib/client.js @@ -152,23 +152,19 @@ class FbpClient extends EventEmitter { } const commands = {}; Object.keys(schemas[protocol].input).forEach((command) => { - commands[command] = (payload = {}) => { - const withSecret = payload; - withSecret.secret = this.definition.secret; - return this.validate(`/${protocol}/${schemas[protocol].input[command].id}`, { - protocol, - command, - payload: withSecret, - }) - .then(() => new Promise((resolve, reject) => { - if (!this.adapter) { - reject(new Error('FBP client must be connected to the runtime before sending commands')); - } - resolve(null); - })) - .then(() => this.canSend(protocol, command)) - .then(() => this.adapter.send(protocol, command, withSecret)); - }; + commands[command] = (payload = {}) => this.validate(`/${protocol}/${schemas[protocol].input[command].id}`, { + protocol, + command, + payload, + }) + .then(() => new Promise((resolve, reject) => { + if (!this.adapter) { + reject(new Error('FBP client must be connected to the runtime before sending commands')); + } + resolve(null); + })) + .then(() => this.canSend(protocol, command)) + .then(() => this.adapter.send(protocol, command, payload, this.definition.secret)); }); this.protocol[protocol] = commands; });