Making connections dynamic as well
This commit is contained in:
parent
16cdb56be6
commit
ed76890b8a
42
lib/robot.js
42
lib/robot.js
|
@ -283,26 +283,42 @@ Robot.prototype.startWork = function() {
|
||||||
Robot.prototype.startConnections = function(callback) {
|
Robot.prototype.startConnections = function(callback) {
|
||||||
this.log("Starting connections.");
|
this.log("Starting connections.");
|
||||||
|
|
||||||
var starters = _.map(this.connections, function(conn, name) {
|
var starters = _.map(this.connections, function(conn) {
|
||||||
this[name] = conn;
|
|
||||||
|
|
||||||
return function(cb) {
|
return function(cb) {
|
||||||
var str = "Starting connection '" + name + "'";
|
return this.startConnection(conn, cb);
|
||||||
|
|
||||||
if (conn.host) {
|
|
||||||
str += " on host " + conn.host;
|
|
||||||
} else if (conn.port) {
|
|
||||||
str += " on port " + conn.port;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.log(str + ".");
|
|
||||||
return conn.connect.call(conn, cb);
|
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
return _.parallel(starters, callback);
|
return _.parallel(starters, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts a single connection on Robot
|
||||||
|
*
|
||||||
|
* @param {Object} connection to start
|
||||||
|
* @param {Function} callback function to be triggered after the connection is
|
||||||
|
* started
|
||||||
|
* @return {void}
|
||||||
|
*/
|
||||||
|
Robot.prototype.startConnection = function(connection, callback) {
|
||||||
|
if (connection.connected === true) {
|
||||||
|
return callback.call(connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
var str = "Starting connection '" + connection.name + "'";
|
||||||
|
|
||||||
|
if (connection.host) {
|
||||||
|
str += " on host " + connection.host;
|
||||||
|
} else if (connection.port) {
|
||||||
|
str += " on port " + connection.port;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.log(str + ".");
|
||||||
|
connection.connect.call(connection, callback);
|
||||||
|
connection.connected = true;
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the Robot's devices
|
* Starts the Robot's devices
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue