marionette-client
Advanced tools
Comparing version 0.5.4 to 0.5.5
var Abstract, CommandStream; | ||
var net = require('net'); | ||
var debug = require('debug')('marionette:tcp'); | ||
@@ -6,6 +8,51 @@ Abstract = require('./abstract'); | ||
var MAX_TRIES = 20; | ||
var WAIT_BETWEEN_TRIES_MS = 250; | ||
/** TCP **/ | ||
Tcp.Socket = require('net').Socket; | ||
Tcp.Socket = net.Socket; | ||
/** | ||
* Tries to connect to a given socket location. | ||
* Will retry on failure. | ||
* | ||
* waitForSocket(2828, 'localhost', function(err, socket) { | ||
* }); | ||
* | ||
* Note- there is a forth argument used to recursion that should | ||
* never be used publicly. | ||
* | ||
* @param {Number} port to connect to. | ||
* @param {String} host like localhost. | ||
* @param {Function} callback [err, socket]. | ||
*/ | ||
function waitForSocket(port, host, callback, _tries) { | ||
debug('attempt to open socket', port, host); | ||
_tries = _tries || 0; | ||
if (_tries >= MAX_TRIES) | ||
return callback(err); | ||
function handleError() { | ||
debug('socket is not ready trying'); | ||
// retry connection | ||
setTimeout( | ||
waitForSocket, | ||
WAIT_BETWEEN_TRIES_MS, | ||
port, | ||
host, | ||
callback, | ||
++_tries | ||
); | ||
} | ||
var socket = new Tcp.Socket(); | ||
socket.connect(port, host, function(one, two) { | ||
debug('connected', port, host); | ||
socket.removeListener('error', handleError); | ||
callback(null, socket); | ||
}); | ||
socket.once('error', handleError); | ||
} | ||
/** | ||
* NodeJS only tcp socket driver for marionette. | ||
@@ -23,8 +70,8 @@ * See {{#crossLink "Marionette.Drivers.MozTcp"}}{{/crossLink}} | ||
function Tcp(options) { | ||
if (typeof(options)) { | ||
if (!options) { | ||
options = {}; | ||
} | ||
Abstract.call(this, options); | ||
this.connectionId = 0; | ||
@@ -61,6 +108,8 @@ /** | ||
this.socket = new Tcp.Socket(); | ||
this.socket.connect(this.port, this.host); | ||
client = this.client = new CommandStream(this.socket); | ||
this.client.on('command', this._onClientCommand.bind(this)); | ||
waitForSocket(this.port, this.host, function(err, socket) { | ||
debug('got socket starting command stream'); | ||
this.socket = socket; | ||
client = this.client = new CommandStream(this.socket); | ||
this.client.on('command', this._onClientCommand.bind(this)); | ||
}.bind(this)); | ||
}; | ||
@@ -67,0 +116,0 @@ |
@@ -200,2 +200,3 @@ (function(module, ns) { | ||
Responder.prototype.on = Responder.prototype.addEventListener; | ||
Responder.prototype.removeListener = Responder.prototype.removeEventListener; | ||
@@ -202,0 +203,0 @@ module.exports = Responder; |
{ | ||
"name": "marionette-client", | ||
"version": "0.5.4", | ||
"version": "0.5.5", | ||
"main": "lib/marionette/index", | ||
@@ -5,0 +5,0 @@ "description": "Marionette Javascript Client", |
Sorry, the diff of this file is not supported yet
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 4 instances in 1 package
4799
5
140091
25