summaryrefslogtreecommitdiffstats
path: root/webchat
diff options
context:
space:
mode:
authorlassulus <lassulus@googlemail.com>2013-11-06 14:32:18 +0100
committerlassulus <lassulus@googlemail.com>2013-11-06 14:32:18 +0100
commit8d049b2de9da1f549da9e5bb8c1b6225a0b0edff (patch)
treed4ad9b488dd456699e805cd3ce14c0c9144e05b6 /webchat
parent241f13cd2880c97b9d3503725a0720a017779ed6 (diff)
webchat: automatic reconnect after ping timeout
Diffstat (limited to 'webchat')
-rw-r--r--webchat/hello_web.js18
1 files changed, 17 insertions, 1 deletions
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+']';