]> git.babelmonkeys.de Git - socialXMPP.git/commitdiff
Implement User Tune support and dependencies
authorFlorian Zeitz <florob@babelmonkeys.de>
Sun, 22 Mar 2009 02:12:40 +0000 (03:12 +0100)
committerFlorian Zeitz <florob@babelmonkeys.de>
Sun, 22 Mar 2009 02:24:00 +0000 (03:24 +0100)
* Implement Disco
* Implmemnt Caps
* Implement User Tune

index.html
scripts/basic.js
scripts/buddy.js [deleted file]
scripts/classes.js [new file with mode: 0644]

index a2a067e72fcc83ef07284466399cc6e983177c25..d808d1261237b99b3930ab6275508c9f7cc67c9a 100644 (file)
@@ -7,7 +7,7 @@
   <script language='javascript' type='text/javascript' src='scripts/strophejs/src/md5.js'></script>
   <script language='javascript' type='text/javascript' src='scripts/strophejs/src/sha1.js'></script>
   <script language='javascript' type='text/javascript' src='scripts/strophejs/src/strophe.js'></script>
-  <script language='javascript' type='text/javascript' src='scripts/buddy.js'></script>
+  <script language='javascript' type='text/javascript' src='scripts/classes.js'></script>
   <script language='javascript' type='text/javascript' src='scripts/basic.js'></script>
   <link rel="stylesheet" href="css/standard.css" type="text/css" />
 </head>
index 1246bfbcff0de95e3aff7a0b368a1eb046b0feb4..984b0cc383236f0d9850ccae0af96d241afcdc42 100644 (file)
@@ -1,13 +1,19 @@
 var NS_VCARD = 'vcard-temp';
+var NS_CAPS= 'http://jabber.org/protocol/caps';
+var NS_PEP = 'http://jabber.org/protocol/pubsub#event';
+var NS_TUNE = 'http://jabber.org/protocol/tune';
 var BOSH_SERVICE = 'http://localhost:5280/http-bind/';
 
 var connection   = null;
 var show_log     = true;
 
+var features = new Array(NS_CAPS, NS_TUNE+'+notify', Strophe.NS.DISCO_INFO);
+var appName = 'socialXMPP';
+
 var roster = new Array();
 
 function log(msg) {
-    var entry = $('<div></div>').append(document.createTextNode(msg));
+    var entry = $('<div></div>').append(Strophe.xmlTextNode(msg));
     $('#log').append(entry);
 }
 
@@ -20,6 +26,7 @@ function rawOutput(data) {
 }
 
 function jid2id(jid) {
+    jid = Strophe.getBareJidFromJid(jid);
     return jid.split('@').join('-').split('.').join('-');
 }
 
@@ -29,7 +36,7 @@ function populateVCard(e, jid) {
        var text = e.getElementsByTagName(easy_cases[i])[0];
        if (text) {
            text = Strophe.getText(text);
-           $('#'+easy_cases[i]).append(document.createTextNode(text));
+           $('#'+easy_cases[i]).append(Strophe.xmlTextNode(text));
        }
     }
     var avatar = e.getElementsByTagName('PHOTO')[0];
@@ -104,6 +111,55 @@ function getRoster() {
     connection.send(rosteriq.tree());
 }
 
+function _cbDisco(e) {
+    var id = e.getAttribute('id');
+    var jid = e.getAttribute('from');
+
+    var response = $iq({id: id, type: 'result', to: jid});
+    var query = response.c('query', {xmlns: Strophe.NS.DISCO_INFO})
+    query.c('identity', {category: 'client', type: 'web', name: appName}).up();
+    for (var i = 0; i < features.length; i++) {
+       query.c('feature', {var: features[i]}).up();
+    }
+    connection.send(response.tree());
+
+    return true;
+}
+
+function genCaps() {
+    var S = '';
+    S += 'client/web//' + appName + '<'
+    features.sort();
+    for (var i = 0; i < features.length; i++) {
+       S += features[i] + '<';
+    }
+    return b64_sha1(S);
+}
+
+function _cbPEP(e) {
+    var from = e.getAttribute('from');
+    var items = e.getElementsByTagName('items')[0];
+    // Handle Tune
+    if (items.getAttribute('node') == NS_TUNE) {
+       var tune = new Tune();
+       tune.artist = Strophe.getText(items.getElementsByTagName('artist')[0]);
+       tune.length= Strophe.getText(items.getElementsByTagName('length')[0]);
+       tune.rating= Strophe.getText(items.getElementsByTagName('rating')[0]);
+       tune.source= Strophe.getText(items.getElementsByTagName('source')[0]);
+       tune.title= Strophe.getText(items.getElementsByTagName('title')[0]);
+       tune.track= Strophe.getText(items.getElementsByTagName('track')[0]);
+       tune.uri= Strophe.getText(items.getElementsByTagName('uri')[0]);
+       roster[jid2id(from)].tune = tune;
+       if ( $('#'+jid2id(from)+' .tune').length > 0 ) {
+           $('#'+jid2id(from)+' .tune').empty();
+           $('#'+jid2id(from)+' .tune').append(Strophe.xmlTextNode('Listening to '+ tune.title + ' by ' + tune.artist + ' from ' + tune.source));
+       } else {
+           $('#'+jid2id(from)).append('<br /><span class="tune">Listening to '+ tune.title + ' by ' + tune.artist + ' from ' + tune.source + '</span>');
+       }
+    }
+    return true;
+}
+
 function onConnect(status) {
     if (status == Strophe.Status.CONNECTING) {
        log('Strophe is connecting.');
@@ -120,6 +176,10 @@ function onConnect(status) {
     } else if (status == Strophe.Status.CONNECTED) {
        log('Strophe is connected.');
        getRoster();
+       connection.addHandler(_cbPEP, NS_PEP, 'message');
+       connection.addHandler(_cbDisco, Strophe.NS.DISCO_INFO, 'iq', 'get');
+       var initialPresence = $pres().c('c', {xmlns: NS_CAPS, hash: 'sha-1', node: 'http://jabber.babelmonkeys.de', ver: genCaps()}).up();
+       connection.send(initialPresence.tree());
     }
 }
 
diff --git a/scripts/buddy.js b/scripts/buddy.js
deleted file mode 100644 (file)
index 1382787..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-Buddy = function(name, jid) {
-    this.name = name;
-    this.jid = jid;
-    this.vCard = "";
-};
diff --git a/scripts/classes.js b/scripts/classes.js
new file mode 100644 (file)
index 0000000..8ada8d8
--- /dev/null
@@ -0,0 +1,17 @@
+Tune = function() {
+    this.artist ='';
+    this.length = 0;
+    this.rating = 1;
+    this.source = '';
+    this.title = '';
+    this.track = 1;
+    this.uri = '';
+}
+
+Buddy = function(name, jid) {
+    this.name = name;
+    this.jid = jid;
+    this.vCard = "";
+    this.tune = new Tune();
+};
+