diff --git a/index.js b/index.js index 8c83bbc..c7b75d3 100644 --- a/index.js +++ b/index.js @@ -1,38 +1,42 @@ -var xmpp; -var hangouts = function(){ - - this.name = 'hangouts'; - this.displayname = 'Google Hangouts Chat'; - this.description = 'Send messages to woodhouse via Google Hangouts'; - - this.defaultPrefs = [{ - name: 'username', - displayname: 'Username', - type: 'text', - value: '' - },{ - name: 'password', - displayname: 'Password', - type: 'password', - value: '' - }]; - - -} +var xmppCore = require('node-xmpp-core'), + xmppClient = require('node-xmpp-client'), + hangouts = function(){ + this.name = 'hangouts'; + this.displayname = 'Google Hangouts Chat'; + this.description = 'Send messages to woodhouse via Google Hangouts'; + + this.defaultPrefs = [{ + name: 'username', + displayname: 'Username', + type: 'text', + value: '' + },{ + name: 'password', + displayname: 'Password', + type: 'password', + value: '' + }]; + } hangouts.prototype.init = function(){ var self = this; - xmpp = require('node-xmpp'); this.getPrefs().done(function(prefs){ - self.connection = connection = new xmpp.Client({ + self.connection = connection = new xmppClient({ jid: prefs.username, password: prefs.password, host: "talk.google.com", reconnect: true }); + self.connection.connection.socket.setTimeout(0) + self.connection.connection.socket.setKeepAlive(true, 10000) + + self.connection.on('disconnect', function() { + self.connection.connect(); + }) + self.connection.on('online', function() { - connection.send(new xmpp.Element('presence', {}) + connection.send(new xmppCore.Element('presence', {}) .c('show') .t('chat') .up() @@ -40,7 +44,7 @@ hangouts.prototype.init = function(){ .t('Online') ); - var roster_elem = new xmpp.Element('iq', { + var roster_elem = new xmppCore.Element('iq', { 'from': connection.jid, 'type': 'get', 'id': 'google-roster' @@ -53,7 +57,7 @@ hangouts.prototype.init = function(){ connection.send(roster_elem); self.addMessageSender(function(message, to){ - var stanza = new xmpp.Element('message', + var stanza = new xmppCore.Element('message', { to: to, type: 'chat' diff --git a/package.json b/package.json index d03f39b..9e82b3a 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "", "main": "index.js", "dependencies": { - "node-xmpp": "~1.0.0-alpha2" + "node-xmpp-client": "^3.0.0", + "node-xmpp-core": "^5.0.1" }, "devDependencies": {}, "scripts": {