|
|
@ -32,10 +32,16 @@ var Client = function(params, callback) {
|
|
|
|
this.xmpp.addListener('stanza', function(stanza) {
|
|
|
|
this.xmpp.addListener('stanza', function(stanza) {
|
|
|
|
//sys.debug('STANZA: '[jabber.color] + ('<' + stanza.name + '> ').bold[jabber.color] + stanza);
|
|
|
|
//sys.debug('STANZA: '[jabber.color] + ('<' + stanza.name + '> ').bold[jabber.color] + stanza);
|
|
|
|
if(stanza.name == 'iq') {
|
|
|
|
if(stanza.name == 'iq') {
|
|
|
|
if(stanza.attrs.type == 'result') {
|
|
|
|
switch(stanza.attrs.type) {
|
|
|
|
|
|
|
|
case 'result':
|
|
|
|
jabber._debug('IQ result: ' + stanza);
|
|
|
|
jabber._debug('IQ result: ' + stanza);
|
|
|
|
jabber.emit('iqResult', stanza.attrs.id, stanza);
|
|
|
|
jabber.emit('iq:result', stanza.attrs.id, stanza);
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'error':
|
|
|
|
|
|
|
|
jabber._debug('IQ error :' + stanza);
|
|
|
|
|
|
|
|
jabber.emit('iq:error', stanza.attrs.id, stanza);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
jabber._debug(('IQ: ' + stanza)[jabber.color]);
|
|
|
|
jabber._debug(('IQ: ' + stanza)[jabber.color]);
|
|
|
|
jabber.emit('iq', stanza);
|
|
|
|
jabber.emit('iq', stanza);
|
|
|
|
var q = stanza.getChild('query');
|
|
|
|
var q = stanza.getChild('query');
|
|
|
@ -44,6 +50,7 @@ var Client = function(params, callback) {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
jabber.emit('iq:unknow', stanza);
|
|
|
|
jabber.emit('iq:unknow', stanza);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(stanza.name == 'presence') {
|
|
|
|
if(stanza.name == 'presence') {
|
|
|
@ -70,9 +77,14 @@ var Client = function(params, callback) {
|
|
|
|
jabber.emit('groupchat', from, stanza.getChild('body').getText(), stanza);
|
|
|
|
jabber.emit('groupchat', from, stanza.getChild('body').getText(), stanza);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
jabber._debug('MESSAGE: ' + stanza);
|
|
|
|
jabber._debug('MESSAGE: ' + stanza);
|
|
|
|
|
|
|
|
var event_ = stanza.getChild('event', 'http://jabber.org/protocol/pubsub#event');
|
|
|
|
|
|
|
|
if(event_ != null) {
|
|
|
|
|
|
|
|
jabber.emit('pubsub:event', from, event_, stanza);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
jabber.emit('message', from, stanza.getChild('body').getText(), stanza);
|
|
|
|
jabber.emit('message', from, stanza.getChild('body').getText(), stanza);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.xmpp.addListener('online', function() {
|
|
|
|
this.xmpp.addListener('online', function() {
|
|
|
|
jabber._debug("[Info] xmpp connection");
|
|
|
|
jabber._debug("[Info] xmpp connection");
|
|
|
@ -89,7 +101,7 @@ var Client = function(params, callback) {
|
|
|
|
fromName = from.split('/')[0];
|
|
|
|
fromName = from.split('/')[0];
|
|
|
|
jabber.rooms[fromName].emit('message', from, msg, stanza);
|
|
|
|
jabber.rooms[fromName].emit('message', from, msg, stanza);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.addListener('iqResult', function(id, stanza){
|
|
|
|
this.addListener('iq:result', function(id, stanza){
|
|
|
|
jabber._iqCallback[id].call(jabber, stanza);
|
|
|
|
jabber._iqCallback[id].call(jabber, stanza);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.addListener('presence', function(from, stanza) {
|
|
|
|
this.addListener('presence', function(from, stanza) {
|
|
|
@ -97,7 +109,7 @@ var Client = function(params, callback) {
|
|
|
|
var jfrom = new JID(stanza.attrs.from);
|
|
|
|
var jfrom = new JID(stanza.attrs.from);
|
|
|
|
var roomName = jfrom.user + '@' + jfrom.domain;
|
|
|
|
var roomName = jfrom.user + '@' + jfrom.domain;
|
|
|
|
if(this.rooms[roomName] != null) {
|
|
|
|
if(this.rooms[roomName] != null) {
|
|
|
|
|
|
|
|
//[FIXME]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
jabber.presences[from] = stanza.attrs.type;
|
|
|
|
jabber.presences[from] = stanza.attrs.type;
|
|
|
@ -136,6 +148,9 @@ var Client = function(params, callback) {
|
|
|
|
this.addListener('iq', function(stanza) {
|
|
|
|
this.addListener('iq', function(stanza) {
|
|
|
|
sys.debug(stanza.getChild('query').toString().yellow);
|
|
|
|
sys.debug(stanza.getChild('query').toString().yellow);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
this.addListener('iq:error', function(id, stanza) {
|
|
|
|
|
|
|
|
this._debug(stanza.toString().red.invert);
|
|
|
|
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
sys.inherits(Client, events.EventEmitter);
|
|
|
|
sys.inherits(Client, events.EventEmitter);
|
|
|
@ -189,11 +204,19 @@ Client.prototype.iq = function(to, query, callback) {
|
|
|
|
this.xmpp.send(new xmpp.Element('iq', attrs).cnode(query).tree());
|
|
|
|
this.xmpp.send(new xmpp.Element('iq', attrs).cnode(query).tree());
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Client.prototype.iqSet = function(query) {
|
|
|
|
Client.prototype.iqSet = function(to, query, callback) {
|
|
|
|
this.xmpp.send(new xmpp.Element('iq', {
|
|
|
|
var n = this._iq++;
|
|
|
|
|
|
|
|
if(callback != null) {
|
|
|
|
|
|
|
|
this._iqCallback[n] = callback;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var attrs = {
|
|
|
|
type:"set",
|
|
|
|
type:"set",
|
|
|
|
id: this._iq++
|
|
|
|
id: n
|
|
|
|
}).cnode(query).tree());
|
|
|
|
};
|
|
|
|
|
|
|
|
if(to != null) {
|
|
|
|
|
|
|
|
attrs.to = to;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.xmpp.send(new xmpp.Element('iq', attrs).cnode(query).tree());
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Client.prototype.resultIq = function(iqGet, result) {
|
|
|
|
Client.prototype.resultIq = function(iqGet, result) {
|
|
|
@ -237,6 +260,26 @@ Client.prototype.disconnect = function() {
|
|
|
|
sys.debug("disconnect from XMPP");
|
|
|
|
sys.debug("disconnect from XMPP");
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Client.prototype.publish = function(to, node, publish) {
|
|
|
|
|
|
|
|
this.iqSet(to, new xmpp.Element('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'})
|
|
|
|
|
|
|
|
.cnode(publish)
|
|
|
|
|
|
|
|
.tree()
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Client.prototype.suscribe = function(to, node, callback) {
|
|
|
|
|
|
|
|
if(to == null) {
|
|
|
|
|
|
|
|
to = 'pubsub.' + this.jid.domain;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.iqSet(to, new xmpp.Element('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'})
|
|
|
|
|
|
|
|
.c('subscription', {
|
|
|
|
|
|
|
|
node: node,
|
|
|
|
|
|
|
|
jid: this.jid.user + '@' + this.jid.domain
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.tree()
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var Room = function(client, name, callback) {
|
|
|
|
var Room = function(client, name, callback) {
|
|
|
|
events.EventEmitter.call(this);
|
|
|
|
events.EventEmitter.call(this);
|
|
|
|
this._isReady = false;
|
|
|
|
this._isReady = false;
|
|
|
|