Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: FBP Protocol 0.8 compat #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/adapter/0_x.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
30 changes: 13 additions & 17 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down