summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@nomic.retiolum>2013-11-06 15:07:13 +0100
committertv <tv@nomic.retiolum>2013-11-06 15:07:13 +0100
commitc74cc8954cfd706b4b337c0245b9dcf33620bdf4 (patch)
treeac534f7f38ff76d250e2f048d5ba73d425c6eadb
parent212e9dcb7b9ed3fd7f09f6b69b0b39e7aff2d84f (diff)
parentb5603234dd333575d2522513d5f9a29d9c5bb848 (diff)
Merge branch 'master' of https://github.com/krebscode/painload
-rw-r--r--.gitignore2
-rw-r--r--webchat/hello_web.js18
-rw-r--r--webchat/package.json2
3 files changed, 20 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index 4a3cb30c..4ccc216f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -29,3 +29,5 @@ a.out
/Reaktor/IRC/irclib.py
/Reaktor/public_commands/*
/ship/out
+/webchat/node_modules
+/webchat/local_config
diff --git a/webchat/hello_web.js b/webchat/hello_web.js
index 31e106c7..4b7595d7 100644
--- a/webchat/hello_web.js
+++ b/webchat/hello_web.js
@@ -10,6 +10,8 @@ Clients.broadcast = function(object) {
client.write(JSON.stringify(object));
});
}
+var pingTimeoutDelay = 5*60*1000
+var lastping = setTimeout(reconnect, pingTimeoutDelay)
var irc_client = new irc.Client('irc.freenode.net', 'kweb', {
channels: ['#krebs'],
@@ -21,14 +23,28 @@ var irc_client = new irc.Client('irc.freenode.net', 'kweb', {
debug: true,
showErrors: true,
port: 6697,
+ autoRejoin: true,
+ autoConnect: true
});
+var reconnect = function() {
+ console.log("reconnecting due to pingtimeout");
+ irc_client.disconnect();
+ irc_client.connect();
+}
+
+irc_client.on('ping', function(server) {
+ console.log("got ping from server, renewing timeout for automatic reconnect");
+ clearTimeout(lastping);
+ lastping = setTimeout(reconnect, pingTimeoutDelay);
+})
+
irc_client.on('message#krebs', function(from, message) {
console.log({ from: from, message: message });
Clients.broadcast({ from: from, message: message });
+ clearTimeout(lastping);
});
-
var echo = sockjs.createServer();
echo.on('connection', function(conn) {
var name = '['+conn.remoteAddress+':'+conn.remotePort+']';
diff --git a/webchat/package.json b/webchat/package.json
index 894ac7e8..cb264a8c 100644
--- a/webchat/package.json
+++ b/webchat/package.json
@@ -4,7 +4,7 @@
"dependencies": {
"connect": "2.11.0",
"irc": "0.3.6",
- "sockjs": "0.3.8",
+ "sockjs": "0.3.8"
},
"scripts": {
"test": "tap test/*.js"