src/react/puppeteer/src/js/puppet/CreateTunnel.js
/**
 * Checks that the destination device (the one being streamed to) has
 * an appropriate 'module-native-protocol-tcp' open. If not, send an
 * ajax request to the destination's puppet node to open said port.
 *
 * @param destDevice The device object from this application's state
 * tree representing the destination (stream-to) device.
 * @param callback A lambda to execute upon determining that the
 * destination device already has a port open OR to pass as the
 * "done" callback for the ajax request to open the port.
 */
Checks that the destination device (the one being streamed to) has
an appropriate 'module-native-protocol-tcp' open. If not, send an
ajax request to the destination's puppet node to open said port.

@param destDevice The device object from this application's state
tree representing the destination (stream-to) device.
@param callback A lambda to execute upon determining that the
destination device already has a port open OR to pass as the
"done" callback for the ajax request to open the port.
Checks that the destination device ( the one being streamed to ) has an appropriate ' module - native - protocol - tcp ' open . If not send an ajax request to the destination ' s puppet node to open said port . @param destDevice The device object from this application ' s state tree representing the destination ( stream - to ) device . @param callback A lambda to execute upon determining that the destination device already has a port open OR to pass as the " done " callback for the ajax request to open the port .
function checkDest(destDevice, callback) {
  const destOpen = destDevice.get('modules').map(m => m.get('name')).includes('module-native-protocol-tcp');
  if (destOpen) {
    callback({status: "Check"});
  } else {
    $.ajax({
      url: destDevice.get('host') + '/v1/gates',
      method: 'POST',
      contentType: 'application/json',
      accepts: 'application/json',
      data: { port: 4141 },
      beforeSend: (xhr) => {
        xhr.setRequestHeader("Authorization", "Basic " + btoa("nick:something"));
      },
      error: (jqXHR) => {
        console.log("Ajax error: " + jqXHR.status);
      }
    }).done(callback);
  }
}
function checkDest ( destDevice , callback ) { const destOpen = destDevice . get ( 'modules' ) . map ( m => m . get ( 'name' ) ) . includes ( 'module-native-protocol-tcp' ) ; if ( destOpen ) { callback ( { status : "Check" } ) ; } else { $ . ajax ( { url : destDevice . get ( 'host' ) + '/v1/gates' , method : 'POST' , contentType : 'application/json' , accepts : 'application/json' , data : { port : 4141 } , beforeSend : ( xhr ) => { xhr . setRequestHeader ( "Authorization" , "Basic " + btoa ( "nick:something" ) ) ; } , error : ( jqXHR ) => { console . log ( "Ajax error: " + jqXHR . status ) ; } } ) . done ( callback ) ; } }
Checks that the destination device (the one being streamed to) has
 an appropriate 'module-native-protocol-tcp' open.
Checks that the destination device ( the one being streamed to ) has an appropriate ' module - native - protocol - tcp ' open .
// Check that 'module-native-protocol-tcp' is open on "destDevice".