Permalink
Browse files

Finished adding the statistics.

  • Loading branch information...
1 parent 145518c commit 0636e7d09640cd12888e2b0f18be4a58eeb7faa5 Paul Maxan committed Apr 17, 2012
Showing with 97 additions and 16 deletions.
  1. +49 −3 irc.js
  2. +1 −5 public/js/app.js
  3. +29 −5 public/js/irc-client.js
  4. +2 −0 public/js/tcp-client.js
  5. +16 −3 tcp-proxy.js
View
52 irc.js
@@ -72,11 +72,57 @@ app.listen(process.env.C9_PORT || process.env['app_port'] || 16960);
console.log("IRC#nodester is running on port %d in %s mode", app.address().port, app.settings.env);
/*
- * app specific processor, e.g., statistics, web users
+ * array of nicks that connect through the web interface
*/
-var appProcessor = function(client, data) {
-//TODO
+var webusers = [];
+/*
+ * app specific processor, e.g., statistics, web users
+ */
+var appProcessor = function (action, client, msg, socket) {
+ switch (action) {
+ case "message":
+ switch (msg.action) {
+ case "requestStatistics":
+ /*
+ * The statistics are gathered every 15 seconds. There will be a lag
+ * of less than 15 seconds since the last statistics "crop" and the actual value
+ */
+ client.send(JSON.stringify({
+ action: "statistics",
+ st: startTime,
+ min: minMem,
+ max: maxMem,
+ current: currMem
+ }));
+ break;
+ case "requestWebUsers":
+ switch (msg.data) {
+ case "add":
+ webusers.push(msg.user);
+ break;
+ case "remove":
+ for (var i = 0; i < webusers.length; i++) {
+ if (webusers[i] == msg.user) {
+ webusers.slice(i,1);
+ break;
+ }
+ }
+ break;
+ default: //list
+ client.send(JSON.stringify({
+ action: "webusers",
+ webusers: webusers
+ }));
+ }
+ default:
+ }
+ break;
+ case "disconnect":
+
+ break;
+ default:
+ }
}
var io = sio.listen(app);
View
6 public/js/app.js
@@ -57,7 +57,7 @@ $(document).ready(function() {
top : 'auto',
left : 'auto'
},
- stats = null, //statistics
+ stats = null, //statistics .st .current .min .max
serverStartTime = null; //server start time
this.getOpts = function() {
@@ -408,10 +408,6 @@ $(document).ready(function() {
break;
case "statistics":
c.updateStats(obj);
- if (obj.wud == true) {
- //the webusers list has been changed, we initiate retrieval
- //ircClient.requestWebUsers();
- }
var header_class = (c.getStatsEnabled() == true) ? 'header-stats' : 'header-stats off';
nickLabel.html('<span class="'+header_class+'">Server up for ' + c.getServerTime()
+ ', using ' + c.getMinRss() + '-' + c.getMaxRss() + ' MB of RAM</span> ' + nickname);
View
34 public/js/irc-client.js
@@ -51,7 +51,21 @@ IRCClient.prototype.connect = function () {
}
});
});
-
+
+ this.client.on("statistics", function (data) {
+ that.emit("data", JSON.stringify({
+ messagetype: "statistics",
+ st: data.st,
+ min: data.min,
+ max: data.max,
+ current: data.current
+ }));
+ });
+
+ this.client.on("webusers", function (data) {
+
+ });
+
this.client.connect();
}
@@ -84,9 +98,19 @@ IRCClient.prototype.requestStatistics = function () {
this.client.send("requestStatistics");
}
-IRCClient.prototype.requestWebUsers = function () {
- this.client.send("requestWebUsers");
+IRCClient.prototype.addWebUsers = function (userNick) {
+
+ this.client.send("requestWebUsers", param);
+}
+IRCClient.prototype.updateWebUsers = function (formerNick, newNick) {
+
+ this.client.send("requestWebUsers", param);
}
+IRCClient.prototype.listWebUsers = function () {
+
+ this.client.send("requestWebUsers", param);
+}
+
IRCClient.prototype.clearAll = function () {
this.client.clearAll();
@@ -336,7 +360,7 @@ var emulateMessage = function (that, message) {
message: (message.args[1])
}));
} else {
- that.send("data", "PRIVMSG " + message.nick
+ that.client.send("data", "PRIVMSG " + message.nick
+ " :I am using a web client. I can only talk on channel #nodester.\r\n");
}
break;
@@ -388,7 +412,7 @@ var emulateMessage = function (that, message) {
* Handler for a server PING
*/
case "PING":
- that.send("data", "PONG :" + message.args[0] + "\r\n");
+ that.client.send("data", "PONG :" + message.args[0] + "\r\n");
break
/*
View
2 public/js/tcp-client.js
@@ -56,6 +56,8 @@ Client.prototype.connect = function () {
that.emit("data", {data: data.data});
break;
default:
+ //app related data that the proxy should not be concerned with, e.g., statistics, webusers
+ that.emit(data.action, data);
}
});
View
19 tcp-proxy.js
@@ -37,6 +37,14 @@ var Proxy = function (client, appProcessor) {
client.on("disconnect", function () {
clientIsConnected = false;
if (socketIsConnected) {
+ /*
+ * app related data that the proxy should not be concerned with:
+ * remove nick from webUsers list
+ * send irc.quit
+ */
+ if (typeof appProcessor === "function") {
+ appProcessor("disconnect", null, null, socket);
+ }
socketIsConnected = false;
socket.destroy();
}
@@ -63,12 +71,17 @@ var Proxy = function (client, appProcessor) {
}
break;
default:
- //app related data that the proxy should not be concerned with, e.g., statistics, webusers
+ /*
+ * app related data that the proxy should not be concerned with:
+ * - requestStatistics()
+ * - addWebUser(nick)
+ * - updateWebUser(former, current)
+ * - listWebUsers()
+ */
console.log(msg.action);
if (typeof appProcessor === "function") {
- appProcessor(client, msg.data);
+ appProcessor("message", client, msg, null);
}
- break;
}
});
}

0 comments on commit 0636e7d

Please sign in to comment.