comparison mod_admin_web/admin_web/www_files/js/main.js @ 317:4f78f5020aa9

mod_admin_web: Get rid of the mod_pubsub dependency
author Florian Zeitz <florob@babelmonkeys.de>
date Fri, 14 Jan 2011 01:54:39 +0100
parents f406e300d709
children ba2e78661ea8
comparison
equal deleted inserted replaced
316:c86fc337d56f 317:4f78f5020aa9
1 var BOSH_SERVICE = '/http-bind/'; 1 var BOSH_SERVICE = '/http-bind/';
2 var show_log = false; 2 var show_log = true;
3 3
4 Strophe.addNamespace('C2SPUBSUB', 'http://prosody.im/streams/c2s'); 4 Strophe.addNamespace('C2SSTREAM', 'http://prosody.im/streams/c2s');
5 Strophe.addNamespace('S2SPUBSUB', 'http://prosody.im/streams/s2s'); 5 Strophe.addNamespace('S2SSTREAM', 'http://prosody.im/streams/s2s');
6 Strophe.addNamespace('PUBSUB', 'http://jabber.org/protocol/pubsub'); 6 Strophe.addNamespace('ADMINSUB', 'http://prosody.im/adminsub');
7 Strophe.addNamespace('CAPS', 'http://jabber.org/protocol/caps'); 7 Strophe.addNamespace('CAPS', 'http://jabber.org/protocol/caps');
8 8
9 var localJID = null; 9 var localJID = null;
10 var connection = null; 10 var connection = null;
11 11
12 var pubsubHost = '%PUBSUBHOST%'; 12 var adminsubHost = '%ADMINSUBHOST%';
13 13
14 function log(msg) { 14 function log(msg) {
15 var entry = $('<div></div>').append(document.createTextNode(msg)); 15 var entry = $('<div></div>').append(document.createTextNode(msg));
16 $('#log').append(entry); 16 $('#log').append(entry);
17 } 17 }
30 for (i = 0; i < items.length; i++) { 30 for (i = 0; i < items.length; i++) {
31 id = items[i].attributes['id'].value; 31 id = items[i].attributes['id'].value;
32 jid = items[i].getElementsByTagName('session')[0].attributes['jid'].value; 32 jid = items[i].getElementsByTagName('session')[0].attributes['jid'].value;
33 33
34 entry = $('<li id="' + id + '">' + jid + '</li>'); 34 entry = $('<li id="' + id + '">' + jid + '</li>');
35 if (e.getElementsByTagName('encrypted')[0]) { 35 if (items[i].getElementsByTagName('encrypted')[0]) {
36 entry.append('<img src="images/encrypted.png" title="encrypted" alt=" (encrypted)" />'); 36 entry.append('<img src="images/encrypted.png" title="encrypted" alt=" (encrypted)" />');
37 } 37 }
38 if (e.getElementsByTagName('compressed')[0]) { 38 if (items[i].getElementsByTagName('compressed')[0]) {
39 entry.append('<img src="images/compressed.png" title="compressed" alt=" (compressed)" />'); 39 entry.append('<img src="images/compressed.png" title="compressed" alt=" (compressed)" />');
40 } 40 }
41 41
42 if (items[i].getElementsByTagName('out')[0]) { 42 if (items[i].getElementsByTagName('out')[0]) {
43 entry.appendTo('#s2sout'); 43 entry.appendTo('#s2sout');
58 items = e.getElementsByTagName('item'); 58 items = e.getElementsByTagName('item');
59 for (i = 0; i < items.length; i++) { 59 for (i = 0; i < items.length; i++) {
60 id = items[i].attributes['id'].value; 60 id = items[i].attributes['id'].value;
61 jid = items[i].getElementsByTagName('session')[0].attributes['jid'].value; 61 jid = items[i].getElementsByTagName('session')[0].attributes['jid'].value;
62 entry = $('<li id="' + id + '">' + jid + '</li>'); 62 entry = $('<li id="' + id + '">' + jid + '</li>');
63 if (e.getElementsByTagName('encrypted')[0]) { 63 if (items[i].getElementsByTagName('encrypted')[0]) {
64 entry.append('<img src="images/encrypted.png" title="encrypted" alt=" (encrypted)" />'); 64 entry.append('<img src="images/encrypted.png" title="encrypted" alt=" (encrypted)" />');
65 } 65 }
66 if (e.getElementsByTagName('compressed')[0]) { 66 if (items[i].getElementsByTagName('compressed')[0]) {
67 entry.append('<img src="images/compressed.png" title="compressed" alt=" (compressed)" />'); 67 entry.append('<img src="images/compressed.png" title="compressed" alt=" (compressed)" />');
68 } 68 }
69 entry.appendTo('#c2s'); 69 entry.appendTo('#c2s');
70 } 70 }
71 retract = e.getElementsByTagName('retract')[0]; 71 retract = e.getElementsByTagName('retract')[0];
74 $('#' + id).remove(); 74 $('#' + id).remove();
75 } 75 }
76 return true; 76 return true;
77 } 77 }
78 78
79 function _cbPubSub(e) { 79 function _cbAdminSub(e) {
80 var node = e.getElementsByTagName('items')[0].attributes['node'].value; 80 var node = e.getElementsByTagName('items')[0].attributes['node'].value;
81 if (node == Strophe.NS.C2SPUBSUB) { 81 if (node == Strophe.NS.C2SSTREAM) {
82 _cbNewC2S(e); 82 _cbNewC2S(e);
83 } else if (node == Strophe.NS.S2SPUBSUB) { 83 } else if (node == Strophe.NS.S2SSTREAM) {
84 _cbNewS2S(e); 84 _cbNewS2S(e);
85 } 85 }
86 86
87 return true; 87 return true;
88 } 88 }
104 connection.disconnect(); 104 connection.disconnect();
105 } 105 }
106 } else if (status == Strophe.Status.CONNECTED) { 106 } else if (status == Strophe.Status.CONNECTED) {
107 log('Strophe is connected.'); 107 log('Strophe is connected.');
108 showDisconnect(); 108 showDisconnect();
109 connection.addHandler(_cbAdminSub, Strophe.NS.ADMINSUB + '#event', 'message');
110 connection.send($iq({to: adminsubHost, type: 'set', id: connection.getUniqueId()}).c('adminsub', {xmlns: Strophe.NS.ADMINSUB})
111 .c('subscribe', {node: Strophe.NS.C2SSTREAM}));
112 connection.send($iq({to: adminsubHost, type: 'set', id: connection.getUniqueId()}).c('adminsub', {xmlns: Strophe.NS.ADMINSUB})
113 .c('subscribe', {node: Strophe.NS.S2SSTREAM}));
114 connection.sendIQ($iq({to: adminsubHost, type: 'get', id: connection.getUniqueId()}).c('adminsub', {xmlns: Strophe.NS.ADMINSUB})
115 .c('items', {node: Strophe.NS.S2SSTREAM}), _cbNewS2S);
116 connection.sendIQ($iq({to: adminsubHost, type: 'get', id: connection.getUniqueId()}).c('adminsub', {xmlns: Strophe.NS.ADMINSUB})
117 .c('items', {node: Strophe.NS.C2SSTREAM}), _cbNewC2S);
109 Adhoc.checkFeatures('#adhoc', connection.domain); 118 Adhoc.checkFeatures('#adhoc', connection.domain);
110 connection.addHandler(_cbPubSub, Strophe.NS.PUBSUB + '#event', 'message');
111 connection.send($iq({to: pubsubHost, type: 'set', id: connection.getUniqueId()}).c('pubsub', {xmlns: Strophe.NS.PUBSUB})
112 .c('subscribe', {node: Strophe.NS.C2SPUBSUB, jid: connection.jid}));
113 connection.send($iq({to: pubsubHost, type: 'set', id: connection.getUniqueId()}).c('pubsub', {xmlns: Strophe.NS.PUBSUB})
114 .c('subscribe', {node: Strophe.NS.S2SPUBSUB, jid: connection.jid}));
115 connection.sendIQ($iq({to: pubsubHost, type: 'get', id: connection.getUniqueId()}).c('pubsub', {xmlns: Strophe.NS.PUBSUB})
116 .c('items', {node: Strophe.NS.S2SPUBSUB}), _cbNewS2S);
117 connection.sendIQ($iq({to: pubsubHost, type: 'get', id: connection.getUniqueId()}).c('pubsub', {xmlns: Strophe.NS.PUBSUB})
118 .c('items', {node: Strophe.NS.C2SPUBSUB}), _cbNewC2S);
119
120 } 119 }
121 } 120 }
122 121
123 function showConnect() { 122 function showConnect() {
124 var jid = $('#jid'); 123 var jid = $('#jid');