From 068dd11b58ae98d32cd3cd06e7b30c950dd992bd Mon Sep 17 00:00:00 2001 From: Sam Eaton Date: Wed, 2 Aug 2017 08:44:59 -0700 Subject: [PATCH] exposes pollTimeout property --- README.md | 22 +++++++++++++++++++++- index.js | 12 +++++------- package.json | 2 +- src/index.js | 4 ++-- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 005eec7..44d46d2 100644 --- a/README.md +++ b/README.md @@ -290,6 +290,26 @@ autossh({
+#### Adjusting Poll Timeout + +Autossh will attempt to establish a connection every *n* milliseconds until a connection is established. To increase the time between each attempt, set the `pollTimeout` option in the configuration. + +The following will attempt to connect every second (1000 ms) up to 50 times before giving up: + +```javascript +autossh({ + host: '111.22.333.444', + username: 'root', + localPort: 'auto', + remotePort: 5432, + maxPollCount: 50, + pollTimeout: 1000 +}) +.on('connect', connection => { + console.log('connected: ', connection); +}) +``` + #### Specifying a Different SSH Port The designated port for SSH according to the Transmission Control Protocol (TCP) is port 22, but you can specify a different port if you are using a different port. Set the `sshPort` property in the object you pass to `autossh`. @@ -302,4 +322,4 @@ autossh({ remotePort: 5432, sshPort: 9999 }); -``` \ No newline at end of file +``` diff --git a/index.js b/index.js index 7226aba..f6e8f45 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ 'use strict'; -var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); @@ -22,19 +22,17 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function" /* AutoSSH class */ - var AutoSSH = function (_EventEmitter) { _inherits(AutoSSH, _EventEmitter); /* */ - function AutoSSH() { - var conf = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; + var conf = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; _classCallCheck(this, AutoSSH); - var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(AutoSSH).call(this)); + var _this = _possibleConstructorReturn(this, (AutoSSH.__proto__ || Object.getPrototypeOf(AutoSSH)).call(this)); _this.configure(conf); @@ -66,8 +64,8 @@ var AutoSSH = function (_EventEmitter) { if (this.reverse) this.localPort = parseInt(conf.localPort) || 22;else this.localPort = conf.localPort || 'auto'; this.pollCount = 0; - this.maxPollCount = conf.maxPollCount || 30; - this.pollTimeout = 75; + this.maxPollCount = parseInt(conf.maxPollCount) || 30; + this.pollTimeout = parseInt(conf.pollTimeout) || 75; this.serverAliveInterval = typeof conf.serverAliveInterval === 'number' ? conf.serverAliveInterval : 120; diff --git a/package.json b/package.json index 8c5a78d..4069419 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "autossh", - "version": "0.0.16", + "version": "0.1.0", "description": "Persistent SSH tunnels", "main": "index.js", "scripts": { diff --git a/src/index.js b/src/index.js index b97f6e8..3495928 100644 --- a/src/index.js +++ b/src/index.js @@ -39,8 +39,8 @@ class AutoSSH extends EventEmitter { this.localPort = conf.localPort || 'auto'; this.pollCount = 0; - this.maxPollCount = conf.maxPollCount || 30; - this.pollTimeout = 75; + this.maxPollCount = parseInt(conf.maxPollCount) || 30; + this.pollTimeout = parseInt(conf.pollTimeout) || 75; this.serverAliveInterval = typeof conf.serverAliveInterval === 'number' ? conf.serverAliveInterval : 120;