telnet-client
Advanced tools
Comparing version 0.8.1 to 0.9.0
@@ -9,3 +9,2 @@ // Node.js Telnet client | ||
// define a constructor (object) and inherit EventEmitter functions | ||
@@ -42,2 +41,6 @@ function Telnet() { | ||
? opts.pageSeparator : '---- More') | ||
self.negotiationMandatory = (typeof opts.negotiationMandatory !== 'undefined' | ||
? opts.negotiationMandatory : true) | ||
self.sendTimeout = (typeof opts.sendTimeout !== 'undefined' ? opts.sendTimeout : 2000) | ||
self.response = '' | ||
@@ -53,2 +56,4 @@ self.telnetState | ||
self.emit('connect') | ||
if (self.negotiationMandatory === false) resolve() | ||
}) | ||
@@ -92,3 +97,2 @@ | ||
var self = this | ||
cmd += this.ors | ||
@@ -108,2 +112,4 @@ if (opts && opts instanceof Function) callback = opts | ||
cmd += self.ors | ||
if (self.telnetSocket.writable) { | ||
@@ -131,2 +137,42 @@ self.telnetSocket.write(cmd, function() { | ||
Telnet.prototype.send = function(data, opts, callback) { | ||
var self = this | ||
if (opts && opts instanceof Function) callback = opts | ||
return new Promise(function(resolve, reject) { | ||
if (opts && opts instanceof Object) { | ||
this.ors = opts.ors || self.ors | ||
self.sendTimeout = opts.timeout || self.sendTimeout | ||
} | ||
data += this.ors | ||
if (self.telnetSocket.writable) { | ||
self.telnetSocket.write(data, function() { | ||
var response = '' | ||
self.telnetState = 'standby' | ||
self.on('data', function(data) { | ||
response += data.toString() | ||
if (opts.waitfor !== undefined) { | ||
if (response.indexOf(opts.waitfor) === -1) return | ||
resolve(response) | ||
} | ||
}) | ||
if (opts.waitfor === undefined) { | ||
setTimeout(function() { | ||
if (response === '') return reject(new Error('response not received')) | ||
resolve(response) | ||
}, self.sendTimeout) | ||
} | ||
}) | ||
} | ||
}).asCallback(callback) | ||
} | ||
Telnet.prototype.end = function() { | ||
@@ -133,0 +179,0 @@ var self = this |
@@ -8,3 +8,3 @@ { | ||
}, | ||
"version": "0.8.1", | ||
"version": "0.9.0", | ||
"main": "./lib/telnet-client.js", | ||
@@ -11,0 +11,0 @@ "engine": "node >= 0.10.29", |
@@ -137,2 +137,4 @@ [![GitHub license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/mkozjak/node-telnet-client/blob/master/LICENSE) | ||
* `pageSeparator`: The pattern used (and removed from final output) for breaking the number of lines on output. Defaults to '---- More'. | ||
* `negotiationMandatory`: Disable telnet negotiations if needed. Can be used with 'send' when telnet specification is not needed. Defaults to true. | ||
* `sendTimeout`: A timeout used to wait for a server reply when the 'send' method is used. Defaults to 2000 (ms) or to sendTimeout ('connect' method) if set. | ||
* `debug`: Enable/disable debug logs on console. Defaults to false. | ||
@@ -161,2 +163,12 @@ | ||
### connection.send(data, [options], [callback]) -> Promise | ||
Sends data on the socket without requiring telnet negotiations. | ||
Options: | ||
* `ors`: Output record separator. A separator used to execute commands (break lines on input). Defaults to '\n'. | ||
* `waitfor`: Wait for the given string before returning a response | ||
* `timeout`: A timeout used to wait for a server reply when the 'send' method is used. Defaults to 2000 (ms). | ||
### connection.end() -> Promise | ||
@@ -163,0 +175,0 @@ |
@@ -9,3 +9,3 @@ var telnet = process.env.NODETELNETCLIENT_COV | ||
exports['busybox'] = nodeunit.testCase({ | ||
exports['server_push'] = nodeunit.testCase({ | ||
setUp: function(callback) { | ||
@@ -12,0 +12,0 @@ srv = telnet_server.createServer(function(c) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24757
11
446
217
4