king
Version:
A powerful server infrastructure management platform - "The King of your Nodes"
91 lines (71 loc) • 2.43 kB
JavaScript
// Generated by CoffeeScript 1.6.3
var Base, KingServer, List, ServantClient, WebUser, ecstatic, http, path, rootdir, shoe, upnode,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
http = require("http");
path = require("path");
upnode = require("upnode");
shoe = require("shoe");
ecstatic = require("ecstatic");
Base = require("../common/base");
List = require("../common/list");
ServantClient = require("./servant-client");
WebUser = require("./web-user");
rootdir = path.join(__dirname, '..', '..');
KingServer = (function(_super) {
__extends(KingServer, _super);
KingServer.prototype.name = "KingServer";
function KingServer(port) {
this.port = port;
this.servants = new List;
this.users = new List;
this.initComms();
this.initWeb();
}
KingServer.prototype.initComms = function() {
var comms,
_this = this;
return comms = upnode(function(remote, d) {
var servant;
servant = new ServantClient(_this, d);
return servant.api;
}).listen(this.port, function() {
return _this.log("comms listening on: " + _this.port);
});
};
KingServer.prototype.initWeb = function() {
var opts, sock, webs,
_this = this;
opts = {
root: path.join(rootdir, 'webui'),
cache: 0
};
webs = http.createServer(ecstatic(opts)).listen(8080, function() {
return _this.log("webs listening on: 8080");
});
sock = shoe(function(stream) {
return new WebUser(_this, stream);
}).install(webs, "/webs");
this.servants.on('add', function(item) {
return _this.userBroadcast('servants-add', item.serialize());
});
return this.servants.on('remove', function(item) {
return _this.userBroadcast('servants-remove', item.serialize());
});
};
KingServer.prototype.userBroadcast = function() {
var args,
_this = this;
args = arguments;
return this.users.each(function(user) {
return user.remote.broadcast.apply(user.remote, args);
});
};
return KingServer;
})(Base);
exports.start = function(port) {
if (port == null) {
port = 5464;
}
return new KingServer(port);
};