You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

browserstack-local

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browserstack-local - npm Package Compare versions

Comparing version

to
1.3.7

77

lib/Local.js

@@ -6,7 +6,8 @@ var childProcess = require('child_process'),

LocalBinary = require('./LocalBinary'),
LocalError = require('./LocalError');
LocalError = require('./LocalError'),
psTree = require('ps-tree');
function Local(){
this.pid = undefined;
this.isProcessRunning = false;
this.retriesLeft = 5;

@@ -61,41 +62,6 @@ this.key = process.env.BROWSERSTACK_ACCESS_KEY;

that.pid = data['pid'];
that.isProcessRunning = true;
callback();
}
});
// that.tunnel = childProcess.spawn(binaryPath, that.getBinaryArgs());
// that.tunnel.on('exit', function(){
// that.tunnel = undefined;
// if(that.exitCallback) that.exitCallback();
// });
// that.stdout = fs.openSync(that.logfile, 'r');
// var chunkSize = 512,
// buffer = new Buffer(81920),
// bytesRead = 0,
// error = undefined;
// while(true){
// var bytes = fs.readSync(that.stdout, buffer, bytesRead, chunkSize, bytesRead);
// if(bytes == 0) continue;
// var buffRead = buffer.slice(bytesRead, bytesRead+bytes);
// bytesRead += bytes;
// var data = buffRead.toString();
// if(data.match(that.errorRegex)){
// fs.closeSync(that.stdout);
// error = data.match(that.errorRegex)[0].trim();
// break;
// }
// if(data.match(that.doneRegex)){
// fs.closeSync(that.stdout);
// break;
// }
// }
// if(error) throw new LocalError(error);
// callback();
});

@@ -105,3 +71,3 @@ };

this.isRunning = function(){
return this.pid && running(this.pid);
return this.pid && running(this.pid) && this.isProcessRunning;
};

@@ -111,4 +77,3 @@

if(!this.pid) return callback();
this.opcode = 'stop';
this.tunnel = childProcess.execFile(this.binaryPath, this.getBinaryArgs(), function(error){
this.killAllProcesses(function(error){
if(error) callback(new LocalError(error.toString()));

@@ -294,3 +259,33 @@ callback();

};
this.killAllProcesses = function(callback){
psTree(this.pid, (err, children) => {
var childPids = children.map(val => val.PID);
var killChecker = setInterval(() => {
if(childPids.length === 0) {
clearInterval(killChecker);
try {
process.kill(this.pid);
// This gives time to local binary to send kill signal to railsApp.
setTimeout(() => {
this.isProcessRunning = false;
callback();
}, 2000);
} catch(err) {
this.isProcessRunning = false;
callback();
}
}
for(var i in childPids) {
try {
process.kill(childPids[i]);
} catch(err) {
childPids.splice(i, 1);
}
}
},500);
});
};
}
module.exports = Local;
{
"name": "browserstack-local",
"version": "1.3.6",
"version": "1.3.7",
"description": "Nodejs bindings for BrowserStack Local",

@@ -22,2 +22,3 @@ "engine": "^0.10.44",

"is-running": "^2.0.0",
"ps-tree": "=1.1.1",
"sinon": "^1.17.6",

@@ -24,0 +25,0 @@ "temp-fs": "^0.9.9"