Permalink
Browse files

Port is 19526 for ircbeta

  • Loading branch information...
1 parent 4f87c75 commit 92a05d3839e40902e74eda493d81d5d8d097ecac Paul Maxan committed Apr 21, 2012
Showing with 56 additions and 12 deletions.
  1. +4 −3 irc.js
  2. +26 −2 public/js/app.js
  3. +4 −0 public/js/irc-client.js
  4. +11 −6 public/js/tcp-client.js
  5. +11 −1 tcp-proxy.js
View
@@ -57,7 +57,7 @@ var tmr = setInterval(function () {
if (currMem > maxMem) {
maxMem = currMem;
};
- console.log(statTime, "curr:", currMem, "min:", minMem, "max: ", maxMem);
+ //console.log(statTime, "curr:", currMem, "min:", minMem, "max: ", maxMem);
}, 15*1000);
process.on("uncaughtException", function (err) {
@@ -68,7 +68,7 @@ app.get("/", function (req, res, next) {
res.render("./public/index.html");
});
-app.listen(process.env.C9_PORT || process.env['app_port'] || 80);
+app.listen(process.env.C9_PORT || process.env['app_port'] || 19526);
console.log("IRC#nodester is running on port %d in %s mode", app.address().port, app.settings.env);
/*
@@ -138,7 +138,7 @@ var appProcessor = function (action, client, msg, socket) {
}
break;
case "disconnect":
- //socket.write("QUIT :Web user closed browser\r\n");
+ socket.write("QUIT :webuser\r\n");
break;
default:
}
@@ -147,5 +147,6 @@ var appProcessor = function (action, client, msg, socket) {
var io = sio.listen(app);
io.set('log level', 0);
io.sockets.on("connection", function (socket) {
+ console.log("creating new proxy on socket.io: " + socket.id);
var proxy = new Proxy(socket, appProcessor);
});
View
@@ -32,7 +32,11 @@ $(document).ready(function() {
//used in multi tab completion
patternPos = -1,
- prePattern = "";
+ prePattern = "",
+
+ //used in reconnects
+ iEncounteredDisconnect = false,
+ iReconnectPostpendCount = 0;
window.counter = 0;
nickText.focus();
@@ -124,6 +128,7 @@ $(document).ready(function() {
//initiate connect to the irc server
ircClient.clearAll();
ircClient.on("connected", handleOnConnected);
+ ircClient.on("reconnecting", handleOnReconnecting);
ircClient.on("disconnected", handleOnDisconnected);
ircClient.on("closed", handleOnClosed);
ircClient.on("error", handleOnError);
@@ -224,8 +229,13 @@ $(document).ready(function() {
message = '<span class="msg-connected">Welcome to http://irc.nodester.com/</span>';
message = message.replace(/(https?:\/\/[-_.a-zA-Z0-9&?\/=\[\]()$!#+:]+)/g, "<a href=\"$1\" target=\"_BLANK\">$1</a>");
break;
+ case "reconnecting":
+ iReconnectPostpendCount++;
+ nickname = nickname + iReconnectPostpendCount;
+ message = '<span class="msg-disconnected">Reconnecting as ' + nickname + '...</span>';
+ break;
case "disconnected":
- message = '<span class="msg-disconnected">You\'ve been disconnected from http://irc.nodester.com/<br />Cross your fingers and refresh your browser!</span>';
+ message = '<span class="msg-disconnected">You\'ve been disconnected from http://irc.nodester.com/<br /></span>';
message = message.replace(/(https?:\/\/[-_.a-zA-Z0-9&?\/=\[\]()$!#+:]+)/g, "<a href=\"$1\" target=\"_BLANK\">$1</a>");
break;
default:
@@ -359,6 +369,11 @@ $(document).ready(function() {
//do nothing
break;
case "001":
+ if (iEncounteredDisconnect) {
+ ircClient.joinChannel(channel);
+ iEncounteredDisconnect = false;
+ return;
+ }
//here we use end of motd to signal web irc login completed
c.setIrcNoticesEnabled(true);
window.spinner.stop();
@@ -430,6 +445,10 @@ $(document).ready(function() {
};
var handleOnConnected = function () {
+ if (iEncounteredDisconnect) {
+ ircClient.registerNick(nickname);
+ return;
+ }
loginMsg.text("");
loginStatus.html("");
var nick = window.nick = getNickname(nickText.val());
@@ -442,11 +461,16 @@ $(document).ready(function() {
window.spinner = new Spinner(c.getOpts()).spin(window.target);
};
+ var handleOnReconnecting = function () {
+ appendEvent("*", "reconnecting", false);
+ }
+
/*
* set a time delay for disconnect
* in case we exit the form we do not want the user to see it
*/
var handleOnDisconnected = function () {
+ iEncounteredDisconnect = true;
setTimeout( function () {
appendEvent("*", "disconnected", false);
nicks = [];
@@ -25,6 +25,10 @@ IRCClient.prototype.connect = function () {
that.emit("connected");
});
+ this.client.on("reconnecting", function () {
+ that.emit("reconnecting");
+ });
+
this.client.on("disconnected", function () {
that.emit("disconnected");
});
@@ -19,17 +19,18 @@ Client.prototype.connect = function () {
if (typeof this.socket === "undefined" || this.socket === null) {
this.socket = io.connect("http://" + window.location.host, {
- "reconnect": false,
- "connect timeout": 65000 //10000
-// "reconnection delay": 1000, //500
-// "reconnection limit": Infinity,
-// "reopen delay": 3000,
-// "max reconnection attempts": 30, //10
+ "reconnect": true,
+ "connect timeout": 65000, //10000
+ "reconnection delay": 1000, //500
+ "reconnection limit": Infinity,
+ "reopen delay": 3000,
+ "max reconnection attempts": 30 //10
});
} else {
//reconnects
if (this.socket.socket.connected) {
that.socket.removeAllListeners("connect");
+ that.socket.removeAllListeners("reconnect");
that.socket.removeAllListeners("disconnect");
that.socket.removeAllListeners("message");
that.socket.send(JSON.stringify({
@@ -51,6 +52,10 @@ Client.prototype.connect = function () {
}));
});
+ this.socket.on("reconnect", function () {
+ that.emit("reconnecting");
+ });
+
this.socket.on("disconnect", function () {
that.sioIsConnected = false;
that.endpointIsConnected = false;
View
@@ -9,11 +9,13 @@ var Proxy = function (client, appProcessor) {
//create the socket to connect to remote server on behalf of the client
var net = require("net");
var socket = new net.Socket();
- socket.setEncoding("utf8");
+ socket.setEncoding("ascii");
+ socket.clientid = client.id;
var socketIsConnected = false;
var clientIsConnected = true; //at this stage this can be only true
socket.on("end", function () {
+ console.log("socket END clientid: " + socket.clientid + " on client socket.io id: " + client.id);
socketIsConnected = false;
if (clientIsConnected)
client.send(JSON.stringify({
@@ -22,6 +24,7 @@ var Proxy = function (client, appProcessor) {
});
socket.on("connect", function () {
+ console.log("socket CONNECT clientid: " + socket.clientid + " on client socket.io id: " + client.id);
socketIsConnected = true;
console.log("socket connected");
if (clientIsConnected)
@@ -31,6 +34,7 @@ var Proxy = function (client, appProcessor) {
});
socket.on("data", function (data) {
+ console.log("socket DATA clientid: " + socket.clientid + " on client socket.io id: " + client.id);
console.log("RECV:" + data + ", length: " + data.length );
if (clientIsConnected)
client.send(JSON.stringify({
@@ -41,7 +45,12 @@ var Proxy = function (client, appProcessor) {
//client related
+ client.on("reconnect", function () {
+ console.log("client on RECONNECT.io socket.io: " + client.id + " for socket clientid:" + socket.clientid);
+ });
+
client.on("disconnect", function () {
+ console.log("client on DISCONNECT.io socket.io: " + client.id + " for socket clientid:" + socket.clientid);
clientIsConnected = false;
if (socketIsConnected) {
/*
@@ -61,6 +70,7 @@ var Proxy = function (client, appProcessor) {
});
client.on("message", function (message) {
+ console.log("client on MESSAGE.io socket.io: " + client.id + " for socket clientid:" + socket.clientid);
msg = JSON.parse(message);
switch (msg.action) {
case "connect":

0 comments on commit 92a05d3

Please sign in to comment.