From 4ee49053d6f222ba2654ee5bf8f9f8f6fd50d961 Mon Sep 17 00:00:00 2001 From: Sonny Piers Date: Thu, 24 Dec 2015 12:13:35 +0100 Subject: [PATCH] better configuration variables --- README.mdown | 9 ++++++--- src/xmpp.coffee | 10 +++++++--- test/adapter-test.coffee | 2 ++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/README.mdown b/README.mdown index 5d07111..13ee658 100644 --- a/README.mdown +++ b/README.mdown @@ -1,6 +1,6 @@ # Hubot XMPP -Connects Hubot to your XMPP network +Connects Hubot to your XMPP network [![Build Status](https://secure.travis-ci.org/markstory/hubot-xmpp.png?branch=master)](http://travis-ci.org/markstory/hubot-xmpp) @@ -29,11 +29,14 @@ Optional: the host to be defined. * `HUBOT_XMPP_PREFERRED_SASL_MECHANISM` Used to change the encoding used for SASL. * `HUBOT_XMPP_DISALLOW_TLS` Prevent upgrading the connection to a secure one via TLS. -* `HUBOT_XMPP_PM_ADD_PREFIX` Make commands work in PMs to hubot without robot name/alias +* `HUBOT_XMPP_PM_ADD_PREFIX` Make commands work in PMs to hubot without robot name/alias. +* `HUBOT_XMPP_KEEPALIVE_INTERVAL` Keep-alive interval in ms. +* `HUBOT_XMPP_RECONNECT_TRY` the number of reconnect retry in case of disconnection, default is 5. +* `HUBOT_XMPP_RECONNECT_WAIT` the time in ms to wait before reconnecting, default is 5000. `HUBOT_XMPP_ROOMS` can be a comma separated list of rooms to join. If your rooms require passwords you should use the `jid:password` syntax. -Room passwords cannot contain `,`. Room names must be the full jid of the +Room passwords cannot contain `,`. Room names must be the full jid of the room for example `dev@conference.jabber.example.org`. `HUBOT_XMPP_PM_ADD_PREFIX` works by prefixing the private message with hubot name, so a diff --git a/src/xmpp.coffee b/src/xmpp.coffee index 3807024..e6b7119 100644 --- a/src/xmpp.coffee +++ b/src/xmpp.coffee @@ -31,7 +31,9 @@ class XmppBot extends Adapter port: process.env.HUBOT_XMPP_PORT rooms: @parseRooms process.env.HUBOT_XMPP_ROOMS.split(',') # ms interval to send whitespace to xmpp server - keepaliveInterval: 30000 + keepaliveInterval: process.env.HUBOT_XMPP_KEEPALIVE_INTERVAL || 30000 + reconnectTry: process.env.HUBOT_XMPP_RECONNECT_TRY || 5 + reconnectWait: process.env.HUBOT_XMPP_RECONNECT_WAIT || 5000 legacySSL: process.env.HUBOT_XMPP_LEGACYSSL preferredSaslMechanism: process.env.HUBOT_XMPP_PREFERRED_SASL_MECHANISM disallowTLS: process.env.HUBOT_XMPP_DISALLOW_TLS @@ -46,8 +48,10 @@ class XmppBot extends Adapter # Only try to reconnect 5 times reconnect: () -> + options = @options + @reconnectTryCount += 1 - if @reconnectTryCount > 5 + if @reconnectTryCount > options.reconnectTry @robot.logger.error 'Unable to reconnect to jabber server dying.' process.exit 1 @@ -58,7 +62,7 @@ class XmppBot extends Adapter setTimeout () => @makeClient() - , 5000 + , options.reconnectWait makeClient: () -> options = @options diff --git a/test/adapter-test.coffee b/test/adapter-test.coffee index dab802e..09c1a16 100644 --- a/test/adapter-test.coffee +++ b/test/adapter-test.coffee @@ -983,6 +983,7 @@ describe 'XmppBot', -> done() assert.equal 0, bot.reconnectTryCount + bot.options = {reconnectTry: 5} bot.reconnect() assert.equal 1, bot.reconnectTryCount, 'No time elapsed' clock.tick 5001 @@ -991,6 +992,7 @@ describe 'XmppBot', -> mock = sinon.mock(process) mock.expects('exit').once() + bot.options = {reconnectTry: 5} bot.reconnectTryCount = 5 bot.reconnect()