lib/usbmux.js
function connect(deviceID, devicePort) {
  return Q.Promise(function(resolve, reject) {
    var conn = net.connect(address)
      , req = protocol.connect(deviceID, devicePort);

    /**
     * Handle complete messages from usbmuxd
     * @function
     */
    var parse = protocol.makeParser(function onMsgComplete(msg) {
      debug.connect('Response: \n%o', msg);

      if (msg.MessageType === 'Result' && msg.Number === 0) {
        conn.removeListener('data', parse);
        resolve(conn);
        return;
      }

      // anything other response means it failed
      reject(new UsbmuxdError('Tunnel failed', msg.Number));
      conn.end();
    });

    debug.connect('Request: \n%s', req.slice(16).toString());

    conn.on('data', parse);
    process.nextTick(function() {
      conn.write(req);
    });
  });
}
function connect(deviceID, devicePort) {
  return Q.Promise(function(resolve, reject) {
    var conn = net.connect(address)
      , req = protocol.connect(deviceID, devicePort);

    /**
     * Handle complete messages from usbmuxd
     * @function
     */
    var parse = protocol.makeParser(function onMsgComplete(msg) {
      debug.connect('Response: \n%o', msg);

      if (msg.MessageType === 'Result' && msg.Number === 0) {
        conn.removeListener('data', parse);
        resolve(conn);
        return;
      }

      // anything other response means it failed
      reject(new UsbmuxdError('Tunnel failed', msg.Number));
      conn.end();
    });

    debug.connect('Request: \n%s', req.slice(16).toString());

    conn.on('data', parse);
    process.nextTick(function() {
      conn.write(req);
    });
  });
}
function connect ( deviceID , devicePort ) { return Q . Promise ( function ( resolve , reject ) { var conn = net . connect ( address ) , req = protocol . connect ( deviceID , devicePort ) ; /**
     * Handle complete messages from usbmuxd
     * @function
     */ var parse = protocol . makeParser ( function onMsgComplete ( msg ) { debug . connect ( 'Response: \n%o' , msg ) ; if ( msg . MessageType === 'Result' && msg . Number === 0 ) { conn . removeListener ( 'data' , parse ) ; resolve ( conn ) ; return ; } // anything other response means it failed reject ( new UsbmuxdError ( 'Tunnel failed' , msg . Number ) ) ; conn . end ( ) ; } ) ; debug . connect ( 'Request: \n%s' , req . slice ( 16 ) . toString ( ) ) ; conn . on ( 'data' , parse ) ; process . nextTick ( function ( ) { conn . write ( req ) ; } ) ; } ) ; }
Connects to a device through usbmuxd for a tunneled tcp connection

@param  {string}  deviceID   - Target device's usbmuxd ID
@param  {integer} devicePort - Port on ios device to connect to
@return {Q.promise}
- resolves {net.Socket} - Tunneled tcp connection to device
- rejects  {Error}
Connects to a device through usbmuxd for a tunneled tcp connection