changeset 72:5dbf93cef55d

Various fixes.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 02 Feb 2012 02:28:18 +0100
parents f12c759e4097
children e4899c122d7b
files lightstring.js plugins/dataforms.js plugins/disco.js
diffstat 3 files changed, 21 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/lightstring.js
+++ b/lightstring.js
@@ -24,7 +24,8 @@ var Lightstring = {
    */
   ns: {
     streams: 'http://etherx.jabber.org/streams',
-    jabber_client: 'jabber:client'
+    jabber_client: 'jabber:client',
+    xmpp_stanzas: 'urn:ietf:params:xml:ns:xmpp-stanzas'
   },
   /**
    * @namespace Holds XMPP stanza builders.
@@ -150,10 +151,10 @@ Lightstring.Connection.prototype = {
     if (!this.service)
       return; //TODO: error
 
-    if(typeof(WebSocket) === "function") {
+    if (typeof(WebSocket) === "function") {
       this.socket = new WebSocket(this.service, 'xmpp');
     }
-    else if(typeof(MozWebSocket) === "function") {
+    else if (typeof(MozWebSocket) === "function") {
       this.socket = new MozWebSocket(this.service, 'xmpp');
     }
     else {
@@ -186,7 +187,7 @@ Lightstring.Connection.prototype = {
       //FIXME: node-xmpp-bosh sends a self-closing stream:stream tag; it is wrong!
       Conn.emit('input', stanza);
 
-      if(!stanza.DOM)
+      if (!stanza.DOM)
         return;
 
       var name = stanza.DOM.localName;
@@ -240,6 +241,10 @@ Lightstring.Connection.prototype = {
 
         delete Conn.callbacks[id];
       }
+
+      else if (name === 'presence' || name === 'message') {
+        Conn.emit(name, stanza);
+      }
     });
   },
   /**
@@ -253,7 +258,7 @@ Lightstring.Connection.prototype = {
     else
       var stanza = aStanza;
 
-    if(!stanza)
+    if (!stanza)
       return;
 
     if (stanza.DOM.tagName === 'iq') {
@@ -313,7 +318,7 @@ Lightstring.Connection.prototype = {
       //Methods
       this[name] = {};
       for (var method in plugin.methods)
-        this[name][method].bind(this);
+        this[name][method] = plugin.methods[method].bind(this);
 
       if (plugin.init)
         plugin.init();
@@ -347,6 +352,10 @@ Lightstring.Connection.prototype = {
     }
 
     if (aData && aData.DOM) {
+      var type = aData.DOM.getAttributeNS(null, 'type');
+      if (type !== 'get' && type !== 'set')
+        return;
+
       var from = aData.DOM.getAttributeNS(null, 'from');
       var id = aData.DOM.getAttributeNS(null, 'id');
       this.send(Lightstring.stanzas.errors.iq(from, id, 'cancel', 'service-unavailable'));
--- a/plugins/dataforms.js
+++ b/plugins/dataforms.js
@@ -91,7 +91,7 @@
     return fields;
   };
 
-  Lightstring.plugins['disco'] = {
+  Lightstring.plugins['dataforms'] = {
     namespaces: {
       dataforms: 'jabber:x:data'
     },
--- a/plugins/disco.js
+++ b/plugins/disco.js
@@ -83,7 +83,7 @@
         }, aError);
       },
       info: function(aTo, aNode, aResult, aError) {
-        this.send(Lightstring.stanzas.disco.info(aTo, aNode), function(stanza){
+        this.send(Lightstring.stanzas.disco.info(aTo, aNode), function(stanza) {
           var identities = [];
           var features = [];
           var fields = {};
@@ -125,8 +125,9 @@
             aResult(stanza);
         }, aError);
       },
-      addFeature: function(feature) {
-        features.push(feature);
+      addFeatures: function() {
+        for (var i = 0; i < arguments.length; i++)
+          features.push(arguments[i]);
       }
     },
     init: function() {
@@ -167,6 +168,7 @@
              "</iq>";
 
         conn.send(res);
+        return true;
       });
     }
   };