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) {
|
||||
this.log("Starting connections.");
|
||||
|
||||
var starters = _.map(this.connections, function(conn, name) {
|
||||
this[name] = conn;
|
||||
|
||||
var starters = _.map(this.connections, function(conn) {
|
||||
return function(cb) {
|
||||
var str = "Starting connection '" + name + "'";
|
||||
|
||||
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);
|
||||
return this.startConnection(conn, cb);
|
||||
}.bind(this);
|
||||
}, this);
|
||||
|
||||
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
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue