changeset 16:6707f450549e

fix several problems
author Sonny Piers <sonny.piers@gmail.com>
date Mon, 16 Jan 2012 16:55:40 +0100
parents 521962f10743
children b7bd814333eb
files lightstring.js plugins.js
diffstat 2 files changed, 19 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/lightstring.js
+++ b/lightstring.js
@@ -120,7 +120,7 @@ Lightstring.Connection = function(aServi
     var that = this;
     this.socket.addEventListener('open', function() {
       if (this.protocol !== 'xmpp')
-        throw 'Lightstring: The server located at '+ that.service + ' is not XMPP aware.';
+        console.error('Lightstring: The server located at '+ that.service + ' doesn\'t seems to be XMPP aware.');
 
       var stream = Lightstring.stanza.stream.open(that.host);
 
@@ -159,7 +159,8 @@ Lightstring.Connection = function(aServi
       var str = this.dom2xml(elm);
     }
     else {
-      that.emit('error', 'Unsupported data type.');
+      this.emit('error', 'Unsupported data type.');
+      return;
     }
 
 
@@ -173,7 +174,7 @@ Lightstring.Connection = function(aServi
         this.on(elm.getAttribute('id'), aCallback);
     }
     else if (aCallback) {
-      that.emit('warning', 'Callback can\'t be called with non-iq stanza.');
+      this.emit('warning', 'Callback can\'t be called with non-iq stanza.');
     }
 
 
@@ -277,7 +278,7 @@ Lightstring.Connection = function(aServi
   });
   this.on('success', function(stanza, that) {
     that.send(
-      "<stream:stream to='" + that.domain + "'\
+      "<stream:stream to='" + that.host + "'\
                       xmlns='jabber:client'\
                       xmlns:stream='http://etherx.jabber.org/streams'\
                       version='1.0' />"
@@ -324,7 +325,7 @@ Lightstring.Connection = function(aServi
       }
     }
 
-    var digest_uri = 'xmpp/' + that.domain;
+    var digest_uri = 'xmpp/' + that.host;
     if (host !== null) {
         digest_uri = digest_uri + '/' + host;
     }
--- a/plugins.js
+++ b/plugins.js
@@ -16,6 +16,19 @@
   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */
 
+////////////
+//Presence// http://xmpp.org/rfcs/rfc6121.html#presence
+////////////
+Lightstring.stanza.presence = function(aPriority) {
+  if(aPriority)
+    return "<presence><priority>"+aPriority+"</priority></presence>";
+  else
+    return "<presence/>";
+};
+Lightstring.presence = function(aConnection, aPriority) {
+  aConnection.send(Lightstring.stanza.presence(aPriority));
+};
+
 //////////
 //Roster//
 //////////