Mercurial > prosody-modules
comparison mod_admin_web/admin_web/www_files/js/main.js @ 301:b241c79a0eb7
mod_admin_web: Add a live view for C2S connections
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Mon, 27 Dec 2010 04:19:41 +0100 |
parents | a70284e01453 |
children | 50abf9922e6e |
comparison
equal
deleted
inserted
replaced
300:b81e4f86a231 | 301:b241c79a0eb7 |
---|---|
1 var BOSH_SERVICE = 'http://localhost:5280/http-bind/'; | 1 var BOSH_SERVICE = 'http://localhost:5280/http-bind/'; |
2 var show_log = false; | 2 var show_log = false; |
3 | 3 |
4 Strophe.addNamespace('C2SPUBSUB', 'http://prosody.im/streams/c2s'); | |
4 Strophe.addNamespace('S2SPUBSUB', 'http://prosody.im/streams/s2s'); | 5 Strophe.addNamespace('S2SPUBSUB', 'http://prosody.im/streams/s2s'); |
5 Strophe.addNamespace('PUBSUB', 'http://jabber.org/protocol/pubsub'); | 6 Strophe.addNamespace('PUBSUB', 'http://jabber.org/protocol/pubsub'); |
6 Strophe.addNamespace('CAPS', 'http://jabber.org/protocol/caps'); | 7 Strophe.addNamespace('CAPS', 'http://jabber.org/protocol/caps'); |
7 | 8 |
8 var localJID = null; | 9 var localJID = null; |
41 $('#' + id).remove(); | 42 $('#' + id).remove(); |
42 } | 43 } |
43 return true; | 44 return true; |
44 } | 45 } |
45 | 46 |
47 function _cbNewC2S(e) { | |
48 var items, retract, id, jid; | |
49 items = e.getElementsByTagName('item'); | |
50 for (i = 0; i < items.length; i++) { | |
51 id = items[i].attributes['id'].value; | |
52 jid = items[i].getElementsByTagName('session')[0].attributes['jid'].value; | |
53 $('#c2s').append('<li id="' + id + '">' + jid + '</li>'); | |
54 } | |
55 retract = e.getElementsByTagName('retract')[0]; | |
56 if (retract) { | |
57 id = retract.attributes['id'].value; | |
58 $('#' + id).remove(); | |
59 } | |
60 return true; | |
61 } | |
62 | |
63 function _cbPubSub(e) { | |
64 var node = e.getElementsByTagName('items')[0].attributes['node'].value; | |
65 if (node == Strophe.NS.C2SPUBSUB) { | |
66 _cbNewC2S(e); | |
67 } else if (node == Strophe.NS.S2SPUBSUB) { | |
68 _cbNewS2S(e); | |
69 } | |
70 | |
71 return true; | |
72 } | |
73 | |
46 function onConnect(status) { | 74 function onConnect(status) { |
47 if (status == Strophe.Status.CONNECTING) { | 75 if (status == Strophe.Status.CONNECTING) { |
48 log('Strophe is connecting.'); | 76 log('Strophe is connecting.'); |
49 } else if (status == Strophe.Status.CONNFAIL) { | 77 } else if (status == Strophe.Status.CONNFAIL) { |
50 log('Strophe failed to connect.'); | 78 log('Strophe failed to connect.'); |
61 } | 89 } |
62 } else if (status == Strophe.Status.CONNECTED) { | 90 } else if (status == Strophe.Status.CONNECTED) { |
63 log('Strophe is connected.'); | 91 log('Strophe is connected.'); |
64 showDisconnect(); | 92 showDisconnect(); |
65 Adhoc.checkFeatures('#adhoc', connection.domain); | 93 Adhoc.checkFeatures('#adhoc', connection.domain); |
94 connection.addHandler(_cbPubSub, Strophe.NS.PUBSUB + '#event', 'message'); | |
95 connection.send($iq({to: pubsubHost, type: 'set', id: connection.getUniqueId()}).c('pubsub', {xmlns: Strophe.NS.PUBSUB}) | |
96 .c('subscribe', {node: Strophe.NS.C2SPUBSUB, jid: connection.jid})); | |
66 connection.send($iq({to: pubsubHost, type: 'set', id: connection.getUniqueId()}).c('pubsub', {xmlns: Strophe.NS.PUBSUB}) | 97 connection.send($iq({to: pubsubHost, type: 'set', id: connection.getUniqueId()}).c('pubsub', {xmlns: Strophe.NS.PUBSUB}) |
67 .c('subscribe', {node: Strophe.NS.S2SPUBSUB, jid: connection.jid})); | 98 .c('subscribe', {node: Strophe.NS.S2SPUBSUB, jid: connection.jid})); |
68 connection.addHandler(_cbNewS2S, Strophe.NS.PUBSUB + '#event', 'message'); | |
69 connection.sendIQ($iq({to: pubsubHost, type: 'get', id: connection.getUniqueId()}).c('pubsub', {xmlns: Strophe.NS.PUBSUB}) | 99 connection.sendIQ($iq({to: pubsubHost, type: 'get', id: connection.getUniqueId()}).c('pubsub', {xmlns: Strophe.NS.PUBSUB}) |
70 .c('items', {node: Strophe.NS.S2SPUBSUB}), _cbNewS2S); | 100 .c('items', {node: Strophe.NS.S2SPUBSUB}), _cbNewS2S); |
101 connection.sendIQ($iq({to: pubsubHost, type: 'get', id: connection.getUniqueId()}).c('pubsub', {xmlns: Strophe.NS.PUBSUB}) | |
102 .c('items', {node: Strophe.NS.C2SPUBSUB}), _cbNewC2S); | |
103 | |
71 } | 104 } |
72 } | 105 } |
73 | 106 |
74 function showConnect() { | 107 function showConnect() { |
75 var jid = $('#jid'); | 108 var jid = $('#jid'); |
80 pass.show(); | 113 pass.show(); |
81 jid.show(); | 114 jid.show(); |
82 $('#menu').hide(); | 115 $('#menu').hide(); |
83 $('#adhoc').hide(); | 116 $('#adhoc').hide(); |
84 $('#s2sList').hide(); | 117 $('#s2sList').hide(); |
118 $('#c2sList').hide(); | |
85 $('#cred label').show(); | 119 $('#cred label').show(); |
86 $('#cred br').show(); | 120 $('#cred br').show(); |
87 $('ul').empty(); | 121 $('ul').empty(); |
88 } | 122 } |
89 | 123 |
130 event.preventDefault(); | 164 event.preventDefault(); |
131 }); | 165 }); |
132 | 166 |
133 $('#adhocMenu').click(function () { | 167 $('#adhocMenu').click(function () { |
134 $('#s2sList').slideUp(); | 168 $('#s2sList').slideUp(); |
169 $('#c2sList').slideUp(); | |
135 $('#adhoc').slideDown(); | 170 $('#adhoc').slideDown(); |
136 event.preventDefault(); | 171 event.preventDefault(); |
137 }); | 172 }); |
138 | 173 |
139 $('#serverMenu').click(function () { | 174 $('#serverMenu').click(function () { |
140 $('#adhoc').slideUp(); | 175 $('#adhoc').slideUp(); |
176 $('#c2sList').slideUp(); | |
141 $('#s2sList').slideDown(); | 177 $('#s2sList').slideDown(); |
142 event.preventDefault(); | 178 event.preventDefault(); |
143 }); | 179 }); |
180 | |
181 $('#clientMenu').click(function () { | |
182 $('#adhoc').slideUp(); | |
183 $('#s2sList').slideUp(); | |
184 $('#c2sList').slideDown(); | |
185 event.preventDefault(); | |
186 }); | |
187 | |
144 }); | 188 }); |
145 | 189 |
146 window.onunload = window.onbeforeunload = function() { | 190 window.onunload = window.onbeforeunload = function() { |
147 if (connection) { | 191 if (connection) { |
148 connection.disconnect(); | 192 connection.disconnect(); |