diff lightstring.js @ 34:6ce66fba0242

Merging.
author Sonny Piers <sonny.piers@gmail.com>
date Sat, 28 Jan 2012 04:39:03 +0100
parents 1e6d2ca2daae 88d24231bf24
children 6773e5bc2ca0
line wrap: on
line diff
--- a/lightstring.js
+++ b/lightstring.js
@@ -86,7 +86,20 @@ var Lightstring = {
     finally {
       return XML;
     };
-  }
+  },
+  /**
+   * @function Get an unique identifier.
+   * @param {String} [aString] Prefix to put before the identifier.
+   * @return {String} Identifier.
+   */
+  newId: (function() {
+    var id = 1024;
+    return function(prefix) {
+      if (typeof prefix === 'string')
+        return prefix + id++;
+      return '' + id++;
+    };
+  })()
 };
 
 /**
@@ -98,11 +111,6 @@ Lightstring.Connection = function(aServi
   if (aService)
     this.service = aService;
   this.handlers = {};
-  this.iqid = 1024;
-  this.getNewId = function() {
-    this.iqid++;
-    return 'sendiq:' + this.iqid;
-  };
   this.on('stream:features', function(stanza, that) {
     var nodes = stanza.DOM.querySelectorAll('mechanism');
     //SASL/Auth features
@@ -321,8 +329,7 @@ Lightstring.Connection.prototype = {
       var id = stanza.DOM.getAttribute('id');
       //TODO: This should be done by a plugin
       if (!id) {
-        alert(Lightstring.DOM2XML(stanza.DOM));
-        stanza.DOM.setAttribute('id', this.getNewId());
+        stanza.DOM.setAttribute('id', Lightstring.newId('sendiq:'));
       }
       if (aCallback)
         this.on(stanza.DOM.getAttribute('id'), aCallback);