# HG changeset patch # User Emmanuel Gil Peyrot # Date 1327586693 -3600 # Node ID 7fcccf59e6ec3aa23d32a698a64766518265bd27 # Parent b7bd814333eb7b9dd8809ed1e45a16a65bfab674 Always use two-spaces indent. diff --git a/lightstring.js b/lightstring.js --- a/lightstring.js +++ b/lightstring.js @@ -24,14 +24,14 @@ var Lightstring = { /** * @namespace Holds XMPP namespaces. */ - NS: { + NS: { stream: 'http://etherx.jabber.org/streams', jabberClient: 'jabber:client' }, /** * @namespace Holds XMPP stanza builders. */ - stanza: { + stanza: { stream: { open: function(aService) { //FIXME no ending "/" - node-xmpp-bosh bug @@ -262,7 +262,7 @@ Lightstring.Connection.prototype = { console.log(e.data); }); this.socket.addEventListener('close', function(e) { - that.emit('disconnected', e.data); + that.emit('disconnected', e.data); }); this.socket.addEventListener('message', function(e) { that.emit('XMLInput', e.data); @@ -270,8 +270,8 @@ Lightstring.Connection.prototype = { that.emit('DOMInput', elm); that.emit(elm.tagName, elm); - if (elm.tagName === 'iq') - that.emit(elm.getAttribute('id'), elm); + if (elm.tagName === 'iq') + that.emit(elm.getAttribute('id'), elm); }); }, /** @@ -295,7 +295,7 @@ Lightstring.Connection.prototype = { if (elm.tagName === 'iq') { - var id = elm.getAttribute('id'); + var id = elm.getAttribute('id'); if (!id) { elm.setAttribute('id', this.getNewId()); str = Lightstring.dom2xml(elm); @@ -316,12 +316,12 @@ Lightstring.Connection.prototype = { * @function Closes the XMPP stream and the socket. */ disconnect: function() { - this.emit('disconnecting'); + this.emit('disconnecting'); var stream = Lightstring.stanza.stream.close(); - this.send(stream); + this.send(stream); this.emit('XMLOutput', stream); - this.socket.close(); - }, + this.socket.close(); + }, /** * @function Emits an event. * @param {String} aName The event name. diff --git a/plugins.js b/plugins.js --- a/plugins.js +++ b/plugins.js @@ -34,26 +34,26 @@ Lightstring.presence = function(aConnect ////////// Lightstring.NS.roster = 'jabber:iq:roster'; Lightstring.stanza.roster = { - 'get': function() { - return ""; - }, - add: function(aAddress, aGroups, aCustomName) { - var iq = $iq({type: 'set'}).c('query', {xmlns: Lightstring.NS.roster}).c('item', {jid: aAddress}).tree(); - if(aCustomName) iq.querySelector('item').setAttribute(aCustomName); - for (var i=0; i"; + }, + add: function(aAddress, aGroups, aCustomName) { + var iq = $iq({type: 'set'}).c('query', {xmlns: Lightstring.NS.roster}).c('item', {jid: aAddress}).tree(); + if(aCustomName) iq.querySelector('item').setAttribute(aCustomName); + for (var i=0; i"; - else - return ""; - } + 'get': function(aTo) { + if(aTo) + return ""; + else + return ""; + } }; //FIXME we should return a proper vcard, not an XMPP one Lightstring.getVcard = function(aConnection, aTo, aCallback) { - aConnection.send(Lightstring.stanza.vcard.get(aTo), function(answer, err){ - if(answer) { - var vcard = answer.querySelector('vCard'); - if(vcard) - aCallback(vcard); - } - else - aCallback(null); - }); + aConnection.send(Lightstring.stanza.vcard.get(aTo), function(answer, err){ + if(answer) { + var vcard = answer.querySelector('vCard'); + if(vcard) + aCallback(vcard); + } + else + aCallback(null); + }); } ///////// //Disco// @@ -109,56 +109,56 @@ Lightstring.getVcard = function(aConnect Lightstring.NS['disco#info'] = "http://jabber.org/protocol/disco#info"; Lightstring.NS['disco#items'] = "http://jabber.org/protocol/disco#items"; Lightstring.stanza.disco = { - items: function(aTo, aNode) { - if(aTo) - var iq = ""; - else - var iq = ""; - - if(aNode) - var query = ""; - else - var query = ""; - - return iq+query+""; - }, - info: function(aTo, aNode) { - if(aTo) - var iq = ""; - else - var iq = ""; - if(aNode) - var query = ""; - else - var query = ""; - - return iq+query+""; - } + items: function(aTo, aNode) { + if(aTo) + var iq = ""; + else + var iq = ""; + + if(aNode) + var query = ""; + else + var query = ""; + + return iq+query+""; + }, + info: function(aTo, aNode) { + if(aTo) + var iq = ""; + else + var iq = ""; + if(aNode) + var query = ""; + else + var query = ""; + + return iq+query+""; + } }; Lightstring.discoItems = function(aConnection, aTo, aCallback) { - aConnection.send(Lightstring.stanza.disco.items(aTo), function(answer){ - var items = []; + aConnection.send(Lightstring.stanza.disco.items(aTo), function(answer){ + var items = []; var elms = answer.querySelectorAll('item'); for(var i = 0; i < elms.length; i++) { var node = elms[i]; - var item = { - jid: node.getAttribute('jid'), - name: node.getAttribute('name'), - node: node.getAttribute('node') - } - items.push(item); - }; - if(aCallback) - aCallback(items); - }); + var item = { + jid: node.getAttribute('jid'), + name: node.getAttribute('name'), + node: node.getAttribute('node') + } + items.push(item); + }; + if(aCallback) + aCallback(items); + }); }; Lightstring.discoInfo = function(aConnection, aTo, aNode, aCallback) { - aConnection.send(Lightstring.stanza.disco.info(aTo, aNode), function(answer){ - var field = answer.querySelector('field[var="pubsub#creator"] > value'); - var creator = field ? field.textContent : ''; - //FIXME callback the entire data - aCallback(creator); - }); + aConnection.send(Lightstring.stanza.disco.info(aTo, aNode), function(answer){ + var field = answer.querySelector('field[var="pubsub#creator"] > value'); + var creator = field ? field.textContent : ''; + //FIXME callback the entire data + aCallback(creator); + }); }; ////////// //PubSub// @@ -167,126 +167,126 @@ Lightstring.NS.x = "jabber:x:data"; Lightstring.NS.pubsub = "http://jabber.org/protocol/pubsub"; Lightstring.NS.pubsub_owner = "http://jabber.org/protocol/pubsub#owner"; Lightstring.stanza.pubsub = { - getConfig: function(aTo, aNode) { - return ""; - }, - items: function(aTo, aNode) { - return ""; - }, - affiliations: function(aTo, aNode) { - return ""; - }, - publish: function(aTo, aNode, aItem, aId) { - return ""+aItem+""; - }, - retract: function(aTo, aNode, aItem) { - return ""; - }, - 'delete': function(aTo, aNode, aURI) { - return ""; - }, - create: function(aTo, aNode, aFields) { - var iq = ""; - if(aFields) { - iq += "" - aFields.forEach(function(field) { - iq += field; - }); - iq += ""; - } - iq += ""; - return iq; - }, - setAffiliations: function(aTo, aNode, aAffiliations) { - var iq = ""; - for(var i = 0; i < aAffiliations.length; i++) { - iq += "" - } - iq += ""; - return iq; - }, + getConfig: function(aTo, aNode) { + return ""; + }, + items: function(aTo, aNode) { + return ""; + }, + affiliations: function(aTo, aNode) { + return ""; + }, + publish: function(aTo, aNode, aItem, aId) { + return ""+aItem+""; + }, + retract: function(aTo, aNode, aItem) { + return ""; + }, + 'delete': function(aTo, aNode, aURI) { + return ""; + }, + create: function(aTo, aNode, aFields) { + var iq = ""; + if(aFields) { + iq += "" + aFields.forEach(function(field) { + iq += field; + }); + iq += ""; + } + iq += ""; + return iq; + }, + setAffiliations: function(aTo, aNode, aAffiliations) { + var iq = ""; + for(var i = 0; i < aAffiliations.length; i++) { + iq += "" + } + iq += ""; + return iq; + }, }; Lightstring.pubsubItems = function(aConnection, aTo, aNode, aCallback) { - aConnection.send(Lightstring.stanza.pubsub.items(aTo, aNode), function(answer){ - var items = []; + aConnection.send(Lightstring.stanza.pubsub.items(aTo, aNode), function(answer){ + var items = []; var elms = answer.querySelectorAll('item'); for(var i = 0; i < elms.length; i++) { var node = elms[i]; - var item = { - id: node.getAttribute('id'), - name: node.querySelector('title').textContent, - src: node.querySelector('content').getAttribute('src'), - type: node.querySelector('content').getAttribute('type'), - } - var miniature = node.querySelector('link'); - if(miniature) - item.miniature = miniature.getAttribute('href'); - items.push(item); - }; - if(aCallback) - aCallback(items); - }); + var item = { + id: node.getAttribute('id'), + name: node.querySelector('title').textContent, + src: node.querySelector('content').getAttribute('src'), + type: node.querySelector('content').getAttribute('type'), + } + var miniature = node.querySelector('link'); + if(miniature) + item.miniature = miniature.getAttribute('href'); + items.push(item); + }; + if(aCallback) + aCallback(items); + }); } Lightstring.pubsubCreate = function(aConnection, aTo, aNode, aFields, aCallback) { - aConnection.send(Lightstring.stanza.pubsub.create(aTo, aNode, aFields), function(answer) { - if(answer.getAttribute('type') === 'result') - aCallback(null, answer); - else - aCallback(answer, null); - }); + aConnection.send(Lightstring.stanza.pubsub.create(aTo, aNode, aFields), function(answer) { + if(answer.getAttribute('type') === 'result') + aCallback(null, answer); + else + aCallback(answer, null); + }); }; Lightstring.pubsubConfig = function(aConnection, aTo, aNode, aCallback) { - aConnection.send(Lightstring.stanza.pubsub.getConfig(aTo, aNode), function(answer){ - var accessmodel = answer.querySelector('field[var="pubsub#access_model"]').lastChild.textContent; - if(accessmodel) - aCallback(accessmodel); - else - aCallback(null); - }); + aConnection.send(Lightstring.stanza.pubsub.getConfig(aTo, aNode), function(answer){ + var accessmodel = answer.querySelector('field[var="pubsub#access_model"]').lastChild.textContent; + if(accessmodel) + aCallback(accessmodel); + else + aCallback(null); + }); } Lightstring.pubsubRetract = function(aConnection, aTo, aNode, aItem, aCallback) { - aConnection.send(Lightstring.stanza.pubsub.retract(aTo, aNode, aItem), function(answer){ - if(aCallback) - aCallback(answer); - }); + aConnection.send(Lightstring.stanza.pubsub.retract(aTo, aNode, aItem), function(answer){ + if(aCallback) + aCallback(answer); + }); } Lightstring.pubsubPublish = function(aConnection, aTo, aNode, aItem, aId, aCallback) { - aConnection.send(Lightstring.stanza.pubsub.publish(aTo, aNode, aItem, aId), function(answer){ - if(answer.getAttribute('type') === 'result') - aCallback(null, answer); - else - aCallback(answer, null); - }); + aConnection.send(Lightstring.stanza.pubsub.publish(aTo, aNode, aItem, aId), function(answer){ + if(answer.getAttribute('type') === 'result') + aCallback(null, answer); + else + aCallback(answer, null); + }); } Lightstring.pubsubDelete = function(aConnection, aTo, aNode, aCallback) { - aConnection.send(Lightstring.stanza.pubsub.delete(aTo, aNode), function(answer){ - if(aCallback) - aCallback(answer); - }); + aConnection.send(Lightstring.stanza.pubsub.delete(aTo, aNode), function(answer){ + if(aCallback) + aCallback(answer); + }); } Lightstring.pubsubGetAffiliations = function(aConnection, aTo, aNode, aCallback) { - aConnection.send(Lightstring.stanza.pubsub.affiliations(aTo, aNode), function(answer) { - if((answer.getAttribute('type') === 'result') && aCallback) { - var affiliations = {}; - answer.querySelectorAll('affiliation').forEach(function(affiliation) { - affiliations[affiliation.getAttribute("jid")] = affiliation.getAttribute("affiliation"); - }) - aCallback(affiliations); - } - }); + aConnection.send(Lightstring.stanza.pubsub.affiliations(aTo, aNode), function(answer) { + if((answer.getAttribute('type') === 'result') && aCallback) { + var affiliations = {}; + answer.querySelectorAll('affiliation').forEach(function(affiliation) { + affiliations[affiliation.getAttribute("jid")] = affiliation.getAttribute("affiliation"); + }) + aCallback(affiliations); + } + }); }; Lightstring.pubsubSetAffiliations = function(aConnection, aTo, aNode, aAffiliations, aCallback) { - aConnection.send(Lightstring.stanza.pubsub.setAffiliations(aTo, aNode, aAffiliations)); + aConnection.send(Lightstring.stanza.pubsub.setAffiliations(aTo, aNode, aAffiliations)); }; ////// //IM// ////// Lightstring.stanza.message = { - normal: function(aTo, aSubject, aText) { - return ""+aSubject+""+aText+""; - }, - chat: function(aTo, aText) { - return ""+aText+""; - } + normal: function(aTo, aSubject, aText) { + return ""+aSubject+""+aText+""; + }, + chat: function(aTo, aText) { + return ""+aText+""; + } };