adds info object to main object

This commit is contained in:
samueleaton 2016-05-13 18:13:25 -06:00
parent 4814d05563
commit 700e505e0b
3 changed files with 72 additions and 27 deletions

View file

@ -92,25 +92,40 @@ var AutoSSH = function (_EventEmitter) {
});
}
/*
*/
}, {
key: 'getConnectionInfo',
value: function getConnectionInfo() {
var _this3 = this;
var infoObj = {
kill: function kill() {
return _this3.kill;
},
pid: null,
host: this.host || null,
username: this.username || null,
remotePort: parseInt(this.remotePort),
localPort: parseInt(this.localPort),
execString: this.execString || null
};
if (this.currentProcess) infoObj.pid = this.currentProcess.pid;
if (!infoObj.localPort) infoObj.localPort = null;
if (!infoObj.remotePort) infoObj.remotePort = null;
return infoObj;
}
/* fired when connection established
*/
}, {
key: 'emitConnect',
value: function emitConnect() {
var _this3 = this;
this.emit('connect', {
kill: function kill() {
return _this3.kill;
},
pid: this.currentProcess.pid,
host: this.host,
username: this.username,
remotePort: this.remotePort,
localPort: this.localPort,
execString: this.execString
});
this.emit('connect', this.getConnectionInfo());
}
/* fired when timeout error occurs
@ -334,9 +349,15 @@ module.exports = function (conf) {
}
};
Object.defineProperty(autosshInterface, 'info', {
get: function get() {
return autossh.getConnectionInfo();
}
});
Object.defineProperty(autosshInterface, 'pid', {
get: function get() {
return autossh.currentProcess.pid;
if (autossh.currentProcess) return autossh.currentProcess.pid;else return null;
}
});

View file

@ -4,7 +4,7 @@
"description": "Persistent SSH tunnels",
"main": "index.js",
"scripts": {
"lint": "eslint -c .eslintrc.json src/*.js -o .eslint.log && echo '' > .eslint.log ; cat .eslint.log ",
"lint": "eslint -c .eslintrc.json --max-warnings 2 src/*.js -o .eslint.log && echo '' > .eslint.log ; cat .eslint.log ",
"pretranspile": "npm run -s lint",
"transpile": "babel src -d ."
},

View file

@ -64,20 +64,35 @@ class AutoSSH extends EventEmitter {
});
}
/*
*/
getConnectionInfo() {
const infoObj = {
kill: () => this.kill,
pid: null,
host: this.host || null,
username: this.username || null,
remotePort: parseInt(this.remotePort),
localPort: parseInt(this.localPort),
execString: this.execString || null
};
if (this.currentProcess)
infoObj.pid = this.currentProcess.pid;
if (!infoObj.localPort)
infoObj.localPort = null;
if (!infoObj.remotePort)
infoObj.remotePort = null;
return infoObj;
}
/* fired when connection established
*/
emitConnect() {
this.emit('connect', {
kill: () => this.kill,
pid: this.currentProcess.pid,
host: this.host,
username: this.username,
remotePort: this.remotePort,
localPort: this.localPort,
execString: this.execString
});
this.emit('connect', this.getConnectionInfo());
}
/* fired when timeout error occurs
*/
emitTimeout() {
@ -96,7 +111,7 @@ class AutoSSH extends EventEmitter {
*/
pollConnection() {
if (this.killed)
return;
return;
if (this.maxPollCount && this.pollCount >= this.maxPollCount) {
this.emit('error', 'Max poll count reached. Aborting...');
@ -277,8 +292,17 @@ module.exports = function(conf) {
}
};
Object.defineProperty(autosshInterface, 'info', {
get: () => autossh.getConnectionInfo()
});
Object.defineProperty(autosshInterface, 'pid', {
get: () => autossh.currentProcess.pid
get: () => {
if (autossh.currentProcess)
return autossh.currentProcess.pid;
else
return null;
}
});
return autosshInterface;