jrpc.js
function sendResponse(id, err, result) {
  var response = {
    jsonrpc: '2.0',
    id     : id
  };

  if (id === null) {
    return;
  }

  if (this.active && id in this.localTimers) {
    clearTimeout(this.localTimers[id]);  // Passing true instead of a timeout is safe
    delete this.localTimers[id];
  } else {
    // Silently ignoring second response to same request
    return;
  }

  if (typeof err !== 'undefined' && err !== null && err !== false) {
    if (typeof err === 'number') {
      response.error = {
        code   : err,
        message: 'error'
      };
    } else if (err === true) {
      response.error = {
        code   : -1,
        message: 'error'
      };
    } else if (typeof err === 'string') {
      response.error = {
        code   : -1,
        message: err
      };
    } else if (
      typeof err === 'object'
      && 'code' in err
      && 'message' in err
    ) {
      response.error = err;
    } else {
      response.error = {
        code   : -2,
        message: 'error',
        data   : err
      };
    }
  } else {
    response.result = result;
  }
  this.outbox.responses.push(response);

  // If we're interactive, send the new response
  this.transmit();
}
function sendResponse(id, err, result) {
  var response = {
    jsonrpc: '2.0',
    id     : id
  };

  if (id === null) {
    return;
  }

  if (this.active && id in this.localTimers) {
    clearTimeout(this.localTimers[id]);  // Passing true instead of a timeout is safe
    delete this.localTimers[id];
  } else {
    // Silently ignoring second response to same request
    return;
  }

  if (typeof err !== 'undefined' && err !== null && err !== false) {
    if (typeof err === 'number') {
      response.error = {
        code   : err,
        message: 'error'
      };
    } else if (err === true) {
      response.error = {
        code   : -1,
        message: 'error'
      };
    } else if (typeof err === 'string') {
      response.error = {
        code   : -1,
        message: err
      };
    } else if (
      typeof err === 'object'
      && 'code' in err
      && 'message' in err
    ) {
      response.error = err;
    } else {
      response.error = {
        code   : -2,
        message: 'error',
        data   : err
      };
    }
  } else {
    response.result = result;
  }
  this.outbox.responses.push(response);

  // If we're interactive, send the new response
  this.transmit();
}
function sendResponse ( id , err , result ) { var response = { jsonrpc : '2.0' , id : id } ; if ( id === null ) { return ; } if ( this . active && id in this . localTimers ) { clearTimeout ( this . localTimers [ id ] ) ; // Passing true instead of a timeout is safe delete this . localTimers [ id ] ; } else { // Silently ignoring second response to same request return ; } if ( typeof err !== 'undefined' && err !== null && err !== false ) { if ( typeof err === 'number' ) { response . error = { code : err , message : 'error' } ; } else if ( err === true ) { response . error = { code : - 1 , message : 'error' } ; } else if ( typeof err === 'string' ) { response . error = { code : - 1 , message : err } ; } else if ( typeof err === 'object' && 'code' in err && 'message' in err ) { response . error = err ; } else { response . error = { code : - 2 , message : 'error' , data : err } ; } } else { response . result = result ; } this . outbox . responses . push ( response ) ; // If we're interactive, send the new response this . transmit ( ) ; }
Handle local method results

@type {JRPC~serviceResultCallback}

@param {number}  id        Serial number, bound, no need to supply
@param {boolean} err       Anything non-falsey means error and is sent
@param {Object}  result    Any result you wish to produce

@return {undefined} No return value
Handle local method results