$ npm i fingi-cmd --save
The package exports the
Command class, a
parse method and a
Stream which is a
Duplex stream that works on
Create by invoking the constructor with
new and passing the desired command properties.
var Command = Command;var cmd = action: 'HELLO' ;
nonce- (number) The nonce counter.
source- (string array) The command source (or origin.)
action- (string) The action to carry out.
args- (string array) Arguments
Check with the official Fingi protocol description for more information.
When you already have a
Command instance, these 2 methods may be of interest:
Signs the entire command line using the HMAC-SHA1 algorithm and append the resulting signature digest as the last argument.
Returns correct protocol represenation of the command as a string ready to be sent onto the wire.
Stream is an instance of node core's
Duplex object-mode stream which
automatically parses incoming data into
Command instances and then allow
out commands to the wire.
var CmdStream = Stream;var commands = ;
To receive commands, pipe your raw incoming stream into the
CmdStream and listen for the
command event. The
chunker module is also recommended to ensure that the stream
always receives a full line.
Or when using with
var chunker = new matcher: '\r\n' ;processstdin;// commands.on('command')... as usual
Send commands by using the
send() method, passing in the
Command instance to send.
commands;// send PINGs every second.;
Optionally, you may have a string representation that you would like to parse by yourself.
You can do this by using the exported
var parse = parse;var input = '1000 server-name 9.9.99 | HELLO device\r\n';var cmd = ;console; // prints "server-name"
MIT. See the LICENSE file for the full license text.