2019-05-27 10:33:22 -07:00
|
|
|
var rpc = require('./jsonrpc');
|
|
|
|
|
|
|
|
|
|
function Client(opts) {
|
|
|
|
|
this.rpc = new rpc.Client(opts);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Client.prototype.cmd = function() {
|
|
|
|
|
var args = [].slice.call(arguments);
|
|
|
|
|
var cmd = args.shift();
|
|
|
|
|
|
|
|
|
|
callRpc(cmd, args, this.rpc);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function callRpc (cmd, args, rpc) {
|
|
|
|
|
var fn = args[args.length - 1];
|
|
|
|
|
|
2021-03-17 17:54:09 -06:00
|
|
|
// if the last argument is a callback, pop it from the args list
|
|
|
|
|
if (typeof fn === 'function')
|
2019-05-27 10:33:22 -07:00
|
|
|
args.pop();
|
2021-03-17 17:54:09 -06:00
|
|
|
else
|
2019-05-27 10:33:22 -07:00
|
|
|
fn = function () {};
|
|
|
|
|
|
|
|
|
|
rpc.call(cmd, args, function () {
|
|
|
|
|
var args = [].slice.call(arguments);
|
2021-03-17 17:54:09 -06:00
|
|
|
|
2019-05-27 10:33:22 -07:00
|
|
|
args.unshift(null);
|
|
|
|
|
fn.apply(this, args);
|
|
|
|
|
}, function(err) {
|
|
|
|
|
fn(err);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports.Client = Client;
|