Skip to content

Commit

Permalink
Slight refactor to try and stop the hanging/unresponsivenes
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeFoodPixels committed Jan 30, 2016
1 parent 886c090 commit e5bb73c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 27 deletions.
56 changes: 30 additions & 26 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,50 @@
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()
.c('status')
.t('Online')
);

var roster_elem = new xmpp.Element('iq', {
var roster_elem = new xmppCore.Element('iq', {
'from': connection.jid,
'type': 'get',
'id': 'google-roster'
Expand All @@ -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'
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit e5bb73c

Please sign in to comment.