Browse files

Reconnect on GTalk disconnection

This is a bot after all, so it should be always on.
  • Loading branch information...
1 parent 48d7f92 commit bf7d346d78cfcbbb9424d5cbef7265cd575816c5 @edufelipe edufelipe committed Feb 17, 2012
Showing with 7 additions and 1 deletion.
  1. +7 −1 src/adapters/gtalk.coffee
View
8 src/adapters/gtalk.coffee
@@ -9,6 +9,7 @@ class Gtalkbot extends Adapter
Xmpp.JID.prototype.from = -> @bare().toString()
@name = @robot.name
+ @rosterTimerId = -1
# Client Options
@options =
@@ -28,11 +29,13 @@ class Gtalkbot extends Adapter
password: @options.password
host: @options.host
port: @options.port
+ reconnect: true
# Events
@client.on 'online', => @online()
@client.on 'stanza', (stanza) => @readStanza(stanza)
@client.on 'error', => @error()
+ @client.on 'offline', => @offline()
@pending = {}
@@ -50,10 +53,13 @@ class Gtalkbot extends Adapter
# Check for buddy requests every so often
@client.send roster_query
- setInterval =>
+ @rosterTimerId = setInterval =>
@client.send roster_query
, @options.keepaliveInterval
+ offline: ->
+ clearInterval @rosterTimerId
+
readStanza: (stanza) ->
# Useful for debugging
# console.log stanza

0 comments on commit bf7d346

Please sign in to comment.