Skip to content

Commit

Permalink
Merge pull request #100 from sonnyp/yeah
Browse files Browse the repository at this point in the history
Better configuration variables
  • Loading branch information
markstory committed Dec 24, 2015
2 parents c6a2a1f + 4ee4905 commit 8296c09
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 4 additions & 1 deletion README.mdown
Expand Up @@ -29,7 +29,10 @@ 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.
Expand Down
10 changes: 7 additions & 3 deletions src/xmpp.coffee
Expand Up @@ -27,7 +27,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
Expand All @@ -42,8 +44,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

Expand All @@ -54,7 +58,7 @@ class XmppBot extends Adapter

setTimeout () =>
@makeClient()
, 5000
, options.reconnectWait

makeClient: () ->
options = @options
Expand Down
2 changes: 2 additions & 0 deletions test/adapter-test.coffee
Expand Up @@ -982,6 +982,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
Expand All @@ -990,6 +991,7 @@ describe 'XmppBot', ->
mock = sinon.mock(process)
mock.expects('exit').once()

bot.options = {reconnectTry: 5}
bot.reconnectTryCount = 5
bot.reconnect()

Expand Down

0 comments on commit 8296c09

Please sign in to comment.